[seam-commits] Seam SVN: r12771 - in modules/drools/trunk/impl/src: main/java/org/jboss/seam/drools/config and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Fri May 21 15:38:14 EDT 2010


Author: tsurdilovic
Date: 2010-05-21 15:38:14 -0400 (Fri, 21 May 2010)
New Revision: 12771

Modified:
   modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/KnowledgeSessionProducer.java
   modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/StatefulKnowledgeSessionWrapper.java
   modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/config/RuleResources.java
   modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/cep/CEPTest-beans.xml
Log:
added stateful knowledge session wrapper

Modified: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/KnowledgeSessionProducer.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/KnowledgeSessionProducer.java	2010-05-21 02:44:30 UTC (rev 12770)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/KnowledgeSessionProducer.java	2010-05-21 19:38:14 UTC (rev 12771)
@@ -79,7 +79,7 @@
       addEventListeners(ksession);
       addWorkItemHandlers(ksession);
       addFactProviders(ksession);
-
+      
       return ksession;
    }
 

Modified: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/StatefulKnowledgeSessionWrapper.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/StatefulKnowledgeSessionWrapper.java	2010-05-21 02:44:30 UTC (rev 12770)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/StatefulKnowledgeSessionWrapper.java	2010-05-21 19:38:14 UTC (rev 12771)
@@ -21,6 +21,8 @@
  */
 package org.jboss.seam.drools;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
@@ -33,6 +35,10 @@
 import org.drools.event.process.ProcessEventListener;
 import org.drools.event.rule.AgendaEventListener;
 import org.drools.event.rule.WorkingMemoryEventListener;
+import org.drools.marshalling.Marshaller;
+import org.drools.marshalling.MarshallerFactory;
+import org.drools.marshalling.ObjectMarshallingStrategy;
+import org.drools.marshalling.ObjectMarshallingStrategyAcceptor;
 import org.drools.runtime.Environment;
 import org.drools.runtime.ExecutionResults;
 import org.drools.runtime.ExitPoint;
@@ -52,7 +58,7 @@
  * 
  * @author Tihomir Surdilovic
  */
-public class StatefulKnowledgeSessionWrapper implements StatefulKnowledgeSession,  Externalizable
+public class StatefulKnowledgeSessionWrapper implements StatefulKnowledgeSession, Externalizable
 {
    private StatefulKnowledgeSession ksession;
 
@@ -88,14 +94,27 @@
 
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
    {
-      // TODO Auto-generated method stub
+      byte[] bytes = new byte[in.available()];
+      in.read(bytes);
+      ByteArrayInputStream bais = new ByteArrayInputStream( bytes );
 
+      KnowledgeBase kbase = (KnowledgeBase) in.readObject();
+      Marshaller marshaller = createSerializableMarshaller( kbase );
+      ksession = marshaller.unmarshall(bais);
+      bais.close();
    }
 
    public void writeExternal(ObjectOutput out) throws IOException
    {
-      // TODO Auto-generated method stub
-
+      Marshaller marshaller = createSerializableMarshaller( ksession.getKnowledgeBase() );
+      
+      ByteArrayOutputStream bos = new ByteArrayOutputStream();
+      marshaller.marshall( bos, ksession );
+      final byte[] b = bos.toByteArray();
+      bos.close();
+      
+      out.write(b);
+      out.writeObject(ksession.getKnowledgeBase());
    }
 
    public FactHandle getFactHandle(Object object)
@@ -226,7 +245,7 @@
    public <T extends SessionClock> T getSessionClock()
    {
       // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954
-      return ksession.<T>getSessionClock();
+      return ksession.<T> getSessionClock();
    }
 
    public void registerExitPoint(String name, ExitPoint exitPoint)
@@ -325,4 +344,12 @@
       ksession.halt();
    }
 
+   private Marshaller createSerializableMarshaller(KnowledgeBase knowledgeBase)
+   {
+      ObjectMarshallingStrategyAcceptor acceptor = MarshallerFactory.newClassFilterAcceptor(new String[] { "*.*" });
+      ObjectMarshallingStrategy strategy = MarshallerFactory.newSerializeMarshallingStrategy(acceptor);
+      Marshaller marshaller = MarshallerFactory.newMarshaller(knowledgeBase, new ObjectMarshallingStrategy[] { strategy });
+      return marshaller;
+   }
+
 }

Modified: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/config/RuleResources.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/config/RuleResources.java	2010-05-21 02:44:30 UTC (rev 12770)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/config/RuleResources.java	2010-05-21 19:38:14 UTC (rev 12771)
@@ -23,8 +23,6 @@
 
 import java.util.regex.Pattern;
 
-import org.drools.io.Resource;
-
 /**
  * 
  * @author Tihomir Surdilovic

Modified: modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/cep/CEPTest-beans.xml
===================================================================
--- modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/cep/CEPTest-beans.xml	2010-05-21 02:44:30 UTC (rev 12770)
+++ modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/cep/CEPTest-beans.xml	2010-05-21 19:38:14 UTC (rev 12771)
@@ -30,5 +30,4 @@
    			<s:value>classpath;ceptest.drl;DRL</s:value>
    		</d:resources>
 	</d:CEPPseudoClockRuleResources>
-	
 </beans>       



More information about the seam-commits mailing list