[jboss-svn-commits] JBL Code SVN: r19380 - in labs/jbossrules/branches/ming-serialization: drools-compiler/src/test/java/org/drools/integrationtests and 10 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Apr 2 14:36:22 EDT 2008


Author: mingjin
Date: 2008-04-02 14:36:22 -0400 (Wed, 02 Apr 2008)
New Revision: 19380

Added:
   labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/util/DroolsStreamUtils.java
Modified:
   labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
   labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/LargeRuleBaseSerializationTest.java
   labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java
   labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
   labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/SerializationHelper.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/agent/FileScanner.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/agent/HttpClientImpl.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectOutputStream.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/util/BinaryRuleBaseLoader.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/agent/RuleBaseAssemblerTest.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/agent/URLScannerTest.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/common/DroolsObjectIOTest.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/integrationtests/SerializationHelper.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/rule/LogicTransformerTest.java
   labs/jbossrules/branches/ming-serialization/drools-jbrms/src/main/java/org/drools/brms/server/ServiceImplementation.java
   labs/jbossrules/branches/ming-serialization/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java
   labs/jbossrules/branches/ming-serialization/drools-jbrms/src/test/java/org/drools/brms/server/contenthandler/ContentHandlerTest.java
Log:
Added DroolsStreamUtils and modified other files to use it.

Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -16,12 +16,8 @@
  * limitations under the License.
  */
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
 import java.io.StringReader;
 import java.lang.reflect.Field;
 import java.util.HashMap;
@@ -40,8 +36,6 @@
 import org.drools.WorkingMemory;
 import org.drools.base.DefaultKnowledgeHelper;
 import org.drools.common.ActivationGroupNode;
-import org.drools.common.DroolsObjectInputStream;
-import org.drools.common.DroolsObjectOutputStream;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.LogicalDependency;
 import org.drools.common.RuleFlowGroupNode;
@@ -1213,12 +1207,7 @@
         assertTrue( p instanceof WorkflowProcessImpl );
 
         //now serialization
-        ByteArrayOutputStream data = new ByteArrayOutputStream();
-        ObjectOutput out = new DroolsObjectOutputStream( data );
-        out.writeObject( pkg );
-
-        ObjectInput objIn = new DroolsObjectInputStream( new ByteArrayInputStream( data.toByteArray() ) );
-        Package pkg2 = (Package) objIn.readObject();
+        Package pkg2 = (Package) SerializationHelper.serializeObject(pkg);
         assertNotNull( pkg2 );
 
         flows = pkg2.getRuleFlows();

Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/LargeRuleBaseSerializationTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/LargeRuleBaseSerializationTest.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/LargeRuleBaseSerializationTest.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -7,12 +7,9 @@
 import org.drools.rule.Package;
 import org.drools.RuleBase;
 import org.drools.RuleBaseFactory;
-import org.drools.common.DroolsObjectOutputStream;
-import org.drools.common.DroolsObjectInputStream;
+import org.drools.util.DroolsStreamUtils;
 
 import java.io.StringReader;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
 
 import junit.framework.TestCase;
 
@@ -26,21 +23,25 @@
 
     private static RuleBase ruleBase;
     private static byte[]   bytes;
+    private static byte[]   compressedBytes;
 
     protected void setUp() throws Exception {
         if (ruleBase == null)
             ruleBase    = createRuleBase();
         if (bytes == null) {
-            bytes   = SerializationHelper.serializeOut(ruleBase);
+            bytes   = DroolsStreamUtils.streamOut(ruleBase);
         }
+        if (compressedBytes == null) {
+            compressedBytes = DroolsStreamUtils.streamOut(ruleBase, true);
+        }
     }
 
     public void testUnmarshallingPerformance() throws Exception {
-        SerializationHelper.serializeIn(bytes);
+        SerializationHelper.streamIn(bytes);
         long    time    = System.currentTimeMillis();
 
         for (int i = ITERATIONS; i-- > 0; ) {
-            SerializationHelper.serializeIn(bytes);
+            DroolsStreamUtils.streamIn(bytes);
         }
         System.out.println("Total time of unmarshalling "+ITERATIONS+" times is "+
                            format(System.currentTimeMillis()-time));
@@ -49,12 +50,31 @@
     public void testMarshallingPerformance() throws Exception {
         long    time    = System.currentTimeMillis();
         for (int i = ITERATIONS; i-- > 0; ) {
-            SerializationHelper.serializeOut(ruleBase);
+            DroolsStreamUtils.streamOut(ruleBase);
         }
         System.out.println("Total time of marshalling "+ITERATIONS+" times is "+
                            format(System.currentTimeMillis()-time)+" with size of "+bytes.length+" bytes");
     }
 
+    public void testUnmarshallWithCompressionPerformance() throws Exception {
+        long    time    = System.currentTimeMillis();
+
+        for (int i = ITERATIONS; i-- > 0; ) {
+            DroolsStreamUtils.streamIn(compressedBytes, true);
+        }
+        System.out.println("Total time of unmarshalling with compression "+ITERATIONS+" times is "+
+                           format(System.currentTimeMillis()-time));
+    }
+
+    public void testMarshallWithCompressionPerformance() throws Exception {
+        long    time    = System.currentTimeMillis();
+        for (int i = ITERATIONS; i-- > 0; ) {
+            DroolsStreamUtils.streamOut(ruleBase, true);
+        }
+        System.out.println("Total time of marshalling with compression "+ITERATIONS+" times is "+
+                           format(System.currentTimeMillis()-time)+" with size of "+compressedBytes.length+" bytes");
+    }
+
     private static final int    MILLIS_IN_SECOND    = 1000;
     private static final int    MILLIS_IN_MINUTE    = 60*MILLIS_IN_SECOND;
     private static final int    MILLIS_IN_HOUR      = 60*MILLIS_IN_MINUTE;

Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -2,12 +2,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.io.InputStreamReader;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
 import java.io.Reader;
 import java.io.StringReader;
 import java.util.ArrayList;
@@ -28,7 +23,7 @@
 import org.drools.RuleBaseFactory;
 import org.drools.StatefulSession;
 import org.drools.WorkingMemory;
-import org.drools.common.DroolsObjectInputStream;
+import org.drools.util.DroolsStreamUtils;
 import org.drools.common.InternalFactHandle;
 import org.drools.compiler.PackageBuilder;
 import org.drools.compiler.PackageBuilderConfiguration;
@@ -77,7 +72,7 @@
         final Person bob = new Person( "bob" );
         workingMemory.insert( bob );
 
-        final byte[] wm = SerializationHelper.serializeOut( workingMemory );
+        final byte[] wm = SerializationHelper.streamOut( workingMemory );
 
         workingMemory = ruleBase.newStatefulSession( new ByteArrayInputStream( wm ) );
 
@@ -127,7 +122,7 @@
         map = SerializationHelper.serializeObject(map);
         ruleBase = (RuleBase) map.get( "x" );
 
-        final byte[] wm = SerializationHelper.serializeOut( workingMemory );
+        final byte[] wm = DroolsStreamUtils.streamOut( workingMemory );
 
         workingMemory = ruleBase.newStatefulSession( new ByteArrayInputStream( wm ) );
 
@@ -202,7 +197,7 @@
         WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         // serialise the working memory before population
-        final byte[] wm = SerializationHelper.serializeOut( workingMemory );
+        final byte[] wm = DroolsStreamUtils.streamOut( workingMemory );
         workingMemory = ruleBase.newStatefulSession( new ByteArrayInputStream( wm ) );
 
         ruleBase.addPackage( pkg );
@@ -281,7 +276,7 @@
         ruleBase = (RuleBase) map.get( "x" );
 
         // now try serialising with a fully populated wm from a serialised rulebase
-        final byte[] wm = SerializationHelper.serializeOut( workingMemory );
+        final byte[] wm = DroolsStreamUtils.streamOut( workingMemory );
         workingMemory = ruleBase.newStatefulSession( new ByteArrayInputStream( wm ) );
 
         final Rule[] rules = ruleBase.getPackages()[0].getRules();
@@ -343,7 +338,7 @@
         assertEquals( list.size(), 1 );
         assertEquals( "stilton", list.get( 0 ));
 
-        byte[] serializedSession = SerializationHelper.serializeOut( session );
+        byte[] serializedSession = DroolsStreamUtils.streamOut( session );
         session.dispose();
 
         // now recreate the rulebase, deserialize the session and test it
@@ -405,7 +400,7 @@
         p.setIntPrimitive( (int) 3 );
         workingMemory.insert( p );
 
-        final byte[] wm = SerializationHelper.serializeOut( workingMemory );
+        final byte[] wm = DroolsStreamUtils.streamOut( workingMemory );
 
         workingMemory = ruleBase.newStatefulSession( new ByteArrayInputStream( wm ) );
 
@@ -469,12 +464,12 @@
                       results.get( 0 ) );
 
         // serialize session and rulebase out
-        byte[] serializedSession = SerializationHelper.serializeOut( session );
-        byte[] serializedRulebase = SerializationHelper.serializeOut( ruleBase );
+        byte[] serializedSession = DroolsStreamUtils.streamOut( session );
+        byte[] serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
         session.dispose();
 
         // now deserialize the rulebase, deserialize the session and test it
-        ruleBase = (RuleBase) SerializationHelper.serializeIn( serializedRulebase );
+        ruleBase = (RuleBase) SerializationHelper.streamIn( serializedRulebase );
         session = ruleBase.newStatefulSession( new ByteArrayInputStream( serializedSession ) );
 
         // dynamically add a new package
@@ -504,8 +499,8 @@
         serializedSession = null;
         serializedRulebase = null;
 
-        serializedSession = SerializationHelper.serializeOut( session );
-        serializedRulebase = SerializationHelper.serializeOut( ruleBase );
+        serializedSession = DroolsStreamUtils.streamOut( session );
+        serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
 
         // dispose session
         session.dispose();
@@ -540,8 +535,8 @@
                                                                                     10 ) );
         session.fireAllRules();
 
-        byte[] serializedSession = SerializationHelper.serializeOut( session );
-        byte[] serializedRulebase = SerializationHelper.serializeOut( ruleBase );
+        byte[] serializedSession = DroolsStreamUtils.streamOut( session );
+        byte[] serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
 
         session.dispose();
 
@@ -551,7 +546,7 @@
                       results.get( 0 ) );
 
         // now recreate the rulebase, deserialize the session and test it
-        ruleBase = (RuleBase) SerializationHelper.serializeIn( serializedRulebase );
+        ruleBase = (RuleBase) SerializationHelper.streamIn( serializedRulebase );
         session = ruleBase.newStatefulSession( new ByteArrayInputStream( serializedSession ) );
         results = (List) session.getGlobal( "results" );
 
@@ -581,8 +576,8 @@
         serializedSession = null;
         serializedRulebase = null;
 
-        serializedSession = SerializationHelper.serializeOut( session );
-        serializedRulebase = SerializationHelper.serializeOut( ruleBase );
+        serializedSession = DroolsStreamUtils.streamOut( session );
+        serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
 
         session.dispose();
     }
@@ -609,8 +604,8 @@
                                                                                     10 ) );
         session.fireAllRules();
 
-        byte[] serializedSession = SerializationHelper.serializeOut( session );
-        byte[] serializedRulebase = SerializationHelper.serializeOut( ruleBase );
+        byte[] serializedSession = DroolsStreamUtils.streamOut( session );
+        byte[] serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
 
         session.dispose();
 
@@ -620,7 +615,7 @@
                       results.get( 0 ) );
 
         // now recreate the rulebase, deserialize the session and test it
-        ruleBase = (RuleBase) SerializationHelper.serializeIn( serializedRulebase );
+        ruleBase = (RuleBase) SerializationHelper.streamIn( serializedRulebase );
         session = ruleBase.newStatefulSession( new ByteArrayInputStream( serializedSession ) );
         results = (List) session.getGlobal( "results" );
 
@@ -648,13 +643,13 @@
         serializedSession = null;
         serializedRulebase = null;
 
-        serializedSession = SerializationHelper.serializeOut( session );
-        serializedRulebase = SerializationHelper.serializeOut( ruleBase );
+        serializedSession = DroolsStreamUtils.streamOut( session );
+        serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
 
         session.dispose();
 
         // now recreate the rulebase, deserialize the session and test it
-        ruleBase = (RuleBase) SerializationHelper.serializeIn( serializedRulebase );
+        ruleBase = (RuleBase) SerializationHelper.streamIn( serializedRulebase );
         session = ruleBase.newStatefulSession( new ByteArrayInputStream( serializedSession ) );
         results = (List) session.getGlobal( "results" );
 
@@ -688,13 +683,13 @@
         serializedSession = null;
         serializedRulebase = null;
 
-        serializedSession = SerializationHelper.serializeOut( session );
-        serializedRulebase = SerializationHelper.serializeOut( ruleBase );
+        serializedSession = DroolsStreamUtils.streamOut( session );
+        serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
 
         session.dispose();
 
         // now recreate the rulebase, deserialize the session and test it
-        ruleBase = (RuleBase) SerializationHelper.serializeIn( serializedRulebase );
+        ruleBase = (RuleBase) SerializationHelper.streamIn( serializedRulebase );
         session = ruleBase.newStatefulSession( new ByteArrayInputStream( serializedSession ) );
         results = (List) session.getGlobal( "results" );
 
@@ -723,8 +718,8 @@
         serializedSession = null;
         serializedRulebase = null;
 
-        serializedSession = SerializationHelper.serializeOut( session );
-        serializedRulebase = SerializationHelper.serializeOut( ruleBase );
+        serializedSession = DroolsStreamUtils.streamOut( session );
+        serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
 
         session.dispose();
 
@@ -759,8 +754,8 @@
                                                                                     10 ) );
         session.fireAllRules();
 
-        byte[] serializedSession = SerializationHelper.serializeOut( session );
-        byte[] serializedRulebase = SerializationHelper.serializeOut( ruleBase );
+        byte[] serializedSession = DroolsStreamUtils.streamOut( session );
+        byte[] serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
 
         session.dispose();
 
@@ -770,7 +765,7 @@
                       results.get( 0 ) );
 
         // now recreate the rulebase, deserialize the session and test it
-        ruleBase = (RuleBase) SerializationHelper.serializeIn( serializedRulebase );
+        ruleBase = (RuleBase) SerializationHelper.streamIn( serializedRulebase );
         session = ruleBase.newStatefulSession( new ByteArrayInputStream( serializedSession ) );
         results = (List) session.getGlobal( "results" );
 
@@ -798,13 +793,13 @@
         serializedSession = null;
         serializedRulebase = null;
 
-        serializedSession = SerializationHelper.serializeOut( session );
-        serializedRulebase = SerializationHelper.serializeOut( ruleBase );
+        serializedSession = DroolsStreamUtils.streamOut( session );
+        serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
 
         session.dispose();
 
         // now recreate the rulebase, deserialize the session and test it
-        ruleBase = (RuleBase) SerializationHelper.serializeIn( serializedRulebase );
+        ruleBase = (RuleBase) SerializationHelper.streamIn( serializedRulebase );
         session = ruleBase.newStatefulSession( new ByteArrayInputStream( serializedSession ) );
         results = (List) session.getGlobal( "results" );
 
@@ -826,7 +821,7 @@
 
 
         // now recreate the rulebase, deserialize the session and test it
-        ruleBase = (RuleBase) SerializationHelper.serializeIn( serializedRulebase );
+        ruleBase = (RuleBase) SerializationHelper.streamIn( serializedRulebase );
         session = ruleBase.newStatefulSession( new ByteArrayInputStream( serializedSession ) );
         results = (List) session.getGlobal( "results" );
 
@@ -849,8 +844,8 @@
         serializedSession = null;
         serializedRulebase = null;
 
-        serializedSession = SerializationHelper.serializeOut( session );
-        serializedRulebase = SerializationHelper.serializeOut( ruleBase );
+        serializedSession = DroolsStreamUtils.streamOut( session );
+        serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
 
         session.dispose();
 
@@ -887,11 +882,7 @@
         assertFalse(builder.hasErrors());
 
         Package p = builder.getPackage();
-        byte[] ser = SerializationHelper.serializeOut(p);
-
-        //now read it back
-        DroolsObjectInputStream in = new DroolsObjectInputStream(new ByteArrayInputStream(ser), loader);
-        Package p_ = (Package) in.readObject();
+        Package p_ = (Package) DroolsStreamUtils.streamIn(DroolsStreamUtils.streamOut(p), loader);
         assertNotNull(p_);
 
     }

Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -76,6 +76,7 @@
 import org.drools.StatelessSession;
 import org.drools.TestParam;
 import org.drools.WorkingMemory;
+import org.drools.util.DroolsStreamUtils;
 import org.drools.Cheesery.Maturity;
 import org.drools.audit.WorkingMemoryFileLogger;
 import org.drools.audit.WorkingMemoryInMemoryLogger;
@@ -175,24 +176,24 @@
         WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         // will test serialisation of int and typesafe enums tests
-        workingMemory   = ruleBase.newStatefulSession( new ByteArrayInputStream( SerializationHelper.serializeOut(  workingMemory  )) );
-        
+        workingMemory   = ruleBase.newStatefulSession( new ByteArrayInputStream( DroolsStreamUtils.streamOut( workingMemory  )) );
+
         List list = new ArrayList();
         workingMemory.setGlobal( "list",
                                  list );
-                       
+
         final Cheesery cheesery1 = new Cheesery();
         cheesery1.setStatus( Cheesery.SELLING_CHEESE );
         cheesery1.setMaturity( Maturity.OLD );
-        workingMemory.insert( cheesery1 );                        
+        workingMemory.insert( cheesery1 );
 
         final Cheesery cheesery2 = new Cheesery();
         cheesery2.setStatus( Cheesery.MAKING_CHEESE );
         cheesery2.setMaturity( Maturity.YOUNG );
-        workingMemory.insert( cheesery2 );        
-        
-        workingMemory.fireAllRules();        
-        
+        workingMemory.insert( cheesery2 );
+
+        workingMemory.fireAllRules();
+
         assertEquals( 2,
                       list.size() );
 
@@ -201,19 +202,19 @@
                       list.get( 0 ) );
         assertSame( cheesery2, list.get( 1 ) );
         assertEquals( cheesery2,
-                      list.get( 1 ) );        
+                      list.get( 1 ) );
 
         // test list after serialising
-        workingMemory   = ruleBase.newStatefulSession( new ByteArrayInputStream( SerializationHelper.serializeOut(  workingMemory  )) );
+        workingMemory   = ruleBase.newStatefulSession( new ByteArrayInputStream( SerializationHelper.streamOut(  workingMemory  )) );
         list = (List) workingMemory.getGlobal( "list" );
 	    workingMemory.fireAllRules();
 
 		assertEquals(2, list.size());
-		
+
 		assertNotSame( cheesery1, list.get( 0 ) );
 		assertEquals(cheesery1, list.get(0));
 		assertNotSame( cheesery2, list.get( 1 ) );
-		assertEquals(cheesery2, list.get(1));        
+		assertEquals(cheesery2, list.get(1));
     }
 
     public void testPrimitiveArray() throws Exception {
@@ -1419,7 +1420,7 @@
         pkg.checkValidity();
         pkg = SerializationHelper.serializeObject(pkg);
     }
-    
+
     /**
      * @see JBRULES-1415 Certain uses of from causes NullPointerException in WorkingMemoryLogger
      */
@@ -1443,23 +1444,23 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage(pkg);
         StatefulSession session = ruleBase.newStatefulSession();
-        
+
         WorkingMemoryInMemoryLogger logger = new WorkingMemoryInMemoryLogger( session );
         List list = new ArrayList();
         session.setGlobal( "list", list );
-        
+
         Cheesery cheesery = new Cheesery();
         cheesery.addCheese(  new Cheese("stilton", 22) );
-        
+
         session.insert( cheesery );
 
         // TODO java.io.EOFException
 //        session = SerializationHelper.serializeObject(session);
-        session.fireAllRules();                 
-        
+        session.fireAllRules();
+
         assertEquals( 1, ((List)session.getGlobal("list")).size());
         assertEquals( "stilton", ((List)session.getGlobal("list")).get(0));
-}    
+}
 
     public void testWithInvalidRule() throws Exception {
         final PackageBuilder builder = new PackageBuilder();

Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/SerializationHelper.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/SerializationHelper.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/SerializationHelper.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -1,29 +1,30 @@
 package org.drools.integrationtests;
 
-import org.drools.common.DroolsObjectOutputStream;
-import org.drools.common.DroolsObjectInputStream;
+import org.drools.util.DroolsStreamUtils;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.ByteArrayInputStream;
 
 /**
  * Marshalling helper class to perform serialize/de-serialize a given object
  */
-public class SerializationHelper {
+public class SerializationHelper extends DroolsStreamUtils {
+
     public static <T> T serializeObject(T obj) throws IOException, ClassNotFoundException {
-        return (T)serializeIn(serializeOut(obj));
+        return serializeObject(obj, null, false);
     }
 
-    public static byte[] serializeOut(Object obj) throws IOException {
-        ByteArrayOutputStream   out = new ByteArrayOutputStream();
-        new DroolsObjectOutputStream(out).writeObject(obj);
-        out.close();
-        return out.toByteArray();
+    public static <T> T serializeObject(T obj, ClassLoader classLoader)
+            throws IOException, ClassNotFoundException {
+        return serializeObject(obj, classLoader, false);
     }
 
-    public static Object serializeIn(byte[] bytes)
+    public static <T> T serializeObject(T obj, boolean compression) throws IOException, ClassNotFoundException {
+        return (T) serializeObject(obj, null, compression);
+    }
+
+    public static <T> T serializeObject(T obj, ClassLoader classLoader, boolean compression)
             throws IOException, ClassNotFoundException {
-        return new DroolsObjectInputStream(new ByteArrayInputStream(bytes)).readObject();
+        return (T) streamIn(streamOut(obj, compression), classLoader, compression);
     }
+
 }

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/agent/FileScanner.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/agent/FileScanner.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/agent/FileScanner.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -4,16 +4,14 @@
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectInput;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
-import org.drools.common.DroolsObjectInputStream;
 import org.drools.rule.Package;
+import org.drools.util.DroolsStreamUtils;
 
 /**
  * This will monitor a file to a binary package.
@@ -104,11 +102,8 @@
     	} else {
 
 	        Package p1_ = null;
-	        ObjectInput in;
 	        try {
-	            in = new DroolsObjectInputStream( new FileInputStream( pkgFile ) );
-	            p1_ = (Package) in.readObject();
-	            in.close();
+	            p1_ = (Package) DroolsStreamUtils.streamIn(new FileInputStream( pkgFile ));
 
 	        } catch ( FileNotFoundException e ) {
 	            this.listener.exception( e );

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/agent/HttpClientImpl.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/agent/HttpClientImpl.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/agent/HttpClientImpl.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -6,8 +6,8 @@
 import java.net.URL;
 import java.net.URLConnection;
 
-import org.drools.common.DroolsObjectInputStream;
 import org.drools.rule.Package;
+import org.drools.util.DroolsStreamUtils;
 
 public class HttpClientImpl implements IHttpClient {
 
@@ -56,8 +56,7 @@
             httpCon.setRequestMethod( "GET" );
             InputStream in = httpCon.getInputStream();
 
-            DroolsObjectInputStream oin = new DroolsObjectInputStream(in);
-                return (Package) oin.readObject();
+            return (Package) DroolsStreamUtils.streamIn(in);
 
         } finally {
             httpCon.disconnect();

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -270,12 +270,10 @@
                 }
                 return collection;
             }
-            case RT_SERIALIZABLE: {
-                int handle = dataInput.readInt();
-                Object  object  =  dataInput.readObject();
-                registerObject(handle, object);
-                return object;
-            }
+            case RT_STRING:
+                return readString(dataInput.readInt());
+            case RT_CLASS:
+                return readClass(dataInput.readInt());
             case RT_EMPTY_SET:
                 return readEmptySet();
             case RT_EMPTY_LIST:
@@ -283,13 +281,9 @@
             case RT_EMPTY_MAP:
                 return readEmptyMap();
             default:
-                int handle = readHandle();
+                int handle = dataInput.readInt();
 
                 switch (type) {
-                    case RT_STRING:
-                        return readString(handle);
-                    case RT_CLASS:
-                        return readClass(handle);
                     case RT_ATOMICREFERENCEARRAY: {
                         int length  = dataInput.readInt();
                         AtomicReferenceArray<Object>    array   = new AtomicReferenceArray<Object>(length);
@@ -299,6 +293,11 @@
                         }
                         return array;
                     }
+                    case RT_SERIALIZABLE: {
+                        Object  object  =  dataInput.readObject();
+                        registerObject(handle, object);
+                        return object;
+                    }
                     default:
                         throw new StreamCorruptedException("Unsupported object type: " + type);
                 }
@@ -373,10 +372,6 @@
         }
     }
 
-    private static Object readNull() {
-        return null;
-    }
-
     private static Set readEmptySet() {
         return Collections.EMPTY_SET;
     }
@@ -418,10 +413,6 @@
         return collection;
     }
 
-    private int readHandle() throws IOException {
-        return dataInput.readInt();
-    }
-
     private Class readClass(int handle) throws IOException, ClassNotFoundException {
         String className = (String) readObject();
         Class clazz = resolveClass(className);

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectOutputStream.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectOutputStream.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectOutputStream.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -32,10 +32,6 @@
         writeStreamHeader();
     }
 
-    private void writeNull() throws IOException {
-        writeRecordType(RT_NULL);
-    }
-
     private void writePrimitiveArray(Object array, Class clazz) throws IOException {
         if (clazz == Integer.TYPE) {
             writeIntArray(array);
@@ -61,23 +57,23 @@
     private void writeIntArray(Object array) throws IOException {
         int[] ints = (int[]) array;
         int length = ints.length;
-        writeInt(length);
+        dataOutput.writeInt(length);
         for (int i = 0; i < length; ++i) {
-            writeInt(ints[i]);
+            dataOutput.writeInt(ints[i]);
         }
     }
 
     private void writeByteArray(Object array) throws IOException {
         byte[] bytes = (byte[]) array;
         int length = bytes.length;
-        writeInt(length);
+        dataOutput.writeInt(length);
         write(bytes, 0, length);
     }
 
     private void writeLongArray(Object array) throws IOException {
         long[] longs = (long[]) array;
         int length = longs.length;
-        writeInt(length);
+        dataOutput.writeInt(length);
         for (int i = 0; i < length; ++i) {
             writeLong(longs[i]);
         }
@@ -95,7 +91,7 @@
     private void writeDoubleArray(Object array) throws IOException {
         double[] doubles = (double[]) array;
         int length = doubles.length;
-        writeInt(length);
+        dataOutput.writeInt(length);
         for (int i = 0; i < length; ++i) {
             writeDouble(doubles[i]);
         }
@@ -104,7 +100,7 @@
     private void writeShortArray(Object array) throws IOException {
         short[] shorts = (short[]) array;
         int length = shorts.length;
-        writeInt(length);
+        dataOutput.writeInt(length);
         for (int i = 0; i < length; ++i) {
             writeShort(shorts[i]);
         }
@@ -113,7 +109,7 @@
     private void writeCharArray(Object array) throws IOException {
         char[] chars = (char[]) array;
         int length = chars.length;
-        writeInt(length);
+        dataOutput.writeInt(length);
         for (int i = 0; i < length; ++i) {
             writeChar(chars[i]);
         }
@@ -122,44 +118,24 @@
     private void writeBooleanArray(Object array) throws IOException {
         boolean[] booleans = (boolean[]) array;
         int length = booleans.length;
-        writeInt(length);
+        dataOutput.writeInt(length);
         for (int i = 0; i < length; ++i) {
             writeBoolean(booleans[i]);
         }
     }
 
     private void writeClass(Class clazz, int handle) throws IOException {
-        writeRecordType(RT_CLASS);
-        writeHandle(handle);
+        dataOutput.writeByte(RT_CLASS);
+        dataOutput.writeInt(handle);
         writeObject(clazz.getName());
     }
 
     private void writeString(String string, int handle) throws IOException {
-        writeRecordType(RT_STRING);
-        writeHandle(handle);
+        dataOutput.writeByte(RT_STRING);
+        dataOutput.writeInt(handle);
         writeUTF(string);
     }
 
-    private void writeEmptySet() throws IOException {
-        writeRecordType(RT_EMPTY_SET);
-    }
-
-    private void writeEmptyList() throws IOException {
-        writeRecordType(RT_EMPTY_LIST);
-    }
-
-    private void writeEmptyMap() throws IOException {
-        writeRecordType(RT_EMPTY_MAP);
-    }
-
-    private void writeRecordType(byte type) throws IOException {
-        writeByte(type);
-    }
-
-    private void writeHandle(int handle) throws IOException {
-        writeInt(handle);
-    }
-
     private void writeStreamHeader() throws IOException {
         writeInt(STREAM_MAGIC);
         writeShort(STREAM_VERSION);
@@ -187,16 +163,16 @@
      */
     public void writeObject(Object object) throws IOException {
         if (object == null) {
-            writeNull();
+            dataOutput.writeByte(RT_NULL);
         } else {
             Class clazz = object.getClass();
 
             if (clazz == EMPTY_SET_CLASS) {
-                writeEmptySet();
+                dataOutput.writeByte(RT_EMPTY_SET);
             } else if (clazz == EMPTY_LIST_CLASS) {
-                writeEmptyList();
+                dataOutput.writeByte(RT_EMPTY_LIST);
             } else if (clazz == EMPTY_MAP_CLASS) {
-                writeEmptyMap();
+                dataOutput.writeByte(RT_EMPTY_MAP);
             } else {
                 if (clazz == String.class)
                     object  = ((String)object).intern();
@@ -204,37 +180,24 @@
                 if (handle < 0) {
                     handle  = -handle;
                     if (Externalizable.class.isAssignableFrom(clazz)) {
-                        writeRecordType(RT_EXTERNALIZABLE);
-                        writeHandle(handle);
+                        dataOutput.writeByte(RT_EXTERNALIZABLE);
+                        dataOutput.writeInt(handle);
                         writeObject(clazz);
                         ((Externalizable)object).writeExternal(this);
-                    } else if (String.class.isAssignableFrom(clazz)) {
-                        writeString((String) object, handle);
                     } else if (Map.class.isAssignableFrom(clazz)) {
                         Map map = (Map)object;
-                        writeRecordType(RT_MAP);
-                        writeHandle(handle);
+                        dataOutput.writeByte(RT_MAP);
+                        dataOutput.writeInt(handle);
                         writeObject(clazz);
-                        writeInt(map.size());
+                        dataOutput.writeInt(map.size());
                         for (Object obj : map.entrySet()) {
                             Map.Entry entry = (Map.Entry) obj;
                             writeObject(entry.getKey());
                             writeObject(entry.getValue());
                         }
-                    } else if (Collection.class.isAssignableFrom(clazz)) {
-                        Collection collection   = (Collection)object;
-                        writeRecordType(RT_COLLECTION);
-                        writeHandle(handle);
-                        writeObject(clazz);
-                        writeInt(collection.size());
-                        for (Object obj : collection) {
-                            writeObject(obj);
-                        }
-                    } else if (clazz == Class.class) {
-                        writeClass((Class) object, handle);
                     } else if (clazz.isArray()) {
-                        writeRecordType(RT_ARRAY);
-                        writeHandle(handle);
+                        dataOutput.writeByte(RT_ARRAY);
+                        dataOutput.writeInt(handle);
                         writeObject(clazz);
                         Class componentType = clazz.getComponentType();
                         if (componentType.isPrimitive()) {
@@ -242,32 +205,45 @@
                         } else {
                             Object[]    array = (Object[])object;
                             int length = array.length;
-                            writeInt(length);
+                            dataOutput.writeInt(length);
                             for (int i = 0; i < length; ++i) {
                                 writeObject(array[i]);
                             }
                         }
+                    } else if (Collection.class.isAssignableFrom(clazz)) {
+                        Collection collection   = (Collection)object;
+                        dataOutput.writeByte(RT_COLLECTION);
+                        dataOutput.writeInt(handle);
+                        writeObject(clazz);
+                        dataOutput.writeInt(collection.size());
+                        for (Object obj : collection) {
+                            writeObject(obj);
+                        }
+                    } else if (String.class.isAssignableFrom(clazz)) {
+                        writeString((String) object, handle);
+                    } else if (clazz == Class.class) {
+                        writeClass((Class) object, handle);
                     } else if (AtomicReferenceArray.class.isAssignableFrom(clazz)) {
                         AtomicReferenceArray array  = (AtomicReferenceArray)object;
-                        writeRecordType(RT_ATOMICREFERENCEARRAY);
-                        writeHandle(handle);
-                        writeInt(array.length());
+                        dataOutput.writeByte(RT_ATOMICREFERENCEARRAY);
+                        dataOutput.writeInt(handle);
+                        dataOutput.writeInt(array.length());
                         for (int i = 0; i < array.length(); i++)
                             writeObject(array.get(i));
                     } else if (Serializable.class.isAssignableFrom(clazz)) {
-                        writeRecordType(RT_SERIALIZABLE);
-                        writeHandle(handle);
+                        dataOutput.writeByte(RT_SERIALIZABLE);
+                        dataOutput.writeInt(handle);
                         dataOutput.writeObject(object);
                     } else {
                         throw new NotSerializableException("Unsupported class: " + clazz);
                     }
                 } else {
-                    writeRecordType(RT_REFERENCE);
-                    writeHandle(handle);
+                    dataOutput.writeByte(RT_REFERENCE);
+                    dataOutput.writeInt(handle);
                 }
             }
         }
-        flush();
+        dataOutput.flush();
     }
 
     /**

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/util/BinaryRuleBaseLoader.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/util/BinaryRuleBaseLoader.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/util/BinaryRuleBaseLoader.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -7,7 +7,6 @@
 import org.drools.RuleBase;
 import org.drools.RuleBaseFactory;
 import org.drools.RuntimeDroolsException;
-import org.drools.common.DroolsObjectInputStream;
 import org.drools.rule.Package;
 
 /**
@@ -78,8 +77,7 @@
         }
 
         try {
-            DroolsObjectInputStream oin = new DroolsObjectInputStream( in, classLoader);
-            Object opkg = oin.readObject();
+            Object opkg = DroolsStreamUtils.streamIn(in, classLoader);
             if ( !(opkg instanceof Package) ) {
                 throw new IllegalArgumentException( "Can only add instances of org.drools.rule.Package to a rulebase instance." );
             }

Added: labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/util/DroolsStreamUtils.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/util/DroolsStreamUtils.java	                        (rev 0)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/util/DroolsStreamUtils.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -0,0 +1,183 @@
+package org.drools.util;
+
+import org.drools.common.DroolsObjectOutputStream;
+import org.drools.common.DroolsObjectInputStream;
+
+import java.io.*;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: sg0521861
+ * Date: Mar 27, 2008
+ * Time: 8:56:14 AM
+ * Provide Drools specific streaming helper routines
+ */
+public class DroolsStreamUtils {
+
+    /**
+     * This routine would stream out the give object uncompressed and store the streamed contents in
+     * the return byte array.  The output contents could only be read by the corresponding "streamIn"
+     * method of this class.
+     * @param object
+     * @return
+     * @throws IOException
+     */
+    public static byte[] streamOut(Object object) throws IOException {
+        return streamOut(object, false);
+    }
+
+    /**
+     * This routine would stream out the give object, uncompressed or compressed depending on the given flag,
+     * and store the streamed contents in the return byte array. The output contents could only be read by
+     * the corresponding "streamIn" method of this class.
+     * @param object
+     * @param compressed
+     * @return
+     * @throws IOException
+     */
+    public static byte[] streamOut(Object object, boolean compressed) throws IOException {
+        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+
+        streamOut(bytes, object, compressed);
+        bytes.flush();
+        bytes.close();
+        return bytes.toByteArray();
+    }
+
+    /**
+     * This method would stream out the given object to the given output stream uncompressed.
+     * The output contents could only be read by the corresponding "streamIn" method of this class.
+     * @param out
+     * @param object
+     * @throws IOException
+     */
+    public static void streamOut(OutputStream out, Object object) throws IOException {
+        streamOut(out, object, false);
+    }
+
+    /**
+     * This method would stream out the given object to the given output stream uncompressed or compressed
+     * depending on the given flag.  The output contents could only be read by the corresponding "streamIn"
+     * methods of this class.
+     * @param out
+     * @param object
+     * @throws IOException
+     */
+    public static void streamOut(OutputStream out, Object object, boolean compressed) throws IOException {
+        if (compressed) {
+            out = new GZIPOutputStream(out);
+        }
+        try {
+            new DroolsObjectOutputStream(out).writeObject(object);
+            out.flush();
+        } finally {
+            if (compressed) {
+                out.close();
+            }
+        }
+    }
+
+    /**
+     * This method reads the contents from the given byte array and returns the object.  It is expected that
+     * the contents in the given buffer was not compressed, and the content stream was written by the corresponding
+     * streamOut methods of this class.
+     * @param bytes
+     * @return
+     * @throws IOException
+     * @throws ClassNotFoundException
+     */
+    public static Object streamIn(byte[] bytes) throws IOException, ClassNotFoundException {
+        return streamIn(bytes, null);
+    }
+
+    /**
+     * This method reads the contents from the given byte array and returns the object.  It is expected that
+     * the contents in the given buffer was not compressed, and the content stream was written by the corresponding
+     * streamOut methods of this class.
+     * @param bytes
+     * @param classLoader
+     * @return
+     * @throws IOException
+     * @throws ClassNotFoundException
+     */
+    public static Object streamIn(byte[] bytes, ClassLoader classLoader)
+            throws IOException, ClassNotFoundException {
+        return streamIn(bytes, classLoader, false);
+    }
+
+    /**
+     * This method reads the contents from the given byte array and returns the object.  The contents in the given
+     * buffer could be compressed or uncompressed depending on the given flag.  It is assumed that the content
+     * stream was written by the corresponding streamOut methods of this class.
+     * @param bytes
+     * @param compressed
+     * @return
+     * @throws IOException
+     * @throws ClassNotFoundException
+     */
+    public static Object streamIn(byte[] bytes, boolean compressed) throws IOException, ClassNotFoundException {
+        return streamIn(new ByteArrayInputStream(bytes), null, compressed);
+    }
+
+    /**
+     * This method reads the contents from the given byte array and returns the object.  The contents in the given
+     * buffer could be compressed or uncompressed depending on the given flag.  It is assumed that the content
+     * stream was written by the corresponding streamOut methods of this class.
+     * @param bytes
+     * @param classLoader
+     * @param compressed
+     * @return
+     * @throws IOException
+     * @throws ClassNotFoundException
+     */
+    public static Object streamIn(byte[] bytes, ClassLoader classLoader, boolean compressed)
+            throws IOException, ClassNotFoundException {
+        return streamIn(new ByteArrayInputStream(bytes), classLoader, compressed);
+    }
+
+    /**
+     * This method reads the contents from the given input stream and returns the object.  It is expected that
+     * the contents in the given stream was not compressed, and it was written by the corresponding
+     * streamOut methods of this class.
+     * @param in
+     * @return
+     * @throws IOException
+     * @throws ClassNotFoundException
+     */
+    public static Object streamIn(InputStream in) throws IOException, ClassNotFoundException {
+        return streamIn(in, null, false);
+    }
+
+    /**
+     * This method reads the contents from the given input stream and returns the object.  It is expected that
+     * the contents in the given stream was not compressed, and it was written by the corresponding
+     * streamOut methods of this class.
+     * @param in
+     * @param classLoader
+     * @return
+     * @throws IOException
+     * @throws ClassNotFoundException
+     */
+    public static Object streamIn(InputStream in, ClassLoader classLoader)
+            throws IOException, ClassNotFoundException {
+        return streamIn(in, classLoader, false);
+    }
+
+    /**
+     * This method reads the contents from the given input stream and returns the object.  The contents in the given
+     * stream could be compressed or uncompressed depending on the given flag.  It is assumed that the content
+     * stream was written by the corresponding streamOut methods of this class.
+     * @param in
+     * @return
+     * @throws IOException
+     * @throws ClassNotFoundException
+     */
+    public static Object streamIn(InputStream in, ClassLoader classLoader, boolean compressed)
+            throws IOException, ClassNotFoundException {
+        if (compressed)
+            in  = new GZIPInputStream(in);
+        return new DroolsObjectInputStream(in, classLoader).readObject();
+     }
+}

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/agent/RuleBaseAssemblerTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/agent/RuleBaseAssemblerTest.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/agent/RuleBaseAssemblerTest.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -1,17 +1,10 @@
 package org.drools.agent;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
+import java.io.*;
 
 import org.drools.RuleBase;
 import org.drools.RuleBaseFactory;
-import org.drools.common.DroolsObjectInputStream;
-import org.drools.common.DroolsObjectOutputStream;
+import org.drools.util.DroolsStreamUtils;
 import org.drools.rule.Package;
 
 import junit.framework.TestCase;
@@ -44,17 +37,14 @@
     public static Package readPackage(File p1file) throws IOException,
                                                           FileNotFoundException,
                                                           ClassNotFoundException {
-        ObjectInput in = new DroolsObjectInputStream(new FileInputStream(p1file));
-        Package p1_ = (Package) in.readObject();
-        in.close();
-        return p1_;
+        return (Package) DroolsStreamUtils.streamIn(new FileInputStream(p1file));
     }
 
-    public static void writePackage(Package pkg, File p1file) throws IOException,
-                                                                     FileNotFoundException {
-        ObjectOutput out = new DroolsObjectOutputStream(new FileOutputStream(p1file));
-        out.writeObject( pkg );
-        out.flush(); out.close();
+    public static void writePackage(Package pkg, File p1file) throws IOException {
+        OutputStream out = new FileOutputStream(p1file);
+        DroolsStreamUtils.streamOut(out, pkg);
+        out.flush();
+        out.close();
     }
 
     public static File getTempDirectory() {

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/agent/URLScannerTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/agent/URLScannerTest.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/agent/URLScannerTest.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -3,6 +3,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 import java.net.URLEncoder;
 import java.util.ArrayList;
@@ -13,7 +14,7 @@
 
 import org.drools.RuleBase;
 import org.drools.RuleBaseFactory;
-import org.drools.common.DroolsObjectInputStream;
+import org.drools.util.DroolsStreamUtils;
 import org.drools.rule.Package;
 
 public class URLScannerTest extends TestCase {
@@ -31,9 +32,7 @@
 
         RuleBaseAssemblerTest.writePackage( p, f );
 
-        DroolsObjectInputStream in = new DroolsObjectInputStream( new FileInputStream( f ) );
-        Package p_ = (Package) in.readObject();
-        in.close();
+        Package p_ = (Package) DroolsStreamUtils.streamIn(new FileInputStream( f ));
         assertEquals( "x", p_.getName() );
 
     }

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/common/DroolsObjectIOTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/common/DroolsObjectIOTest.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/common/DroolsObjectIOTest.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -2,23 +2,11 @@
 
 import junit.framework.TestCase;
 
-import java.io.File;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.ObjectInput;
-import java.io.FileOutputStream;
-import java.io.FileInputStream;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectOutput;
-import java.io.ByteArrayInputStream;
-import java.io.Serializable;
-import java.io.ObjectOutputStream;
-import java.io.ObjectInputStream;
-import java.net.URL;
+import java.io.*;
 
 import org.drools.rule.GroupElement;
 import org.drools.rule.Package;
+import org.drools.util.DroolsStreamUtils;
 
 /**
  * Created by IntelliJ IDEA. User: SG0521861 Date: Mar 3, 2008 Time: 11:19:44 AM To change this template use File |
@@ -40,17 +28,15 @@
         String  str = TEST_FILE;
         file    = new File(file.getParent().replaceAll("%20", " "), str);
 
-        DroolsObjectOutputStream    out = new DroolsObjectOutputStream(new FileOutputStream(file));
+        OutputStream out = new FileOutputStream(file);
 
-        out.writeObject(testGroupElement);
+        DroolsStreamUtils.streamOut(out, testGroupElement);
         out.flush();
         out.close();
 
         InputStream         fis = getClass().getResourceAsStream(TEST_FILE);
         System.out.println(fis.available());
-        ObjectInput   ois = new DroolsObjectInputStream(fis);
-
-        GroupElement    that    = (GroupElement)ois.readObject();
+        GroupElement    that    = (GroupElement) DroolsStreamUtils.streamIn(fis);
         assertEquals(that, testGroupElement);
     }
 
@@ -103,18 +89,11 @@
     }
 
     private static Object deserialize(byte[] buf) throws Exception {
-        return new DroolsObjectInputStream(new ByteArrayInputStream(buf)).readObject();
+        return DroolsStreamUtils.streamIn(buf);
     }
 
     private static byte[] serialize(Object obj) throws IOException {
-        ByteArrayOutputStream   bytes   = new ByteArrayOutputStream();
-        ObjectOutput            out = new DroolsObjectOutputStream(bytes);
-
-        out.writeObject(obj);
-        out.flush();
-        out.close();
-
-        return bytes.toByteArray();
+        return DroolsStreamUtils.streamOut(obj);
     }
 
     private static Object unmarshal(byte[] buf) throws Exception {

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/integrationtests/SerializationHelper.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/integrationtests/SerializationHelper.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/integrationtests/SerializationHelper.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -1,29 +1,30 @@
 package org.drools.integrationtests;
 
-import org.drools.common.DroolsObjectOutputStream;
-import org.drools.common.DroolsObjectInputStream;
+import org.drools.util.DroolsStreamUtils;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.ByteArrayInputStream;
 
 /**
  * Marshalling helper class to perform serialize/de-serialize a given object
  */
-public class SerializationHelper {
+public class SerializationHelper extends DroolsStreamUtils {
+
     public static <T> T serializeObject(T obj) throws IOException, ClassNotFoundException {
-        return (T)serializeIn(serializeOut(obj));
+        return serializeObject(obj, null, false);
     }
 
-    public static byte[] serializeOut(Object obj) throws IOException {
-        ByteArrayOutputStream   out = new ByteArrayOutputStream();
-        new DroolsObjectOutputStream(out).writeObject(obj);
-        out.close();
-        return out.toByteArray();
+    public static <T> T serializeObject(T obj, ClassLoader classLoader)
+            throws IOException, ClassNotFoundException {
+        return serializeObject(obj, classLoader, false);
     }
 
-    public static Object serializeIn(byte[] bytes)
+    public static <T> T serializeObject(T obj, boolean compression) throws IOException, ClassNotFoundException {
+        return (T) serializeObject(obj, null, compression);
+    }
+
+    public static <T> T serializeObject(T obj, ClassLoader classLoader, boolean compression)
             throws IOException, ClassNotFoundException {
-        return new DroolsObjectInputStream(new ByteArrayInputStream(bytes)).readObject();
+        return (T) streamIn(streamOut(obj, compression), classLoader, compression);
     }
+
 }

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/rule/LogicTransformerTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/rule/LogicTransformerTest.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/test/java/org/drools/rule/LogicTransformerTest.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -16,17 +16,10 @@
  * limitations under the License.
  */
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-import java.net.URL;
+import java.io.*;
 
 import org.drools.DroolsTestCase;
-import org.drools.common.DroolsObjectOutputStream;
-import org.drools.common.DroolsObjectInputStream;
+import org.drools.util.DroolsStreamUtils;
 import org.drools.base.ClassObjectType;
 import org.drools.spi.ObjectType;
 
@@ -527,10 +520,10 @@
         // result
         writeTree( result,
                    "correct_processTree1.dat" );
-        final ObjectInput ois = new DroolsObjectInputStream( this.getClass().getResourceAsStream( "correct_processTree1.dat" ));
+        final GroupElement[] correctResultRoot =
+                (GroupElement[]) DroolsStreamUtils.streamIn(
+                        this.getClass().getResourceAsStream( "correct_processTree1.dat" ));
 
-        final GroupElement[] correctResultRoot = (GroupElement[]) ois.readObject();
-
         // Make sure they are equal
         for ( int j = 0; j < correctResultRoot.length; j++ ) {
             assertEquals( correctResultRoot[j],
@@ -709,8 +702,9 @@
 
         // Get known correct tree
         // The binary stream was created from a handchecked correct output
-        final ObjectInput ois = new DroolsObjectInputStream( this.getClass().getResourceAsStream( "correct_transform1.dat" ) );
-        final GroupElement[] correctResultAnds = (GroupElement[]) ois.readObject();
+        final GroupElement[] correctResultAnds =
+                (GroupElement[]) DroolsStreamUtils.streamIn(
+                        this.getClass().getResourceAsStream( "correct_transform1.dat" ) );
 
         for ( int j = 0; j < ands.length; j++ ) {
             assertEquals( correctResultAnds[j],
@@ -726,11 +720,7 @@
 
         file = new File( file.getParent().replaceAll("%20", " "), fileName );
 
-        ObjectOutput    out = new DroolsObjectOutputStream(new FileOutputStream( file ) );
-
-        out.writeObject( object );
-        out.flush();
-        out.close();
+        DroolsStreamUtils.streamOut(new FileOutputStream( file ), object);
     }
 
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/ming-serialization/drools-jbrms/src/main/java/org/drools/brms/server/ServiceImplementation.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-jbrms/src/main/java/org/drools/brms/server/ServiceImplementation.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-jbrms/src/main/java/org/drools/brms/server/ServiceImplementation.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -45,6 +45,7 @@
 import org.drools.RuleBase;
 import org.drools.RuleBaseConfiguration;
 import org.drools.RuleBaseFactory;
+import org.drools.util.DroolsStreamUtils;
 import org.drools.base.ClassTypeResolver;
 import org.drools.brms.client.common.AssetFormats;
 import org.drools.brms.client.modeldriven.SuggestionCompletionEngine;
@@ -78,9 +79,7 @@
 import org.drools.brms.server.util.MetaDataMapper;
 import org.drools.brms.server.util.TableDisplayHandler;
 import org.drools.common.AbstractRuleBase;
-import org.drools.common.DroolsObjectInputStream;
 import org.drools.common.InternalWorkingMemory;
-import org.drools.common.DroolsObjectOutputStream;
 import org.drools.compiler.DrlParser;
 import org.drools.compiler.DroolsParserException;
 import org.drools.compiler.PackageBuilderConfiguration;
@@ -895,14 +894,11 @@
             return result;
         } else {
             try {
-                ByteArrayOutputStream bout = new ByteArrayOutputStream();
-                ObjectOutput out = new DroolsObjectOutputStream(bout);
-                out.writeObject( asm.getBinaryPackage() );
 
-                item.updateCompiledPackage( new ByteArrayInputStream( bout.toByteArray()) );
-                out.flush();
-                out.close();
+                byte[]  bytes = DroolsStreamUtils.streamOut(asm.getBinaryPackage());
 
+                item.updateCompiledPackage( new ByteArrayInputStream( bytes ) );
+
                 updateBinaryPackage(item, asm);
                 repository.save();
             } catch (Exception e) {
@@ -1157,9 +1153,7 @@
 	private RuleBase loadRuleBase(PackageItem item, ClassLoader cl)  throws DetailedSerializableException {
 		try {
 			RuleBase rb = RuleBaseFactory.newRuleBase(new RuleBaseConfiguration(cl));
-			DroolsObjectInputStream in = new DroolsObjectInputStream(new ByteArrayInputStream(item.getCompiledPackageBytes()), cl);
-			Package bin = (Package) in.readObject();
-			in.close();
+			Package bin = (Package) DroolsStreamUtils.streamIn(item.getCompiledPackageBytes(), cl);
 			rb.addPackage(bin);
 			return rb;
 		} catch (ClassNotFoundException e) {

Modified: labs/jbossrules/branches/ming-serialization/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -68,7 +68,6 @@
 import org.drools.brms.server.util.ScenarioXMLPersistence;
 import org.drools.brms.server.util.TableDisplayHandler;
 import org.drools.brms.server.util.TestEnvironmentSessionHelper;
-import org.drools.common.DroolsObjectInputStream;
 import org.drools.repository.AssetItem;
 import org.drools.repository.CategoryItem;
 import org.drools.repository.PackageItem;
@@ -77,6 +76,7 @@
 import org.drools.repository.StateItem;
 import org.drools.rule.Package;
 import org.drools.util.BinaryRuleBaseLoader;
+import org.drools.util.DroolsStreamUtils;
 
 import com.google.gwt.user.client.rpc.IsSerializable;
 import com.google.gwt.user.client.rpc.SerializableException;
@@ -945,9 +945,7 @@
 
 		assertNotNull(binPackage);
 
-		ByteArrayInputStream bin = new ByteArrayInputStream(binPackage);
-		ObjectInput in = new DroolsObjectInputStream(bin);
-		Package binPkg = (Package) in.readObject();
+		Package binPkg = (Package) DroolsStreamUtils.streamIn(binPackage);
 
 		assertNotNull(binPkg);
 		assertTrue(binPkg.isValid());
@@ -1041,9 +1039,7 @@
 
 		assertNotNull(binPackage);
 
-		ByteArrayInputStream bin = new ByteArrayInputStream(binPackage);
-		ObjectInput in = new DroolsObjectInputStream(bin);
-		Package binPkg = (Package) in.readObject();
+		Package binPkg = (Package) DroolsStreamUtils.streamIn( binPackage );
 
 		assertNotNull(binPkg);
 		assertTrue(binPkg.isValid());
@@ -1801,77 +1797,6 @@
 	}
 
 
-	public void testGuidedDTExecute() throws Exception {
-		ServiceImplementation impl = getService();
-		RulesRepository repo = impl.repository;
-		impl.createCategory("/", "decisiontables", "");
-
-		PackageItem pkg = repo.createPackage("testGuidedDTCompile", "");
-		pkg.updateHeader("import org.drools.Person");
-		AssetItem rule1 = pkg.addAsset("rule_1", "");
-		rule1.updateFormat(AssetFormats.DRL);
-		rule1.updateContent("rule 'rule1' \n when \np : Person() \n then \np.setAge(42); \n end");
-		rule1.checkin("");
-		repo.save();
-
-
-		GuidedDecisionTable dt = new GuidedDecisionTable();
-		ConditionCol col = new ConditionCol();
-		col.boundName = "p";
-		col.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
-		col.factField = "hair";
-		col.factType = "Person";
-		col.operator = "==";
-		dt.conditionCols.add(col);
-
-		ActionSetFieldCol ac = new ActionSetFieldCol();
-		ac.boundName = "p";
-		ac.factField = "likes";
-		ac.type = SuggestionCompletionEngine.TYPE_STRING;
-		dt.actionCols.add(ac);
-
-		dt.data = new String[][] {
-			new String[] {"1", "descrip", "pink", "cheese"}
-		};
-
-		String uid = impl.createNewRule("decTable", "", "decisiontables", pkg.getName(), AssetFormats.DECISION_TABLE_GUIDED);
-		RuleAsset ass = impl.loadRuleAsset(uid);
-		ass.content = dt;
-		impl.checkinVersion(ass);
-
-		BuilderResult[] results = impl.buildPackage(pkg.getUUID(), null, true);
-		assertNull(results);
-
-		pkg = repo.loadPackage("testGuidedDTCompile");
-		byte[] binPackage = pkg.getCompiledPackageBytes();
-
-		assertNotNull(binPackage);
-
-		ByteArrayInputStream bin = new ByteArrayInputStream(binPackage);
-		ObjectInput in = new DroolsObjectInputStream(bin);
-		Package binPkg = (Package) in.readObject();
-
-		assertEquals(2, binPkg.getRules().length);
-
-		assertNotNull(binPkg);
-		assertTrue(binPkg.isValid());
-
-		Person p = new Person();
-
-
-		p.setHair("pink");
-
-		BinaryRuleBaseLoader loader = new BinaryRuleBaseLoader();
-		loader.addPackage(new ByteArrayInputStream(binPackage));
-		RuleBase rb = loader.getRuleBase();
-
-		StatelessSession sess = rb.newStatelessSession();
-		sess.execute(p);
-		assertEquals(42, p.getAge());
-		assertEquals("cheese", p.getLikes());
-	}
-
-
 	private ServiceImplementation getService() throws Exception {
 		ServiceImplementation impl = new ServiceImplementation();
 

Modified: labs/jbossrules/branches/ming-serialization/drools-jbrms/src/test/java/org/drools/brms/server/contenthandler/ContentHandlerTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-jbrms/src/test/java/org/drools/brms/server/contenthandler/ContentHandlerTest.java	2008-04-02 15:52:15 UTC (rev 19379)
+++ labs/jbossrules/branches/ming-serialization/drools-jbrms/src/test/java/org/drools/brms/server/contenthandler/ContentHandlerTest.java	2008-04-02 18:36:22 UTC (rev 19380)
@@ -35,9 +35,7 @@
         assertTrue(ContentHandler.getHandler( AssetFormats.BUSINESS_RULE ) instanceof BRLContentHandler);
         assertTrue(ContentHandler.getHandler( AssetFormats.DECISION_SPREADSHEET_XLS ) instanceof DecisionTableXLSHandler);
         assertTrue(ContentHandler.getHandler( AssetFormats.ENUMERATION ) instanceof EnumerationContentHandler);
-        assertTrue(ContentHandler.getHandler( AssetFormats.DECISION_TABLE_GUIDED ) instanceof GuidedDTContentHandler);
 
-
         try {
             ContentHandler.getHandler( "XXX" );
             fail("should have thrown an exception");
@@ -51,7 +49,6 @@
         assertTrue(ContentHandler.getHandler( AssetFormats.DSL_TEMPLATE_RULE ).isRuleAsset());
         assertTrue(ContentHandler.getHandler( AssetFormats.BUSINESS_RULE ).isRuleAsset());
         assertTrue(ContentHandler.getHandler( AssetFormats.DECISION_SPREADSHEET_XLS ).isRuleAsset());
-        assertTrue(ContentHandler.getHandler( AssetFormats.DECISION_TABLE_GUIDED ).isRuleAsset());
 
         assertFalse(ContentHandler.getHandler( AssetFormats.DSL ).isRuleAsset());
         assertFalse(ContentHandler.getHandler( AssetFormats.MODEL ).isRuleAsset());




More information about the jboss-svn-commits mailing list