[jboss-cvs] JBossAS SVN: r81179 - in trunk/server: src/main/org/jboss/invocation and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 17 15:17:49 EST 2008


Author: dimitris at jboss.org
Date: 2008-11-17 15:17:49 -0500 (Mon, 17 Nov 2008)
New Revision: 81179

Added:
   trunk/server/src/main/org/jboss/invocation/ByValueInvokerInterceptor.java
   trunk/server/src/main/org/jboss/invocation/DataContainerMarshallingInvokerInterceptor.java
   trunk/server/src/main/org/jboss/invocation/MarshalledValueEX.java
   trunk/server/src/main/org/jboss/invocation/unified/interfaces/JavaSerializationManager.java
Modified:
   trunk/server/build.xml
   trunk/server/src/main/org/jboss/invocation/InvokerInterceptor.java
   trunk/server/src/main/org/jboss/invocation/MarshalledInvocation.java
   trunk/server/src/main/org/jboss/invocation/MarshalledValue.java
   trunk/server/src/main/org/jboss/invocation/MarshallingInvokerInterceptor.java
   trunk/server/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerProxy.java
Log:
JBAS-6178, fix most compatibility-matrix failures, synch org.jboss.invocation.unified.interfaces.JavaSerializationManager with Branch_4_2

Modified: trunk/server/build.xml
===================================================================
--- trunk/server/build.xml	2008-11-17 19:46:02 UTC (rev 81178)
+++ trunk/server/build.xml	2008-11-17 20:17:49 UTC (rev 81179)
@@ -94,6 +94,7 @@
       <path refid="jboss.microcontainer.classpath"/>
       <path refid="jboss.jboss.jpa.deployers.classpath"/>
       <path refid="jboss.jboss.vfs.classpath"/>
+      <path refid="jboss.serialization.classpath"/>
       <path refid="oswego.concurrent.classpath"/>
       <path refid="sun.jaxb.classpath"/>
       <path refid="sun.servlet.classpath"/>
@@ -433,6 +434,11 @@
         <include name="org/jboss/logging/**"/>
         <include name="org/jboss/naming/**"/>
       </fileset>
+      <zipfileset src="${jboss.remoting.lib}/jboss-remoting.jar">
+        <include name="org/jboss/remoting/util/**"/>
+        <include name="org/jboss/remoting/serialization/**"/>
+        <include name="org/jboss/remoting/loading/ObjectInputStreamWithClassLoader*"/>
+      </zipfileset>      
     </jar>
 
     <!-- jboss-client.jar -->

Added: trunk/server/src/main/org/jboss/invocation/ByValueInvokerInterceptor.java
===================================================================
--- trunk/server/src/main/org/jboss/invocation/ByValueInvokerInterceptor.java	                        (rev 0)
+++ trunk/server/src/main/org/jboss/invocation/ByValueInvokerInterceptor.java	2008-11-17 20:17:49 UTC (rev 81179)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.invocation;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+/**
+* An InvokerInterceptor that does not optimize remote invocations.<p>
+*
+* This interceptor implements spec compliant behaviour.<p>
+*
+* @todo The performance could be improved by simulating marshalling
+*       for "local" remote, rather than going straight for the invoker
+* 
+* @author <a href="mailto:adrian.brock at happeningtimes.com">Adrian Brock</a>
+* @version $Revision: 57209 $
+*/
+public class ByValueInvokerInterceptor
+   extends InvokerInterceptor
+   implements Externalizable
+{
+   /** Serial Version Identifier. @since 1.1.4.1 */
+   private static final long serialVersionUID = -6402069656713307195L;
+
+   public ByValueInvokerInterceptor()
+   {
+      // For externalization to work
+   }
+   
+   // Public --------------------------------------------------------
+
+   /**
+    * Are you local?
+    */
+   public boolean isLocal(Invocation invocation)
+   {
+      InvocationType type = invocation.getType();
+      if (type == InvocationType.LOCAL || type == InvocationType.LOCALHOME)
+         return true;
+      return false;
+   }
+   
+   /**
+    * Invoke using the invoker for remote invocations
+    */
+   public Object invoke(Invocation invocation)
+      throws Exception
+   {
+      // local interface
+      if (isLocal(invocation))
+         // The payload as is is good
+         return localInvoker.invoke(invocation);
+      else
+         // through the invoker
+         return invocation.getInvocationContext().getInvoker().invoke(invocation);
+   }
+   
+   /**
+    *  Externalize this instance.
+    */
+   public void writeExternal(final ObjectOutput out)
+      throws IOException
+   { 
+      // We have no state
+   }
+   
+   /**
+    *  Un-externalize this instance.
+    */
+   public void readExternal(final ObjectInput in)
+      throws IOException, ClassNotFoundException
+   {
+      // We have no state
+   }
+   
+   // Private -------------------------------------------------------
+   
+   // Inner classes -------------------------------------------------
+}

Added: trunk/server/src/main/org/jboss/invocation/DataContainerMarshallingInvokerInterceptor.java
===================================================================
--- trunk/server/src/main/org/jboss/invocation/DataContainerMarshallingInvokerInterceptor.java	                        (rev 0)
+++ trunk/server/src/main/org/jboss/invocation/DataContainerMarshallingInvokerInterceptor.java	2008-11-17 20:17:49 UTC (rev 81179)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.invocation;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import org.jboss.proxy.ClientContainer;
+import org.jboss.remoting.serialization.IMarshalledValue;
+import org.jboss.remoting.serialization.impl.jboss.LocalMarshalledValue;
+import org.jboss.serial.objectmetamodel.safecloning.SafeClone;
+import org.jboss.serial.objectmetamodel.safecloning.SafeCloningRepository;
+
+
+/** 
+ * This MarshallingInvokerInterceptor uses JbossSerialization DataContainer's doing a faster serialization over call-by-values than For Marshalling local call-by-values using JBossSerialization
+ * @author <mailto="clebert.suconic at jboss.com">Clebert Suconic</a> 
+ * */
+public class DataContainerMarshallingInvokerInterceptor extends MarshallingInvokerInterceptor
+{
+	private static final long serialVersionUID = -1889397492156790576L;
+
+	
+	  /** These objects are safe to reuse in callByValue operations */
+	   static final SafeClone safeToReuse = new SafeClone(){
+	                 public boolean isSafeToReuse(Object obj) {
+	                     if (obj==null)
+	                     {
+	                         return false;
+	                     }
+
+	                     if (obj instanceof ClientContainer ||
+	                         obj instanceof String ||
+	                         obj instanceof Number ||
+	                         obj instanceof BigDecimal ||
+	                         obj instanceof BigInteger ||
+	                         obj instanceof Byte ||
+	                         obj instanceof Double ||
+	                         obj instanceof Float ||
+	                         obj instanceof Integer ||
+	                         obj instanceof Long ||
+	                         obj instanceof Short)
+	                     {
+	                         return true;
+	                     }
+	                     else
+	                     {
+	                         return false;
+	                     }
+	                 }
+	             };
+
+
+	   protected IMarshalledValue createMarshalledValueForCallByValue(Object value) throws IOException
+	   {
+		   return new LocalMarshalledValue(value,new SafeCloningRepository(safeToReuse));
+
+	   }
+	
+}

Modified: trunk/server/src/main/org/jboss/invocation/InvokerInterceptor.java
===================================================================
--- trunk/server/src/main/org/jboss/invocation/InvokerInterceptor.java	2008-11-17 19:46:02 UTC (rev 81178)
+++ trunk/server/src/main/org/jboss/invocation/InvokerInterceptor.java	2008-11-17 20:17:49 UTC (rev 81179)
@@ -26,20 +26,26 @@
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.lang.reflect.UndeclaredThrowableException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 import javax.transaction.Transaction;
 
-import org.jboss.invocation.Invocation;
-import org.jboss.invocation.Invoker;
-
 import org.jboss.proxy.Interceptor;
+import org.jboss.proxy.ClientContainer;
 
 import org.jboss.system.Registry;
 import org.jboss.util.id.GUID;
+import org.jboss.remoting.serialization.IMarshalledValue;
+import org.jboss.remoting.serialization.SerializationStreamFactory;
+import org.jboss.serial.objectmetamodel.safecloning.SafeClone;
 
 /**
  * A very simple implementation of it that branches to the local stuff.
- * 
+ *
  * @author <a href="mailto:marc.fleury at jboss.org">Marc Fleury</a>
  * @author Scott.Stark at jboss.org
  * @version $Revision$
@@ -58,23 +64,33 @@
    protected Invoker remoteInvoker;
 
    /** Static references to local invokers. */
-   protected static Invoker localInvoker; 
+   protected static Invoker localInvoker;
 
    /** The InvokerProxyHA class */
    protected static Class invokerProxyHA;
-   
+
    static
    {
-      try
-      {
-         // Using Class.forName() to avoid security problems in the client
-         invokerProxyHA = Class.forName("org.jboss.invocation.InvokerProxyHA");
-      }
-      catch (Throwable ignored)
-      {
-      }
+       try
+       {
+          // Using Class.forName() to avoid security problems in the client
+          invokerProxyHA = Class.forName("org.jboss.invocation.InvokerProxyHA");
+       }
+       catch (Throwable ignored)
+       {
+       }
+
+       try
+       {
+          // To guarantee backwards compatibility, we need to make sure this SerializationManager is being used
+          Class.forName("org.jboss.invocation.unified.interfaces.JavaSerializationManager");
+       }
+       catch (Throwable ignored)
+       {
+       }
+
    }
-   
+
    /**
     * Get the local invoker reference, useful for optimization.
     */
@@ -101,8 +117,8 @@
 
    /**
     * Returns wether we are local to the originating container or not.
-    * 
-    * @return true when we have the same GUID 
+    *
+    * @return true when we have the same GUID
     */
    public boolean isLocal()
    {
@@ -111,7 +127,7 @@
 
    /**
     * Whether the target is local
-    * 
+    *
     * @param invocation the invocation
     * @return true when the target is local
     */
@@ -128,19 +144,19 @@
          if (isClustered(invocation) == false)
             return false;
       }
-      
+
       // See whether we have a local target
       return hasLocalTarget(invocation);
    }
-   
+
    /**
     * Whether we are in a clustered environment<p>
-    * 
+    *
     * NOTE: This should be future compatible under any
     * new design where a prior target chooser interceptor
     * picks a non HA target than that code being
     * inside a ha invoker.
-    * 
+    *
     * @param invocation the invocation
     * @return true when a clustered invoker
     */
@@ -149,16 +165,16 @@
       // No clustering classes
       if (invokerProxyHA == null)
          return false;
-      
+
       // Is the invoker a HA invoker?
       InvocationContext ctx = invocation.getInvocationContext();
       Invoker invoker = ctx.getInvoker();
       return invoker != null && invokerProxyHA.isAssignableFrom(invoker.getClass());
    }
-   
+
    /**
     * Whether there is a local target
-    * 
+    *
     * @param invocation
     * @return true when in the registry
     */
@@ -166,10 +182,10 @@
    {
       return Registry.lookup(invocation.getObjectName()) != null;
    }
-   
+
    /**
-    * The invocation on the delegate, calls the right invoker.  
-    * Remote if we are remote, local if we are local. 
+    * The invocation on the delegate, calls the right invoker.
+    * Remote if we are remote, local if we are local.
     */
    public Object invoke(Invocation invocation)
       throws Exception
@@ -183,7 +199,7 @@
 
    /**
     * Invoke using local invoker
-    * 
+    *
     * @param invocation the invocation
     * @return the result
     * @throws Exception for any error
@@ -195,7 +211,7 @@
 
    /**
     * Invoke using local invoker and marshalled
-    * 
+    *
     * @param invocation the invocation
     * @return the result
     * @throws Exception for any error
@@ -227,23 +243,128 @@
       }
    }
 
-   /**
-    * Invoke using invoker
-    * 
-    * @param invocation the invocation
-    * @return the result
-    * @throws Exception for any error
-    */
-   protected Object invokeInvoker(Invocation invocation) throws Exception
+
+   /** These objects are safe to reuse in callByValue operations */
+   static final SafeClone safeToReuse = new SafeClone(){
+                 public boolean isSafeToReuse(Object obj) {
+                     if (obj==null)
+                     {
+                         return false;
+                     }
+
+                     if (obj instanceof ClientContainer ||
+                         obj instanceof String ||
+                         obj instanceof Number ||
+                         obj instanceof BigDecimal ||
+                         obj instanceof BigInteger ||
+                         obj instanceof Byte ||
+                         obj instanceof Double ||
+                         obj instanceof Float ||
+                         obj instanceof Integer ||
+                         obj instanceof Long ||
+                         obj instanceof Short)
+                     {
+                         return true;
+                     }
+                     else
+                     {
+                         return false;
+                     }
+                 }
+             };
+
+
+   protected IMarshalledValue createMarshalledValueForCallByValue(Object value) throws IOException
    {
-      //Specify that it is inter-vm on the invocation
-      invocation.setInterVM(Boolean.TRUE);
-      
-      InvocationContext ctx = invocation.getInvocationContext();
-      Invoker invoker = ctx.getInvoker();
-      return invoker.invoke(invocation);
+	   return SerializationStreamFactory.getManagerInstance().createdMarshalledValue(value);
    }
-   
+             
+   /** This method is for local calls when using pass-by-value*/
+   protected Object invokeLocalMarshalled(Invocation invocation) throws Exception
+   {
+
+       IMarshalledValue value = createMarshalledValueForCallByValue(invocation.getArguments());
+       MarshalledInvocation invocationCopy = createInvocationCopy(invocation, value);
+
+      // copy the Tx
+      Transaction tx = invocation.getTransaction();
+      invocationCopy.setTransaction(tx);
+
+      try
+      {
+         Object rtnValue = localInvoker.invoke(invocationCopy);
+         IMarshalledValue mv = createMarshalledValueForCallByValue(rtnValue);
+         return mv.get();
+      }
+      catch(Throwable t)
+      {
+         IMarshalledValue mv = SerializationStreamFactory.getManagerInstance().createdMarshalledValue(t);
+         Throwable t2 = (Throwable) mv.get();
+         if( t2 instanceof Exception )
+            throw (Exception) t2;
+         else
+            throw new UndeclaredThrowableException(t2);
+      }
+   }
+
+    /**  It is too expensive to serialize this entire object just to get class isolation
+         and MarshalledValues on local calls.
+         We are creating an in-memory copy without using serialization for that matter. 
+     * @throws ClassNotFoundException 
+     * @throws IOException */
+    private MarshalledInvocation createInvocationCopy(Invocation invocation, IMarshalledValue value) throws IOException, ClassNotFoundException {
+    	
+    		
+        MarshalledInvocation invocationCopy = new MarshalledInvocation(invocation);
+        invocationCopy.setMethod(null);
+        invocationCopy.setMethodHash(MarshalledInvocation.calculateHash(invocation.getMethod()));
+        invocationCopy.setMarshalledArguments(value);
+        invocationCopy.setArguments(null);
+        
+    	InvocationContext copyContext = null;
+    	if (invocation.getInvocationContext()!=null)
+    	{
+    		copyContext = (InvocationContext)createMarshalledValueForCallByValue(invocation.getInvocationContext()).get();
+    	}
+        invocationCopy.setInvocationContext(copyContext);
+        
+        Map payLoad = invocation.getPayload();
+        Map payloadCopy = new HashMap();
+        
+        if (payLoad!=null && payLoad.size()!=0)
+        {
+        	
+            Iterator keys = payLoad.keySet().iterator();
+            while (keys.hasNext())
+            {
+               Object currentKey = keys.next();
+               Object valueSource = payLoad.get(currentKey);
+               
+               payloadCopy.put(currentKey,this.createMarshalledValueForCallByValue(valueSource));
+            }
+        }
+
+        invocationCopy.payload = payloadCopy;
+        
+        
+
+        return invocationCopy;
+    }
+
+    /**
+     * Invoke using invoker
+     *
+     * @param invocation the invocation
+     * @return the result
+     * @throws Exception for any error
+     */
+    protected Object invokeInvoker(Invocation invocation) throws Exception
+    {
+       InvocationContext ctx = invocation.getInvocationContext();
+       Invoker invoker = ctx.getInvoker();
+       return invoker.invoke(invocation);
+    }
+
    /**
     * Externalize this instance.
     *

Modified: trunk/server/src/main/org/jboss/invocation/MarshalledInvocation.java
===================================================================
--- trunk/server/src/main/org/jboss/invocation/MarshalledInvocation.java	2008-11-17 19:46:02 UTC (rev 81178)
+++ trunk/server/src/main/org/jboss/invocation/MarshalledInvocation.java	2008-11-17 20:17:49 UTC (rev 81179)
@@ -21,6 +21,9 @@
  */
 package org.jboss.invocation;
 
+import org.jboss.remoting.serialization.IMarshalledValue;
+import org.jboss.remoting.serialization.SerializationStreamFactory;
+
 import java.io.DataOutputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -49,6 +52,7 @@
  * @author  <a href="mailto:marc at jboss.org">Marc Fleury</a>
  * @author Bill.Burke at jboss.org
  * @author Scott.Stark at jboss.org
+ * @author Clebert.Suconic at jboss.org - added pluggable serialization
  * @version $Revision$
  */
 public class MarshalledInvocation
@@ -57,6 +61,17 @@
 {
    // Constants -----------------------------------------------------
 
+   static
+   {
+      try
+      {
+          Class.forName("org.jboss.invocation.unified.interfaces.JavaSerializationManager");
+      }
+      catch (Exception e)
+      {
+      }
+   }
+
    /** Serial Version Identifier. */
    static final long serialVersionUID = -718723094688127810L;
    /** A flag indicating if the full hash format that includes the interface
@@ -74,9 +89,17 @@
 
    // These are here to avoid unneeded hash lookup
    protected transient long methodHash = 0;
-   protected transient MarshalledValue marshalledArgs = null;
+   protected transient Object marshalledArgs = null;
 
-   /** Get the full hash mode flag.
+    public long getMethodHash() {
+        return methodHash;
+    }
+
+    public void setMethodHash(long methodHash) {
+        this.methodHash = methodHash;
+    }
+
+    /** Get the full hash mode flag.
     * @return the full hash mode flag.
     */
    public static boolean getUseFullHashMode()
@@ -415,11 +438,11 @@
       Object value = super.getValue(key);
 
       // The map may contain serialized values of the fields
-      if (value instanceof MarshalledValue)
+      if (value instanceof IMarshalledValue)
       {
          try
          {
-            MarshalledValue mv = (MarshalledValue) value;
+            IMarshalledValue mv = (IMarshalledValue) value;
             value = mv.get();
          }
          catch (Exception e)
@@ -443,20 +466,35 @@
       Object value = getPayload().get(key);
 
       // The map may contain serialized values of the fields
-      if (value instanceof MarshalledValue)
-      {
-         try
-         {
-            MarshalledValue mv = (MarshalledValue) value;
-            value = mv.get();
-         }
-         catch (Exception e)
-         {
-            JBossLazyUnmarshallingException ise = new JBossLazyUnmarshallingException("getPayloadValue failed");
-            ise.initCause(e);
-            throw ise;
-         }
-      }
+       if (value instanceof MarshalledValue)
+       {
+          try
+          {
+             MarshalledValue mv = (MarshalledValue) value;
+             value = mv.get();
+          }
+          catch (Exception e)
+          {
+             JBossLazyUnmarshallingException ise = new JBossLazyUnmarshallingException("getPayloadValue failed");
+             ise.initCause(e);
+             throw ise;
+          }
+       }
+       else
+       if (value instanceof IMarshalledValue)
+       {
+           try
+           {
+              IMarshalledValue mv = (IMarshalledValue) value;
+              value = mv.get();
+           }
+           catch (Exception e)
+           {
+              JBossLazyUnmarshallingException ise = new JBossLazyUnmarshallingException("getPayloadValue failed");
+              ise.initCause(e);
+              throw ise;
+           }
+       }
       return value;
    }
 
@@ -464,16 +502,33 @@
    {
       if (this.args == null)
       {
-         try
-         {
-            this.args = (Object[]) marshalledArgs.get();
-         }
-         catch (Exception e)
-         {
-            JBossLazyUnmarshallingException ise = new JBossLazyUnmarshallingException("getArguments failed");
-            ise.initCause(e);
-            throw ise;
-         }
+    	  if (marshalledArgs instanceof MarshalledValue)
+    	  {
+             try
+             {
+                this.args = (Object[]) ((MarshalledValue)marshalledArgs).get();
+             }
+             catch (Exception e)
+             {
+                JBossLazyUnmarshallingException ise = new JBossLazyUnmarshallingException("getArguments failed");
+                ise.initCause(e);
+                throw ise;
+             }
+    	  }
+    	  else
+    	  if (marshalledArgs instanceof IMarshalledValue)
+    	  {
+              try
+              {
+                 this.args = (Object[]) ((IMarshalledValue)marshalledArgs).get();
+              }
+              catch (Exception e)
+              {
+                 JBossLazyUnmarshallingException ise = new JBossLazyUnmarshallingException("getArguments failed");
+                 ise.initCause(e);
+                 throw ise;
+              }
+    	  }
       }
       return args;
    }
@@ -499,13 +554,20 @@
 
       out.writeObject(this.objectName);
 
+      String serializationType = null;
+
+      if (invocationContext!=null)
+      {
+          serializationType = (String)invocationContext.getValue("SERIALIZATION_TYPE");
+      }
+
       if(this.args == null && this.marshalledArgs != null)
       {
          out.writeObject(this.marshalledArgs);
       }
       else
       {
-         out.writeObject(new MarshalledValue(this.args));
+         out.writeObject(createMarshalledValue(serializationType,this.args));
       }
 
 
@@ -535,7 +597,7 @@
             // no reason to marshall an already marshalled value
             if(!(value instanceof MarshalledValue))
             {
-               value = new MarshalledValue(value);
+               value = createMarshalledValue(serializationType,value);
             }
 
             out.writeObject(value);
@@ -560,42 +622,61 @@
       }
    }
 
-   public void readExternal(java.io.ObjectInput in)
-           throws IOException, ClassNotFoundException
-   {
-      tpc = in.readObject();
-      this.methodHash = in.readLong();
+    private Object createMarshalledValue(String serializationType, Object valueToBeMarshalled) throws IOException {
+        if (serializationType!=null)
+        {
+            return (IMarshalledValue)SerializationStreamFactory.getManagerInstance(serializationType).createdMarshalledValue(valueToBeMarshalled);
+        }
+        else
+        {
+            return new MarshalledValue(valueToBeMarshalled);
+        }
+    }
 
-      this.objectName = in.readObject();
+    public void readExternal(java.io.ObjectInput in)
+            throws IOException, ClassNotFoundException
+    {
+       tpc = in.readObject();
+       this.methodHash = in.readLong();
 
-      marshalledArgs = (MarshalledValue) in.readObject();
+       this.objectName = in.readObject();
 
-      int payloadSize = in.readInt();
-      if (payloadSize > 0)
-      {
-         payload = new HashMap();
-         for (int i = 0; i < payloadSize; i++)
-         {
-            Object key = in.readObject();
-            Object value = in.readObject();
-            payload.put(key, value);
-         }
-      }
+       marshalledArgs = in.readObject();
 
-      int as_is_payloadSize = in.readInt();
-      if (as_is_payloadSize > 0)
-      {
-         as_is_payload = new HashMap();
-         for (int i = 0; i < as_is_payloadSize; i++)
-         {
-            Object key = in.readObject();
-            Object value = in.readObject();
-            as_is_payload.put(key, value);
-         }
-      }
-      // TODO invocationType should be removed from as is payload
-      // for now, it is in there for binary compatibility
-      invocationType = (InvocationType)getAsIsValue(InvocationKey.TYPE);
+       int payloadSize = in.readInt();
+       if (payloadSize > 0)
+       {
+          payload = new HashMap();
+          for (int i = 0; i < payloadSize; i++)
+          {
+             Object key = in.readObject();
+             Object value = in.readObject();
+             payload.put(key, value);
+          }
+       }
+
+       int as_is_payloadSize = in.readInt();
+       if (as_is_payloadSize > 0)
+       {
+          as_is_payload = new HashMap();
+          for (int i = 0; i < as_is_payloadSize; i++)
+          {
+             Object key = in.readObject();
+             Object value = in.readObject();
+             as_is_payload.put(key, value);
+          }
+       }
+       // TODO invocationType should be removed from as is payload
+       // for now, it is in there for binary compatibility
+       invocationType = (InvocationType)getAsIsValue(InvocationKey.TYPE);
+    }
+
+   /**
+    * This is method is used for chaing the MarshalledAruments in a Call-By-Value operation.
+    * */
+   public void setMarshalledArguments(IMarshalledValue marshalledValue)
+   {
+      marshalledArgs = marshalledValue;
    }
 
    private static class DeclaredMethodsAction implements PrivilegedAction

Modified: trunk/server/src/main/org/jboss/invocation/MarshalledValue.java
===================================================================
--- trunk/server/src/main/org/jboss/invocation/MarshalledValue.java	2008-11-17 19:46:02 UTC (rev 81178)
+++ trunk/server/src/main/org/jboss/invocation/MarshalledValue.java	2008-11-17 20:17:49 UTC (rev 81179)
@@ -21,7 +21,6 @@
  */
 package org.jboss.invocation;
 
-import java.io.DataOutputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -50,7 +49,7 @@
     * reference.
     */
    private byte[] serializedForm;
-   
+
    /**
     * The RMI MarshalledObject hash of the serializedForm array
     */
@@ -78,7 +77,7 @@
       {
          hash = 31 * hash + serializedForm[i];
       }
-      
+
       hashCode = hash;
    }
 
@@ -135,7 +134,7 @@
       }
       return equals;
    }
-   
+
    /**
     * The object implements the readExternal method to restore its
     * contents by calling the methods of DataInput for primitive
@@ -144,7 +143,7 @@
     * and with the same types as were written by writeExternal.
     *
     * @param in the stream to read data from in order to restore the object
-    * 
+    *
     * @throws IOException              if I/O errors occur
     * @throws ClassNotFoundException   If the class for an object being
     *                                  restored cannot be found.
@@ -174,7 +173,7 @@
     *            method of this Externalizable class.
     *
     * @param out    the stream to write the object to
-    * 
+    *
     * @throws IOException   Includes any I/O exceptions that may occur
     */
    public void writeExternal(ObjectOutput out) throws IOException

Added: trunk/server/src/main/org/jboss/invocation/MarshalledValueEX.java
===================================================================
--- trunk/server/src/main/org/jboss/invocation/MarshalledValueEX.java	                        (rev 0)
+++ trunk/server/src/main/org/jboss/invocation/MarshalledValueEX.java	2008-11-17 20:17:49 UTC (rev 81179)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.invocation;
+
+import java.io.IOException;
+
+import org.jboss.remoting.serialization.IMarshalledValue;
+
+/**
+ * This is a way to have MarshalledValue implementing IMarshalledValue without
+ * changing legacy Invokers (Pooled, RMI)
+ * 
+ * @author Clebert Suconic
+ */
+public class MarshalledValueEX extends MarshalledValue
+   implements IMarshalledValue
+{
+   private static final long serialVersionUID = -1527598981234110322L;
+
+   public MarshalledValueEX()
+   {
+      super();
+   }
+
+   public MarshalledValueEX(Object obj) throws IOException
+   {
+      super(obj);
+   }
+}

Modified: trunk/server/src/main/org/jboss/invocation/MarshallingInvokerInterceptor.java
===================================================================
--- trunk/server/src/main/org/jboss/invocation/MarshallingInvokerInterceptor.java	2008-11-17 19:46:02 UTC (rev 81178)
+++ trunk/server/src/main/org/jboss/invocation/MarshallingInvokerInterceptor.java	2008-11-17 20:17:49 UTC (rev 81179)
@@ -37,7 +37,7 @@
    {
       // For externalization to work
    }
-   
+
    // Public --------------------------------------------------------
 
    /**
@@ -46,8 +46,19 @@
    public Object invoke(Invocation invocation)
       throws Exception
    {
+
+      /*
+          if(isLocal(invocation))
+             return invokeLocalMarshalled(invocation);
+          else
+             return invokeInvoker(invocation);
+
+          invokeLocalMarshalled is an optimized method for call-by-values. we don't need to serialize the entire Invocation
+          for having call-by-value.
+      */
+
       if(isLocal(invocation))
-         return invokeMarshalled(invocation);
+         return invokeLocalMarshalled(invocation);
       else
          return invokeInvoker(invocation);
    }

Added: trunk/server/src/main/org/jboss/invocation/unified/interfaces/JavaSerializationManager.java
===================================================================
--- trunk/server/src/main/org/jboss/invocation/unified/interfaces/JavaSerializationManager.java	                        (rev 0)
+++ trunk/server/src/main/org/jboss/invocation/unified/interfaces/JavaSerializationManager.java	2008-11-17 20:17:49 UTC (rev 81179)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.invocation.unified.interfaces;
+
+import java.io.IOException;
+
+import org.jboss.invocation.MarshalledValueEX;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.serialization.IMarshalledValue;
+import org.jboss.remoting.serialization.SerializationStreamFactory;
+
+/**
+ * JavaSerializationmanager from JBossRemoting doesn't use the same
+ * MarshalledValue specified by org.jboss.invocation. As
+ * org.jboss.invocation.MarshalledValue could use caching features from JBossAS,
+ * we will need to use that MarshalledValue.
+ * 
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ */
+public class JavaSerializationManager extends
+   org.jboss.remoting.serialization.impl.java.JavaSerializationManager
+{
+   protected static final Logger log = Logger.getLogger(JavaSerializationManager.class);
+
+   static
+   {
+      register();
+   }
+
+   /** Register yourself as Java manager into SerializationStreamFactory */
+   private static void register()
+   {
+      register("compatible");
+      register(SerializationStreamFactory.JAVA);
+
+      try
+      {
+         if (SerializationStreamFactory.getManagerInstance().getClass() 
+            == org.jboss.remoting.serialization.impl.java.JavaSerializationManager.class)
+         {
+            register(SerializationStreamFactory.DEFAULT);
+         }
+      } catch (Exception e)
+      {
+         log.error(e);
+      }
+   }
+
+   private static void register(String provider)
+   {
+      try
+      {
+         SerializationStreamFactory.setManagerClassName(
+            provider, JavaSerializationManager.class.getName());
+      }
+      catch (ClassNotFoundException e)
+      {
+         log.error(e);
+      }
+      catch (IllegalAccessException e)
+      {
+         log.error(e);
+      }
+      catch (InstantiationException e)
+      {
+         log.error(e);
+      }
+   }
+
+   /**
+    * Creates a MarshalledValue that does lazy serialization.
+    */
+   public IMarshalledValue createdMarshalledValue(Object source) throws IOException
+   {
+      if (source instanceof IMarshalledValue)
+      {
+         return (IMarshalledValue) source;
+      }
+      else
+      {
+         return new MarshalledValueEX(source);
+      }
+   }
+}

Modified: trunk/server/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerProxy.java
===================================================================
--- trunk/server/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerProxy.java	2008-11-17 19:46:02 UTC (rev 81178)
+++ trunk/server/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerProxy.java	2008-11-17 20:17:49 UTC (rev 81179)
@@ -34,6 +34,7 @@
 import org.jboss.logging.Logger;
 import org.jboss.remoting.Client;
 import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.serialization.IMarshalledValue;
 
 /**
  * This represents the client side of the EJB invoker.  This invoker uses
@@ -44,6 +45,17 @@
  */
 public class UnifiedInvokerProxy implements Invoker, Externalizable
 {
+    static
+    {
+        try
+        {
+            Class.forName("org.jboss.invocation.unified.interfaces.JavaSerializationManager");
+        }
+        catch (Exception e)
+        {
+        }
+    }
+
    static final long serialVersionUID = -1108158470271861548L;
 
    private transient Client client;
@@ -157,8 +169,18 @@
    {
       Object response = null;
 
+      // Earlier versions of InvokerLocator don't have a findSerializationType() method.
       try
       {
+         invocation.getInvocationContext().setValue("SERIALIZATION_TYPE",locator.findSerializationType());
+      }
+      catch (NoSuchMethodError e)
+      {
+         invocation.getInvocationContext().setValue("SERIALIZATION_TYPE", "java");
+      }
+      
+      try
+      {
          response = client.invoke(invocation, null);
 
          if(response instanceof Exception)
@@ -169,6 +191,10 @@
          {
             return ((MarshalledObject) response).get();
          }
+         if (response instanceof IMarshalledValue)
+         {
+             return ((IMarshalledValue)response).get();
+         }
          return response;
 
       }




More information about the jboss-cvs-commits mailing list