openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r1055479 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/config/ webbeans-impl/src/main/java/org/apache/webbeans/proxy/ webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/ webbeans-resource/src/main/ja...
Date Wed, 05 Jan 2011 15:02:49 GMT
Author: gerdogdu
Date: Wed Jan  5 15:02:47 2011
New Revision: 1055479

URL: http://svn.apache.org/viewvc?rev=1055479&view=rev
Log:
[OWB-511] Delegate actualInstance serialization behavior in ResourceProxyHandler

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/ResourceProxyHandler.java
    openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourceInjectionService.java
    openwebbeans/trunk/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceInjectionService.java
    openwebbeans/trunk/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceProcessor.java
    openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/ResourceInjectionService.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1055479&r1=1055478&r2=1055479&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
Wed Jan  5 15:02:47 2011
@@ -21,6 +21,7 @@ package org.apache.webbeans.config;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.webbeans.container.BeanManagerImpl;
@@ -40,6 +41,7 @@ import org.apache.webbeans.plugins.Plugi
 import org.apache.webbeans.portable.AnnotatedElementFactory;
 import org.apache.webbeans.portable.events.ExtensionLoader;
 import org.apache.webbeans.proxy.JavassistProxyFactory;
+import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.xml.WebBeansNameSpaceContainer;
 import org.apache.webbeans.xml.XMLAnnotationTypeManager;
@@ -74,6 +76,8 @@ public class WebBeansContext
 
     private final Map<String, Object> managerMap = new HashMap<String, Object>();
 
+    private final Map<Class<?>, Object> serviceMap = new HashMap<Class<?>,
Object>();
+
     public WebBeansContext()
     {
         // Allow the WebBeansContext itself to be looked up
@@ -110,6 +114,50 @@ public class WebBeansContext
         return webBeansContext;
     }
 
+    public <T> T getService(Class<T> clazz)
+    {
+        T t = (T) serviceMap.get(clazz);
+        if (t == null)
+        {
+            t = doServiceLoader(clazz);
+            registerService(clazz, t);
+        }
+        return t;
+    }
+
+    public <T> void registerService(Class<T> clazz, T t)
+    {
+        serviceMap.put(clazz, t);
+    }
+
+    private <T> T doServiceLoader(Class<T> serviceInterface)
+    {
+        String implName = getOpenWebBeansConfiguration().getProperty(serviceInterface.getName());
+
+        if (implName == null)
+        {
+            //Look for plugins
+            List<OpenWebBeansPlugin> plugins = getPluginLoader().getPlugins();
+            if(plugins != null && plugins.size() > 0)
+            {
+                for(OpenWebBeansPlugin plugin : plugins)
+                {
+                    if(plugin.supportService(serviceInterface))
+                    {
+                        return plugin.getSupportedService(serviceInterface);
+                    }
+                }
+            }
+
+//            if (logger.wblWillLogWarn())
+//            {
+//                logger.warn(OWBLogConst.WARN_0009, serviceInterface.getName());
+//            }
+            return null;
+        }
+        return (T) WebBeansFinder.getSingletonInstance(implName);
+    }
+
     public ConversationManager getConversationManager()
     {
         return conversationManager;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/ResourceProxyHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/ResourceProxyHandler.java?rev=1055479&r1=1055478&r2=1055479&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/ResourceProxyHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/ResourceProxyHandler.java
Wed Jan  5 15:02:47 2011
@@ -29,25 +29,18 @@ import java.lang.reflect.Method;
 import javassist.util.proxy.MethodHandler;
 import org.apache.webbeans.component.ResourceBean;
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.corespi.ServiceLoader;
-import org.apache.webbeans.spi.FailOverService;
+import org.apache.webbeans.spi.ResourceInjectionService;
 
 public class ResourceProxyHandler implements MethodHandler, Serializable, Externalizable
 {
     /**
      * 
      */
-    private static final long serialVersionUID = 4171212030439910547L;
-    
-    /**
-     * When ResourceProxyHandler deserialized, this will instruct owb to create a new actual
instance, if
-     * the actual resource is not serializable.
-     */
-    private static final String DUMMY_STRING = "owb.actual.resource.dummy";
-    
-    private Object actualResource = null;
+    private static final long serialVersionUID = 2608686651845218158L;
+
+    private transient Object actualResource;
 
-    private transient ResourceBean bean = null;
+    private transient ResourceBean bean;
 
     //DO NOT REMOVE, used by failover and passivation.
     public ResourceProxyHandler()
@@ -84,29 +77,9 @@ public class ResourceProxyHandler implem
     {        
         // write bean id first
         out.writeObject(bean.getId());
-
-        // try fail over service to serialize the resource object
-        FailOverService failoverService = ServiceLoader.getService(FailOverService.class);
-        if (failoverService != null)
-        {
-            Object ret = failoverService.handleResource(bean, actualResource, null, out);
-            if (ret != FailOverService.NOT_HANDLED)
-            {
-                return;
-            }
-        }
-        
-        // default behavior
-        if (actualResource instanceof Serializable)
-        {
-            // for remote ejb stub and other serializable resources
-            out.writeObject(actualResource);
-        }
-        else
-        {
-            // otherwise, write a dummy string. 
-            out.writeObject(DUMMY_STRING);
-        }
+        WebBeansContext webBeansContext = WebBeansContext.getInstance();
+        ResourceInjectionService resourceInjectionService = webBeansContext.getService(ResourceInjectionService.class);
+        resourceInjectionService.writeExternal(bean, actualResource, out);
     }
 
     /**
@@ -121,30 +94,9 @@ public class ResourceProxyHandler implem
             ClassNotFoundException 
     {
         String id = (String)in.readObject();
-        bean = (ResourceBean) WebBeansContext.getInstance().getBeanManagerImpl().getPassivationCapableBean(id);
-        
-        // try fail over service to serialize the resource object
-        FailOverService failoverService = ServiceLoader.getService(FailOverService.class);
-        if (failoverService != null) 
-        {
-            actualResource = failoverService.handleResource(bean, actualResource, in, null);
-            if (actualResource != FailOverService.NOT_HANDLED)
-            {
-                return;
-            }
-        }
-
-        // default behavior
-        actualResource = in.readObject();
-        if (actualResource instanceof javax.rmi.CORBA.Stub)
-        {
-            // for remote ejb stub, reconnect after deserialization.
-            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(new String[0], null);
-            ((javax.rmi.CORBA.Stub)actualResource).connect(orb);
-        }
-        else if (actualResource.equals(DUMMY_STRING))
-        {
-            actualResource = bean.getActualInstance();
-        }
-    }    
+        WebBeansContext webBeansContext = WebBeansContext.getInstance();
+        bean = (ResourceBean) webBeansContext.getBeanManagerImpl().getPassivationCapableBean(id);
+        ResourceInjectionService resourceInjectionService = webBeansContext.getService(ResourceInjectionService.class);
+        actualResource = resourceInjectionService.readExternal(bean, in);
+    }
 }

Modified: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourceInjectionService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourceInjectionService.java?rev=1055479&r1=1055478&r2=1055479&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourceInjectionService.java
(original)
+++ openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/resource/OpenEjbResourceInjectionService.java
Wed Jan  5 15:02:47 2011
@@ -18,17 +18,25 @@
  */
 package org.apache.webbeans.ejb.resource;
 
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 import java.text.MessageFormat;
 
 import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Bean;
 
+import org.apache.webbeans.component.ResourceBean;
 import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.corespi.ServiceLoader;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.spi.FailOverService;
 import org.apache.webbeans.spi.ResourceInjectionService;
 import org.apache.webbeans.spi.api.ResourceReference;
 import org.apache.webbeans.util.AnnotationUtil;
@@ -36,6 +44,12 @@ import org.apache.webbeans.util.Security
 
 public class OpenEjbResourceInjectionService implements ResourceInjectionService
 {
+    /**
+     * When ResourceProxyHandler deserialized, this will instruct owb to create a new actual
instance, if
+     * the actual resource is not serializable.
+     */
+    private static final String DUMMY_STRING = "owb.actual.resource.dummy";
+
     private static final WebBeansLogger logger = WebBeansLogger.getLogger(OpenEjbResourceInjectionService.class);
 
     @Override
@@ -98,4 +112,66 @@ public class OpenEjbResourceInjectionSer
         }
     }
 
+    /**
+     * delegation of serialization behavior
+     */
+    public <T> void writeExternal(Bean<T> bean, T actualResource, ObjectOutput
out) throws IOException
+    {
+        // try fail over service to serialize the resource object
+        FailOverService failoverService = ServiceLoader.getService(FailOverService.class);
+        if (failoverService != null)
+        {
+            Object ret = failoverService.handleResource(bean, actualResource, null, out);
+            if (ret != FailOverService.NOT_HANDLED)
+            {
+                return;
+            }
+        }
+
+        // default behavior
+        if (actualResource instanceof Serializable)
+        {
+            // for remote ejb stub and other serializable resources
+            out.writeObject(actualResource);
+        }
+        else
+        {
+            // otherwise, write a dummy string.
+            out.writeObject(DUMMY_STRING);
+        }
+
+    }
+
+    /**
+     * delegation of serialization behavior
+     */
+    public <T> T readExternal(Bean<T> bean, ObjectInput in) throws IOException,
+            ClassNotFoundException
+    {
+        T actualResource = null;
+        // try fail over service to serialize the resource object
+        FailOverService failoverService = ServiceLoader.getService(FailOverService.class);
+        if (failoverService != null)
+        {
+            actualResource = (T) failoverService.handleResource(bean, actualResource, in,
null);
+            if (actualResource != FailOverService.NOT_HANDLED)
+            {
+                return actualResource;
+            }
+        }
+
+        // default behavior
+        actualResource = (T) in.readObject();
+        if (actualResource instanceof javax.rmi.CORBA.Stub)
+        {
+            // for remote ejb stub, reconnect after deserialization.
+            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(new String[0], null);
+            ((javax.rmi.CORBA.Stub)actualResource).connect(orb);
+        }
+        else if (actualResource.equals(DUMMY_STRING))
+        {
+            actualResource = (T) ((ResourceBean)bean).getActualInstance();
+        }
+        return actualResource;
+    }
 }

Modified: openwebbeans/trunk/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceInjectionService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceInjectionService.java?rev=1055479&r1=1055478&r2=1055479&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceInjectionService.java
(original)
+++ openwebbeans/trunk/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceInjectionService.java
Wed Jan  5 15:02:47 2011
@@ -18,6 +18,10 @@
  */
 package org.apache.webbeans.resource.spi.se;
 
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
@@ -25,13 +29,17 @@ import java.text.MessageFormat;
 
 import javax.annotation.Resource;
 import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Bean;
 import javax.persistence.PersistenceContext;
 import javax.persistence.PersistenceUnit;
 import javax.xml.ws.WebServiceRef;
 
+import org.apache.webbeans.component.ResourceBean;
 import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.corespi.ServiceLoader;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.spi.FailOverService;
 import org.apache.webbeans.spi.ResourceInjectionService;
 import org.apache.webbeans.spi.api.ResourceReference;
 import org.apache.webbeans.util.AnnotationUtil;
@@ -39,6 +47,12 @@ import org.apache.webbeans.util.Security
 
 public class StandaloneResourceInjectionService implements ResourceInjectionService
 {
+    /**
+     * When ResourceProxyHandler deserialized, this will instruct owb to create a new actual
instance, if
+     * the actual resource is not serializable.
+     */
+    private static final String DUMMY_STRING = "owb.actual.resource.dummy";
+
     private final StandaloneResourceProcessor processor = StandaloneResourceProcessor.getProcessor();
     
     private static final WebBeansLogger logger = WebBeansLogger.getLogger(StandaloneResourceInjectionService.class);
@@ -126,5 +140,68 @@ public class StandaloneResourceInjection
         processor.clear();       
     }
     
+    /**
+     * delegation of serialization behavior
+     */
+    public <T> void writeExternal(Bean<T> bean, T actualResource, ObjectOutput
out) throws IOException
+    {
+        // try fail over service to serialize the resource object
+        FailOverService failoverService = ServiceLoader.getService(FailOverService.class);
+        if (failoverService != null)
+        {
+            Object ret = failoverService.handleResource(bean, actualResource, null, out);
+            if (ret != FailOverService.NOT_HANDLED)
+            {
+                return;
+            }
+        }
+
+        // default behavior
+        if (actualResource instanceof Serializable)
+        {
+            // for remote ejb stub and other serializable resources
+            out.writeObject(actualResource);
+        }
+        else
+        {
+            // otherwise, write a dummy string.
+            out.writeObject(DUMMY_STRING);
+        }
+
+    }
+
+    /**
+     * delegation of serialization behavior
+     */
+    public <T> T readExternal(Bean<T> bean, ObjectInput in) throws IOException,
+            ClassNotFoundException
+    {
+        T actualResource = null;
+        // try fail over service to serialize the resource object
+        FailOverService failoverService = ServiceLoader.getService(FailOverService.class);
+        if (failoverService != null)
+        {
+            actualResource = (T) failoverService.handleResource(bean, actualResource, in,
null);
+            if (actualResource != FailOverService.NOT_HANDLED)
+            {
+                return actualResource;
+            }
+        }
+
+        // default behavior
+        actualResource = (T) in.readObject();
+        if (actualResource instanceof javax.rmi.CORBA.Stub)
+        {
+            // for remote ejb stub, reconnect after deserialization.
+            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(new String[0], null);
+            ((javax.rmi.CORBA.Stub)actualResource).connect(orb);
+        }
+        else if (actualResource.equals(DUMMY_STRING))
+        {
+            actualResource = (T) ((ResourceBean)bean).getActualInstance();
+        }
+        return actualResource;
+    }
+
 
 }

Modified: openwebbeans/trunk/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceProcessor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceProcessor.java?rev=1055479&r1=1055478&r2=1055479&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceProcessor.java
(original)
+++ openwebbeans/trunk/webbeans-resource/src/main/java/org/apache/webbeans/resource/spi/se/StandaloneResourceProcessor.java
Wed Jan  5 15:02:47 2011
@@ -30,7 +30,6 @@ import javax.persistence.Persistence;
 import javax.persistence.PersistenceContext;
 import javax.persistence.PersistenceUnit;
 import javax.xml.ws.WebServiceRef;
-
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.logger.WebBeansLogger;
 

Modified: openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/ResourceInjectionService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/ResourceInjectionService.java?rev=1055479&r1=1055478&r2=1055479&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/ResourceInjectionService.java
(original)
+++ openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/ResourceInjectionService.java
Wed Jan  5 15:02:47 2011
@@ -18,9 +18,13 @@
  */
 package org.apache.webbeans.spi;
 
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.lang.annotation.Annotation;
 
 
+import javax.enterprise.inject.spi.Bean;
 import org.apache.webbeans.spi.api.ResourceReference;
 
 /**
@@ -76,5 +80,16 @@ public interface ResourceInjectionServic
      * </p>
      */
     public void clear();
+
+    /**
+     * delegation of serialization behavior
+     */
+    public <T> void writeExternal(Bean<T> bean, T actualResource, ObjectOutput
out) throws IOException;
+
+    /**
+     * delegation of serialization behavior
+     */
+    public <T> T readExternal(Bean<T> bean, ObjectInput out) throws IOException,
+            ClassNotFoundException;
         
 }



Mime
View raw message