[jboss-cvs] JBossAS SVN: r60518 - trunk/cluster/src/main/org/jboss/ha/framework/server.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 13 14:54:28 EST 2007


Author: jerrygauth
Date: 2007-02-13 14:54:27 -0500 (Tue, 13 Feb 2007)
New Revision: 60518

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
Log:
JBAS-3583, HAPartition using optimized response marshaller

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2007-02-13 19:13:10 UTC (rev 60517)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2007-02-13 19:54:27 UTC (rev 60518)
@@ -197,7 +197,43 @@
       mvos.flush();
       return baos.toByteArray();
    }
+   
+   /**
+    * Creates a response object from a byte buffer - optimized for response marshalling
+    */
+   public static Object objectFromByteBufferResponse (byte[] buffer) throws Exception
+   {
+      if(buffer == null) 
+         return null;
 
+      if (buffer[0] == NULL_VALUE)
+         return null;
+
+      ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+      // read past the null/serializable byte
+      bais.read();
+      MarshalledValueInputStream mvis = new MarshalledValueInputStream(bais);
+      return mvis.readObject();
+   }
+   
+   /**
+    * Serializes a response object into a byte buffer, optimized for response marshalling.
+    * The object has to implement interface Serializable or Externalizable
+    */
+   public static byte[] objectToByteBufferResponse (Object obj) throws Exception
+   {
+      if (obj == null)
+         return new byte[]{NULL_VALUE};
+
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      // write a marker to stream to distinguish from null value stream
+      baos.write(SERIALIZABLE_VALUE);
+      MarshalledValueOutputStream mvos = new MarshalledValueOutputStream(baos);
+      mvos.writeObject(obj);
+      mvos.flush();
+      return baos.toByteArray();
+   }
+
    private static JChannel createMuxChannel(ClusterPartitionConfig config)
    {
       JChannelFactoryMBean factory = config.getMultiplexer();
@@ -1627,12 +1663,12 @@
 
       public Object objectFromByteBuffer(byte[] buf) throws Exception
       {
-         return ClusterPartition.objectFromByteBuffer(buf);
+         return ClusterPartition.objectFromByteBufferResponse(buf);
       }
 
       public byte[] objectToByteBuffer(Object obj) throws Exception
       {
-         return ClusterPartition.objectToByteBuffer(obj);
+         return ClusterPartition.objectToByteBufferResponse(obj);
       }      
    }
    




More information about the jboss-cvs-commits mailing list