[jboss-svn-commits] JBL Code SVN: r19868 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue May 6 01:17:52 EDT 2008


Author: mark.proctor at jboss.com
Date: 2008-05-06 01:17:52 -0400 (Tue, 06 May 2008)
New Revision: 19868

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/InputPersister.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/OutputPersister.java
Log:
JBRULES-1598 Efficient WorkingMemory serialization with binary protocol
-Added helper method to serialize WM and to do a round trip test at the same time, to make sure information is not lost on serialization.

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/InputPersister.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/InputPersister.java	2008-05-06 05:16:30 UTC (rev 19867)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/InputPersister.java	2008-05-06 05:17:52 UTC (rev 19868)
@@ -103,15 +103,8 @@
             context.wm.getObjectStore().addHandle( handle,
                                                    object );
 
-            int type = stream.readInt();
-            if ( type == PersisterEnums.RIGHT_TUPLE ) {
-                type = PersisterEnums.REPEAT;
-                while ( type == PersisterEnums.REPEAT ) {
-                    readRightTuple( context,
-                                    handle );
-                    type = stream.readInt();
-                }
-            }
+            readRightTuples( handle,
+                             context );
         }
 
         EntryPointNode node = ruleBase.getRete().getEntryPointNode( EntryPoint.DEFAULT );
@@ -134,6 +127,15 @@
         readActivations( context );
     }
 
+    public static void readRightTuples(InternalFactHandle factHandle,
+                                       WMSerialisationInContext context) throws IOException {
+        ObjectInputStream stream = context.stream;
+        while ( stream.readInt() == PersisterEnums.RIGHT_TUPLE ) {
+            readRightTuple( context,
+                            factHandle );
+        }
+    }
+
     public static void readRightTuple(WMSerialisationInContext context,
                                       InternalFactHandle factHandle) throws IOException {
         ObjectInputStream stream = context.stream;
@@ -150,10 +152,10 @@
 
         memory.getRightTupleMemory().add( rightTuple );
     }
-    
-    public static void readLeftTuples(WMSerialisationInContext context)  throws IOException {
+
+    public static void readLeftTuples(WMSerialisationInContext context) throws IOException {
         ObjectInputStream stream = context.stream;
-        
+
         while ( stream.readInt() == PersisterEnums.LEFT_TUPLE ) {
             LeftTupleSink sink = (LeftTupleSink) context.sinks.get( stream.readInt() );
             int factHandleId = stream.readInt();
@@ -268,6 +270,8 @@
                                                 rule,
                                                 subRule );
 
+        leftTuple.setActivation( activation );
+        
         boolean activated = stream.readBoolean();
         activation.setActivated( activated );
         if ( activated ) {
@@ -317,11 +321,13 @@
             int tuplePos = stream.readInt();
             leftTuple = (LeftTuple) context.terminalTupleMap.get( tuplePos );
         }
-
+        
+        long propagationNumber = stream.readLong();
+        
         int factHandleId = stream.readInt();
         InternalFactHandle factHandle = context.handles.get( factHandleId );
 
-        long propagationNumber = stream.readLong();
+
         int activeActivations = stream.readInt();
         int dormantActivations = stream.readInt();
         String entryPointId = stream.readUTF();

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/OutputPersister.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/OutputPersister.java	2008-05-06 05:16:30 UTC (rev 19867)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/OutputPersister.java	2008-05-06 05:17:52 UTC (rev 19868)
@@ -80,21 +80,8 @@
             strategy.write( stream,
                             object );
 
-            // Write out RightTuples for FactHandle
-            if ( handle.getRightTuple() != null ) {
-                stream.writeInt( PersisterEnums.RIGHT_TUPLE );
-                int i = 0;
-                for ( RightTuple rightTuple = handle.getRightTuple(); rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandleNext() ) {
-                    if ( i != 0 ) {
-                        stream.writeInt( PersisterEnums.REPEAT );
-                    }
-                    writeRightTuple( rightTuple,
-                                     context );
-                    i++;
-                }
-            } else {
-                stream.writeInt( PersisterEnums.END );
-            }
+            writeRightTuples( handle,
+                              context );
         }
 
         writeLeftTuples( context );
@@ -106,6 +93,17 @@
         stream.writeInt( PersisterEnums.END );
     }
 
+    public static void writeRightTuples(InternalFactHandle handle,
+                                        WMSerialisationOutContext context) throws IOException {
+        ObjectOutputStream stream = context.stream;
+        for ( RightTuple rightTuple = handle.getRightTuple(); rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandleNext() ) {
+            stream.writeInt( PersisterEnums.RIGHT_TUPLE );
+            writeRightTuple( rightTuple,
+                             context );
+        }
+        stream.writeInt( PersisterEnums.END );
+    }
+
     public static void writeRightTuple(RightTuple rightTuple,
                                        WMSerialisationOutContext context) throws IOException {
         ObjectOutputStream stream = context.stream;




More information about the jboss-svn-commits mailing list