[jboss-svn-commits] JBL Code SVN: r16421 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: reteoo and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 7 21:43:36 EST 2007
Author: mark.proctor at jboss.com
Date: 2007-11-07 21:43:35 -0500 (Wed, 07 Nov 2007)
New Revision: 16421
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
Log:
JBRULES-1318 Rebuild the Rete network on serialisation
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2007-11-08 02:22:39 UTC (rev 16420)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2007-11-08 02:43:35 UTC (rev 16421)
@@ -78,7 +78,7 @@
protected RuleBaseConfiguration config;
- protected Map pkgs;
+ protected Map<String, Package> pkgs;
protected Map processes;
@@ -167,8 +167,7 @@
* The Package uses PackageCompilationData to hold a reference to the generated bytecode. The generated bytecode must be restored before any Rules.
*
*/
- public void doWriteExternal(final ObjectOutput stream,
- final Object[] objects) throws IOException {
+ public void doWriteExternal(final ObjectOutput stream) throws IOException {
stream.writeObject( this.pkgs );
// Rules must be restored by an ObjectInputStream that can resolve using a given ClassLoader to handle seaprately by storing as
@@ -183,12 +182,8 @@
out.writeObject( this.config );
this.eventSupport.removeEventListener( RuleBaseEventListener.class );
- out.writeObject( this.eventSupport );
+ out.writeObject( this.eventSupport );
- for ( int i = 0, length = objects.length; i < length; i++ ) {
- out.writeObject( objects[i] );
- }
-
stream.writeObject( bos.toByteArray() );
}
@@ -198,8 +193,7 @@
* A custom ObjectInputStream, able to resolve classes against the bytecode in the PackageCompilationData, is used to restore the Rules.
*
*/
- public void doReadExternal(final ObjectInput stream,
- final Object[] objects) throws IOException,
+ public void doReadExternal(final ObjectInput stream) throws IOException,
ClassNotFoundException {
// PackageCompilationData must be restored before Rules as it has the ClassLoader needed to resolve the generated code references in Rules
this.pkgs = (Map) stream.readObject();
@@ -240,10 +234,6 @@
this.eventSupport.setRuleBase( this );
this.statefulSessions = new ObjectHashSet();
-
- for ( int i = 0, length = objects.length; i < length; i++ ) {
- objects[i] = childStream.readObject();
- }
}
/**
@@ -715,7 +705,7 @@
((InternalWorkingMemory) session).setRuleBase( this );
((InternalWorkingMemory) session).setId( ( nextWorkingMemoryCounter() ) );
- ExecutorService executor = ExecutorServiceFactory.createExecutorService( this.config.getExecutorService() );;
+ ExecutorService executor = ExecutorServiceFactory.createExecutorService( this.config.getExecutorService() );
executor.setCommandExecutor( new CommandExecutor( session ) );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java 2007-11-08 02:22:39 UTC (rev 16420)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java 2007-11-08 02:43:35 UTC (rev 16421)
@@ -38,6 +38,7 @@
import org.drools.reteoo.ReteooWorkingMemory.WorkingMemoryReteAssertAction;
import org.drools.rule.InvalidPatternException;
import org.drools.rule.Rule;
+import org.drools.rule.Package;
import org.drools.spi.ExecutorServiceFactory;
import org.drools.spi.FactHandleFactory;
import org.drools.spi.PropagationContext;
@@ -58,7 +59,7 @@
private static final long serialVersionUID = 400L;
/** The root Rete-OO for this <code>RuleBase</code>. */
- private Rete rete;
+ private transient Rete rete;
private ReteooBuilder reteooBuilder;
@@ -134,9 +135,7 @@
*
*/
public void writeExternal(final ObjectOutput stream) throws IOException {
- final Object[] objects = new Object[]{this.rete, this.reteooBuilder};
- doWriteExternal( stream,
- objects );
+ doWriteExternal( stream );
}
/**
@@ -147,12 +146,18 @@
*/
public void readExternal(final ObjectInput stream) throws IOException,
ClassNotFoundException {
- final Object[] objects = new Object[2];
- doReadExternal( stream,
- objects );
-
- this.rete = (Rete) objects[0];
- this.reteooBuilder = (ReteooBuilder) objects[1];
+ doReadExternal( stream );
+
+ // rebuild the Rete network from the pkg information
+ this.reteooBuilder = new ReteooBuilder( this );
+ this.rete = new Rete( this );
+ synchronized ( this.pkgs ) {
+ for (Package pkg : this.pkgs.values() ) {
+ for ( Rule rule : pkg.getRules() ) {
+ addRule( rule );
+ }
+ }
+ }
}
// ------------------------------------------------------------
More information about the jboss-svn-commits
mailing list