[jboss-svn-commits] JBL Code SVN: r20000 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: marshalling and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat May 17 23:33:38 EDT 2008
Author: mark.proctor at jboss.com
Date: 2008-05-17 23:33:38 -0400 (Sat, 17 May 2008)
New Revision: 20000
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/DefaultMarshaller.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/InputMarshaller.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/MarshallerReaderContext.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/MarshallerWriteContext.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java
Removed:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/InputPersister.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/Marshaller.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputPersister.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/WMSerialisationInContext.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/WMSerialisationOutContext.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/WorkingMemoryAction.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/PersisterHelper.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooTemporalSession.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java
Log:
JBRULES-1598 Efficient WorkingMemory serialization with binary protocol
-Some refactoring tidyups on various class names
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -24,8 +24,8 @@
import java.util.concurrent.atomic.AtomicLong;
import org.drools.WorkingMemory;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.reteoo.ObjectTypeConf;
import org.drools.spi.FactHandleFactory;
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 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -43,12 +43,12 @@
import org.drools.event.RuleBaseEventListener;
import org.drools.event.RuleBaseEventSupport;
import org.drools.marshalling.Marshaller;
-import org.drools.marshalling.OutputPersister;
+import org.drools.marshalling.OutputMarshaller;
import org.drools.marshalling.PlaceholderResolverStrategyFactory;
import org.drools.marshalling.RuleBaseNodes;
import org.drools.marshalling.SerializablePlaceholderResolverStrategy;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.objenesis.Objenesis;
import org.drools.process.core.Process;
import org.drools.reteoo.ReteooStatefulSession;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -62,12 +62,12 @@
import org.drools.event.RuleFlowEventSupport;
import org.drools.event.WorkingMemoryEventListener;
import org.drools.event.WorkingMemoryEventSupport;
-import org.drools.marshalling.InputPersister;
-import org.drools.marshalling.OutputPersister;
+import org.drools.marshalling.InputMarshaller;
+import org.drools.marshalling.OutputMarshaller;
import org.drools.marshalling.PersisterEnums;
import org.drools.marshalling.PersisterHelper;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.process.core.Process;
import org.drools.process.core.context.variable.Variable;
import org.drools.process.core.context.variable.VariableScope;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -17,8 +17,8 @@
*/
import org.drools.conflict.DepthConflictResolver;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.spi.Activation;
import org.drools.spi.AgendaGroup;
import org.drools.spi.ConflictResolver;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -37,8 +37,8 @@
import org.drools.base.SequentialKnowledgeHelper;
import org.drools.common.RuleFlowGroupImpl.DeactivateCallback;
import org.drools.marshalling.PersisterEnums;
-import org.drools.marshalling.WMSerialisationOutContext;
-import org.drools.marshalling.OutputPersister.HandleSorter;
+import org.drools.marshalling.MarshallerWriteContext;
+import org.drools.marshalling.OutputMarshaller.HandleSorter;
import org.drools.spi.Activation;
import org.drools.spi.ActivationGroup;
import org.drools.spi.AgendaFilter;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -25,7 +25,7 @@
import org.drools.RuleBaseConfiguration;
import org.drools.StatefulSession;
import org.drools.audit.WorkingMemoryInMemoryLogger;
-import org.drools.marshalling.WMSerialisationInContext;
+import org.drools.marshalling.MarshallerReaderContext;
import org.drools.objenesis.Objenesis;
import org.drools.process.core.Process;
import org.drools.reteoo.Rete;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupImpl.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupImpl.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -23,8 +23,8 @@
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.drools.marshalling.PersisterEnums;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.spi.Activation;
import org.drools.util.Iterator;
import org.drools.util.LinkedList;
@@ -264,11 +264,11 @@
this.ruleFlowGroup = ruleFlowGroup;
}
- public DeactivateCallback(WMSerialisationInContext context) throws IOException {
+ public DeactivateCallback(MarshallerReaderContext context) throws IOException {
}
- public void write(WMSerialisationOutContext context) throws IOException {
+ public void write(MarshallerWriteContext context) throws IOException {
}
public void readExternal(ObjectInput in) throws IOException,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -31,8 +31,8 @@
import org.drools.FactException;
import org.drools.marshalling.PersisterEnums;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.rule.Rule;
import org.drools.spi.Activation;
import org.drools.spi.AgendaGroup;
@@ -229,7 +229,7 @@
this.context = context;
}
- public LogicalRetractCallback(WMSerialisationInContext context) throws IOException {
+ public LogicalRetractCallback(MarshallerReaderContext context) throws IOException {
this.tms = context.wm.getTruthMaintenanceSystem();
this.handle = context.handles.get( context.readInt() );
@@ -247,7 +247,7 @@
}
}
- public void write(WMSerialisationOutContext context) throws IOException {
+ public void write(MarshallerWriteContext context) throws IOException {
context.writeInt( WorkingMemoryAction.LogicalRetractCallback );
context.writeInt( this.handle.getId() );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/WorkingMemoryAction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/WorkingMemoryAction.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/WorkingMemoryAction.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -6,7 +6,7 @@
import java.io.Externalizable;
import java.io.IOException;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerWriteContext;
public interface WorkingMemoryAction extends Externalizable {
public static final int WorkingMemoryReteAssertAction = 1;
@@ -17,5 +17,5 @@
public void execute(InternalWorkingMemory workingMemory);
- public void write(WMSerialisationOutContext context) throws IOException;
+ public void write(MarshallerWriteContext context) throws IOException;
}
\ No newline at end of file
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/DefaultMarshaller.java (from rev 19998, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/Marshaller.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/DefaultMarshaller.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/DefaultMarshaller.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -0,0 +1,78 @@
+package org.drools.marshalling;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.drools.RuleBaseConfiguration;
+import org.drools.StatefulSession;
+import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.concurrent.ExecutorService;
+import org.drools.reteoo.ReteooStatefulSession;
+import org.drools.spi.GlobalResolver;
+
+public class DefaultMarshaller implements Marshaller {
+ GlobalResolver globalResolver;
+ private RuleBaseConfiguration config;
+ PlaceholderResolverStrategyFactory factory;
+
+ public DefaultMarshaller() {
+ this( null );
+ }
+
+ public DefaultMarshaller(RuleBaseConfiguration config) {
+ this( config, null);
+ }
+
+ public DefaultMarshaller(RuleBaseConfiguration config,
+ PlaceholderResolverStrategyFactory factory) {
+ this.config = (config != null) ? config : new RuleBaseConfiguration();
+
+ if ( factory == null ) {
+ this.factory = new PlaceholderResolverStrategyFactory();
+ ClassPlaceholderResolverStrategyAcceptor acceptor = new ClassPlaceholderResolverStrategyAcceptor( "*.*" );
+ IdentityPlaceholderResolverStrategy strategy = new IdentityPlaceholderResolverStrategy( acceptor );
+ this.factory.addStrategy( strategy );
+ } else {
+ this.factory = factory;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.marshalling.Marshaller#read(java.io.InputStream, org.drools.common.InternalRuleBase, int, org.drools.concurrent.ExecutorService)
+ */
+ public ReteooStatefulSession read(final InputStream stream,
+ final InternalRuleBase ruleBase,
+ final int id,
+ final ExecutorService executor) throws IOException,
+ ClassNotFoundException {
+ MarshallerReaderContext context = new MarshallerReaderContext( stream,
+ ruleBase,
+ RuleBaseNodes.getNodeMap( ruleBase ),
+ factory );
+
+ ReteooStatefulSession session = InputMarshaller.readSession( context,
+ id,
+ executor );
+ context.close();
+ return session;
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.marshalling.Marshaller#write(java.io.OutputStream, org.drools.common.InternalRuleBase, org.drools.StatefulSession)
+ */
+ public void write(final OutputStream stream,
+ final InternalRuleBase ruleBase,
+ final StatefulSession session) throws IOException {
+ MarshallerWriteContext context = new MarshallerWriteContext( stream,
+ ruleBase,
+ (InternalWorkingMemory) session,
+ RuleBaseNodes.getNodeMap( ruleBase ),
+ this.factory );
+ OutputMarshaller.writeSession( context );
+ context.close();
+ }
+
+}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/InputMarshaller.java (from rev 19998, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/InputPersister.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/InputMarshaller.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/InputMarshaller.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -0,0 +1,513 @@
+package org.drools.marshalling;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Queue;
+
+import org.drools.base.ClassObjectType;
+import org.drools.common.AgendaItem;
+import org.drools.common.BaseNode;
+import org.drools.common.BinaryHeapQueueAgendaGroup;
+import org.drools.common.DefaultAgenda;
+import org.drools.common.DefaultFactHandle;
+import org.drools.common.EqualityKey;
+import org.drools.common.InternalAgendaGroup;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalRuleFlowGroup;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.common.PropagationContextImpl;
+import org.drools.common.RuleFlowGroupImpl;
+import org.drools.common.TruthMaintenanceSystem;
+import org.drools.concurrent.ExecutorService;
+import org.drools.reteoo.BetaMemory;
+import org.drools.reteoo.BetaNode;
+import org.drools.reteoo.EntryPointNode;
+import org.drools.reteoo.EvalConditionNode;
+import org.drools.reteoo.ExistsNode;
+import org.drools.reteoo.InitialFactHandle;
+import org.drools.reteoo.InitialFactHandleDummyObject;
+import org.drools.reteoo.JoinNode;
+import org.drools.reteoo.LeftInputAdapterNode;
+import org.drools.reteoo.LeftTuple;
+import org.drools.reteoo.LeftTupleSink;
+import org.drools.reteoo.LeftTupleSource;
+import org.drools.reteoo.NotNode;
+import org.drools.reteoo.ObjectSink;
+import org.drools.reteoo.ObjectTypeNode;
+import org.drools.reteoo.ReteooFactHandleFactory;
+import org.drools.reteoo.ReteooStatefulSession;
+import org.drools.reteoo.ReteooWorkingMemory;
+import org.drools.reteoo.RightTuple;
+import org.drools.reteoo.RightTupleSink;
+import org.drools.reteoo.RuleTerminalNode;
+import org.drools.reteoo.EvalConditionNode.EvalMemory;
+import org.drools.reteoo.RuleTerminalNode.TerminalNodeMemory;
+import org.drools.rule.EntryPoint;
+import org.drools.rule.GroupElement;
+import org.drools.rule.Package;
+import org.drools.rule.Rule;
+import org.drools.spi.Activation;
+import org.drools.spi.AgendaGroup;
+import org.drools.spi.FactHandleFactory;
+import org.drools.spi.ObjectType;
+import org.drools.spi.PropagationContext;
+import org.drools.spi.RuleFlowGroup;
+import org.drools.util.BinaryHeapQueue;
+import org.drools.util.Iterator;
+import org.drools.util.ObjectHashMap;
+import org.drools.util.ObjectHashSet;
+import org.drools.util.ObjectHashSet.ObjectEntry;
+
+public class InputMarshaller {
+ public static ReteooStatefulSession readSession(MarshallerReaderContext context,
+ int id,
+ ExecutorService executor) throws IOException,
+ ClassNotFoundException {
+ FactHandleFactory handleFactory = context.ruleBase.newFactHandleFactory( context.readInt(),
+ context.readLong() );
+
+ InitialFactHandle initialFactHandle = new InitialFactHandle( new DefaultFactHandle( context.readInt(), //id
+ new InitialFactHandleDummyObject(),
+ context.readLong() ) ); //recency
+ context.handles.put( initialFactHandle.getId(),
+ initialFactHandle );
+
+ long propagationCounter = context.readLong();
+
+ DefaultAgenda agenda = new DefaultAgenda( context.ruleBase, false );
+ readAgenda( context, agenda );
+ ReteooStatefulSession session = new ReteooStatefulSession( id,
+ context.ruleBase,
+ executor,
+ handleFactory,
+ initialFactHandle,
+ propagationCounter,
+ agenda );
+
+ // RuleFlowGroups need to reference the session
+ for ( RuleFlowGroup group : agenda.getRuleFlowGroupsMap().values() ) {
+ ((RuleFlowGroupImpl) group).setWorkingMemory( session );
+ }
+ context.wm = session;
+
+ readFactHandles( context );
+
+ readActionQueue( context );
+
+ if ( context.readBoolean() ) {
+ readTruthMaintenanceSystem( context );
+ }
+
+ return session;
+ }
+
+ public static void readAgenda(MarshallerReaderContext context, DefaultAgenda agenda) throws IOException {
+ ObjectInputStream stream = context.stream;
+ while ( stream.readInt() == PersisterEnums.AGENDA_GROUP ) {
+ BinaryHeapQueueAgendaGroup group = new BinaryHeapQueueAgendaGroup( stream.readUTF(), context.ruleBase );
+ group.setActive( stream.readBoolean() );
+ agenda.getAgendaGroupsMap().put( group.getName(), group );
+ }
+
+ while ( stream.readInt() == PersisterEnums.AGENDA_GROUP ) {
+ String agendaGroupName = stream.readUTF();
+ agenda.getStackList().add( agenda.getAgendaGroup( agendaGroupName ) );
+ }
+
+ while ( stream.readInt() == PersisterEnums.RULE_FLOW_GROUP ) {
+ String rfgName = stream.readUTF();
+ boolean active = stream.readBoolean();
+ boolean autoDeactivate = stream.readBoolean();
+ RuleFlowGroup rfg = new RuleFlowGroupImpl( rfgName, active, autoDeactivate );
+ agenda.getRuleFlowGroupsMap().put( rfgName, rfg );
+ }
+
+ }
+
+ public static void readActionQueue(MarshallerReaderContext context) throws IOException {
+ ReteooWorkingMemory wm = (ReteooWorkingMemory) context.wm;
+ Queue actionQueue = wm.getActionQueue();
+ while ( context.readInt() == PersisterEnums.WORKING_MEMORY_ACTION ) {
+ actionQueue.offer( PersisterHelper.readWorkingMemoryAction( context ) );
+ }
+ }
+
+ public static void readTruthMaintenanceSystem(MarshallerReaderContext context) throws IOException {
+ ObjectInputStream stream = context.stream;
+
+ TruthMaintenanceSystem tms = context.wm.getTruthMaintenanceSystem();
+ while ( stream.readInt() == PersisterEnums.EQUALITY_KEY ) {
+ int status = stream.readInt();
+ int factHandleId = stream.readInt();
+ InternalFactHandle handle = (InternalFactHandle) context.handles.get( factHandleId );
+ EqualityKey key = new EqualityKey( handle,
+ status );
+ handle.setEqualityKey( key );
+ while ( stream.readInt() == PersisterEnums.FACT_HANDLE ) {
+ factHandleId = stream.readInt();
+ handle = (InternalFactHandle) context.handles.get( factHandleId );
+ key.addFactHandle( handle );
+ handle.setEqualityKey( key );
+ }
+ tms.put( key );
+ }
+ }
+
+ public static void readFactHandles(MarshallerReaderContext context) throws IOException,
+ ClassNotFoundException {
+ ObjectInputStream stream = context.stream;
+ InternalRuleBase ruleBase = context.ruleBase;
+ PlaceholderResolverStrategyFactory resolverStrategyFactory = context.resolverStrategyFactory;
+ InternalWorkingMemory wm = context.wm;
+
+ if ( stream.readBoolean() ) {
+ InternalFactHandle initialFactHandle = wm.getInitialFactHandle();
+ int sinkId = stream.readInt();
+ ObjectTypeNode initialFactNode = (ObjectTypeNode) context.sinks.get( sinkId );
+ ObjectHashSet initialFactMemory = (ObjectHashSet) context.wm.getNodeMemory( initialFactNode );
+
+ initialFactMemory.add( initialFactHandle );
+ readRightTuples( initialFactHandle,
+ context );
+ }
+
+ int size = stream.readInt();
+
+ // load the handles
+ InternalFactHandle[] handles = new InternalFactHandle[size];
+ for ( int i = 0; i < size; i++ ) {
+ int id = stream.readInt();
+ long recency = stream.readLong();
+
+ int strategyIndex = stream.readInt();
+ PlaceholderResolverStrategy strategy = resolverStrategyFactory.getStrategy( strategyIndex );
+ ObjectPlaceholder placeHolder = strategy.read( stream );
+
+ Object object = placeHolder.resolveObject();
+
+ InternalFactHandle handle = new DefaultFactHandle( id,
+ object,
+ recency );
+ context.handles.put( id,
+ handle );
+ handles[i] = handle;
+
+ context.wm.getObjectStore().addHandle( handle,
+ object );
+
+ readRightTuples( handle,
+ context );
+ }
+
+ EntryPointNode node = ruleBase.getRete().getEntryPointNode( EntryPoint.DEFAULT );
+ Map<ObjectType, ObjectTypeNode> objectTypeNodes = node.getObjectTypeNodes();
+
+ // add handles to object type nodes
+ for ( InternalFactHandle handle : handles ) {
+ Object object = handle.getObject();
+ ClassObjectType objectType = new ClassObjectType( object.getClass() );
+ ObjectTypeNode objectTypeNode = objectTypeNodes.get( objectType );
+ ObjectHashSet set = (ObjectHashSet) context.wm.getNodeMemory( objectTypeNode );
+ set.add( handle,
+ false );
+ }
+
+ InternalFactHandle handle = wm.getInitialFactHandle();
+ while ( stream.readInt() == PersisterEnums.LEFT_TUPLE ) {
+ LeftTupleSink sink = (LeftTupleSink) context.sinks.get( stream.readInt() );
+ LeftTuple leftTuple = new LeftTuple( handle,
+ sink,
+ true );
+ readLeftTuple( leftTuple,
+ context );
+ }
+
+ readLeftTuples( context );
+
+ readPropagationContexts( context );
+
+ readActivations( context );
+ }
+
+ public static void readRightTuples(InternalFactHandle factHandle,
+ MarshallerReaderContext context) throws IOException {
+ ObjectInputStream stream = context.stream;
+ while ( stream.readInt() == PersisterEnums.RIGHT_TUPLE ) {
+ readRightTuple( context,
+ factHandle );
+ }
+ }
+
+ public static void readRightTuple(MarshallerReaderContext context,
+ InternalFactHandle factHandle) throws IOException {
+ ObjectInputStream stream = context.stream;
+
+ RightTupleSink sink = (RightTupleSink) context.sinks.get( stream.readInt() );
+
+ BetaMemory memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
+
+ RightTuple rightTuple = new RightTuple( factHandle,
+ sink );
+ context.rightTuples.put( new RightTupleKey( factHandle.getId(),
+ sink ),
+ rightTuple );
+
+ memory.getRightTupleMemory().add( rightTuple );
+ }
+
+ public static void readLeftTuples(MarshallerReaderContext 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();
+ LeftTuple leftTuple = new LeftTuple( context.handles.get( factHandleId ),
+ sink,
+ true );
+ readLeftTuple( leftTuple,
+ context );
+ }
+ }
+
+ public static void readLeftTuple(LeftTuple parentLeftTuple,
+ MarshallerReaderContext context) throws IOException {
+ ObjectInputStream stream = context.stream;
+ InternalRuleBase ruleBase = context.ruleBase;
+ InternalWorkingMemory wm = context.wm;
+ Map<Integer, BaseNode> sinks = context.sinks;
+
+ LeftTupleSink sink = parentLeftTuple.getLeftTupleSink();
+
+ if ( sink instanceof JoinNode ) {
+ BetaMemory memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
+ memory.getLeftTupleMemory().add( parentLeftTuple );
+
+ while ( stream.readInt() == PersisterEnums.RIGHT_TUPLE ) {
+ LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
+ int factHandleId = stream.readInt();
+ RightTupleKey key = new RightTupleKey( factHandleId,
+ sink );
+ RightTuple rightTuple = context.rightTuples.get( key );
+ LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,
+ rightTuple,
+ childSink,
+ true );
+ readLeftTuple( childLeftTuple,
+ context );
+ }
+
+ } else if ( sink instanceof EvalConditionNode ) {
+ final EvalMemory memory = (EvalMemory) context.wm.getNodeMemory( (EvalConditionNode) sink );
+ memory.tupleMemory.add( parentLeftTuple );
+ while ( stream.readInt() == PersisterEnums.LEFT_TUPLE ) {
+ LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
+ LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,
+ childSink,
+ true );
+ readLeftTuple( childLeftTuple,
+ context );
+ }
+ } else if ( sink instanceof NotNode ) {
+ BetaMemory memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
+ int type = stream.readInt();
+ if ( type == PersisterEnums.LEFT_TUPLE_NOT_BLOCKED ) {
+ memory.getLeftTupleMemory().add( parentLeftTuple );
+
+ while ( stream.readInt() == PersisterEnums.LEFT_TUPLE ) {
+ LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
+ LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,
+ childSink,
+ true );
+ readLeftTuple( childLeftTuple,
+ context );
+ }
+
+ } else {
+ int factHandleId = stream.readInt();
+ RightTupleKey key = new RightTupleKey( factHandleId,
+ sink );
+ RightTuple rightTuple = context.rightTuples.get( key );
+
+ parentLeftTuple.setBlocker( rightTuple );
+ rightTuple.setBlocked( parentLeftTuple );
+ }
+ } else if ( sink instanceof ExistsNode ) {
+ BetaMemory memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
+ int type = stream.readInt();
+ if ( type == PersisterEnums.LEFT_TUPLE_NOT_BLOCKED ) {
+ memory.getLeftTupleMemory().add( parentLeftTuple );
+ } else {
+ int factHandleId = stream.readInt();
+ RightTupleKey key = new RightTupleKey( factHandleId,
+ sink );
+ RightTuple rightTuple = context.rightTuples.get( key );
+
+ parentLeftTuple.setBlocker( rightTuple );
+ rightTuple.setBlocked( parentLeftTuple );
+
+ while ( stream.readInt() == PersisterEnums.LEFT_TUPLE ) {
+ LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
+ LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,
+ childSink,
+ true );
+ readLeftTuple( childLeftTuple,
+ context );
+ }
+ }
+ } else if ( sink instanceof RuleTerminalNode ) {
+ RuleTerminalNode ruleTerminalNode = (RuleTerminalNode) sink;
+ TerminalNodeMemory memory = (TerminalNodeMemory) wm.getNodeMemory( ruleTerminalNode );
+ memory.getTupleMemory().add( parentLeftTuple );
+
+ int pos = context.terminalTupleMap.size();
+ context.terminalTupleMap.put( pos,
+ parentLeftTuple );
+ }
+ }
+
+ public static void readActivations(MarshallerReaderContext context) throws IOException {
+ ObjectInputStream stream = context.stream;
+
+ while ( stream.readInt() == PersisterEnums.ACTIVATION ) {
+ readActivation( context );
+ }
+ }
+
+ public static Activation readActivation(MarshallerReaderContext context) throws IOException {
+ ObjectInputStream stream = context.stream;
+ InternalRuleBase ruleBase = context.ruleBase;
+ InternalWorkingMemory wm = context.wm;
+
+ long activationNumber = stream.readLong();
+
+ int pos = stream.readInt();
+ LeftTuple leftTuple = context.terminalTupleMap.get( pos );
+
+ int salience = stream.readInt();
+
+ //PropagationContext context,
+ String pkgName = stream.readUTF();
+ String ruleName = stream.readUTF();
+ Package pkg = ruleBase.getPackage( pkgName );
+ Rule rule = pkg.getRule( ruleName );
+
+ RuleTerminalNode ruleTerminalNode = (RuleTerminalNode) leftTuple.getLeftTupleSink();
+ GroupElement subRule = ruleTerminalNode.getSubRule();
+
+ PropagationContext pc = context.propagationContexts.get( stream.readLong() );
+
+ AgendaItem activation = new AgendaItem( activationNumber,
+ leftTuple,
+ salience,
+ pc,
+ rule,
+ subRule );
+
+ leftTuple.setActivation( activation );
+
+ if ( stream.readBoolean() ) {
+ String activationGroupName = stream.readUTF();
+ wm.getAgenda().getActivationGroup( activationGroupName ).addActivation( activation );
+ }
+
+ boolean activated = stream.readBoolean();
+ activation.setActivated( activated );
+
+ InternalAgendaGroup agendaGroup;
+ if ( rule.getAgendaGroup() == null || rule.getAgendaGroup().equals( "" ) || rule.getAgendaGroup().equals( AgendaGroup.MAIN ) ) {
+ // Is the Rule AgendaGroup undefined? If it is use MAIN,
+ // which is added to the Agenda by default
+ agendaGroup = (InternalAgendaGroup) wm.getAgenda().getAgendaGroup( AgendaGroup.MAIN );
+ } else {
+ // AgendaGroup is defined, so try and get the AgendaGroup
+ // from the Agenda
+ agendaGroup = (InternalAgendaGroup) wm.getAgenda().getAgendaGroup( rule.getAgendaGroup() );
+ }
+
+ activation.setAgendaGroup( agendaGroup );
+
+ if ( activated ) {
+ if ( rule.getRuleFlowGroup() == null ) {
+ agendaGroup.add( activation );
+ } else {
+ InternalRuleFlowGroup rfg = (InternalRuleFlowGroup) wm.getAgenda().getRuleFlowGroup( rule.getRuleFlowGroup() );
+ rfg.addActivation( activation );
+ }
+ }
+
+ TruthMaintenanceSystem tms = context.wm.getTruthMaintenanceSystem();
+ while ( stream.readInt() == PersisterEnums.LOGICAL_DEPENDENCY ) {
+ int factHandleId = stream.readInt();
+ InternalFactHandle handle = (InternalFactHandle) context.handles.get( factHandleId );
+ tms.addLogicalDependency( handle,
+ activation,
+ pc,
+ rule );
+ }
+
+ return activation;
+ }
+
+ public static void readPropagationContexts(MarshallerReaderContext context) throws IOException {
+ ObjectInputStream stream = context.stream;
+
+ while ( stream.readInt() == PersisterEnums.PROPAGATION_CONTEXT ) {
+ readPropagationContext( context );
+ }
+
+ }
+
+ public static void readPropagationContext(MarshallerReaderContext context) throws IOException {
+ ObjectInputStream stream = context.stream;
+ InternalRuleBase ruleBase = context.ruleBase;
+ InternalWorkingMemory wm = context.wm;
+
+ int type = stream.readInt();
+
+ Rule rule = null;
+ if ( stream.readBoolean() ) {
+ String pkgName = stream.readUTF();
+ String ruleName = stream.readUTF();
+ Package pkg = ruleBase.getPackage( pkgName );
+ rule = pkg.getRule( ruleName );
+ }
+
+ LeftTuple leftTuple = null;
+ if ( stream.readBoolean() ) {
+ int tuplePos = stream.readInt();
+ leftTuple = (LeftTuple) context.terminalTupleMap.get( tuplePos );
+ }
+
+ long propagationNumber = stream.readLong();
+
+ int factHandleId = stream.readInt();
+ InternalFactHandle factHandle = context.handles.get( factHandleId );
+
+ int activeActivations = stream.readInt();
+ int dormantActivations = stream.readInt();
+ String entryPointId = stream.readUTF();
+
+ EntryPoint entryPoint = context.entryPoints.get( entryPointId );
+ if ( entryPoint == null ) {
+ entryPoint = new EntryPoint( entryPointId );
+ context.entryPoints.put( entryPointId,
+ entryPoint );
+ }
+
+ PropagationContext pc = new PropagationContextImpl( propagationNumber,
+ type,
+ rule,
+ leftTuple,
+ factHandle,
+ activeActivations,
+ dormantActivations,
+ entryPoint );
+ context.propagationContexts.put( propagationNumber,
+ pc );
+ }
+}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/InputPersister.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/InputPersister.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/InputPersister.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -1,513 +0,0 @@
-package org.drools.marshalling;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Queue;
-
-import org.drools.base.ClassObjectType;
-import org.drools.common.AgendaItem;
-import org.drools.common.BaseNode;
-import org.drools.common.BinaryHeapQueueAgendaGroup;
-import org.drools.common.DefaultAgenda;
-import org.drools.common.DefaultFactHandle;
-import org.drools.common.EqualityKey;
-import org.drools.common.InternalAgendaGroup;
-import org.drools.common.InternalFactHandle;
-import org.drools.common.InternalRuleBase;
-import org.drools.common.InternalRuleFlowGroup;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.common.PropagationContextImpl;
-import org.drools.common.RuleFlowGroupImpl;
-import org.drools.common.TruthMaintenanceSystem;
-import org.drools.concurrent.ExecutorService;
-import org.drools.reteoo.BetaMemory;
-import org.drools.reteoo.BetaNode;
-import org.drools.reteoo.EntryPointNode;
-import org.drools.reteoo.EvalConditionNode;
-import org.drools.reteoo.ExistsNode;
-import org.drools.reteoo.InitialFactHandle;
-import org.drools.reteoo.InitialFactHandleDummyObject;
-import org.drools.reteoo.JoinNode;
-import org.drools.reteoo.LeftInputAdapterNode;
-import org.drools.reteoo.LeftTuple;
-import org.drools.reteoo.LeftTupleSink;
-import org.drools.reteoo.LeftTupleSource;
-import org.drools.reteoo.NotNode;
-import org.drools.reteoo.ObjectSink;
-import org.drools.reteoo.ObjectTypeNode;
-import org.drools.reteoo.ReteooFactHandleFactory;
-import org.drools.reteoo.ReteooStatefulSession;
-import org.drools.reteoo.ReteooWorkingMemory;
-import org.drools.reteoo.RightTuple;
-import org.drools.reteoo.RightTupleSink;
-import org.drools.reteoo.RuleTerminalNode;
-import org.drools.reteoo.EvalConditionNode.EvalMemory;
-import org.drools.reteoo.RuleTerminalNode.TerminalNodeMemory;
-import org.drools.rule.EntryPoint;
-import org.drools.rule.GroupElement;
-import org.drools.rule.Package;
-import org.drools.rule.Rule;
-import org.drools.spi.Activation;
-import org.drools.spi.AgendaGroup;
-import org.drools.spi.FactHandleFactory;
-import org.drools.spi.ObjectType;
-import org.drools.spi.PropagationContext;
-import org.drools.spi.RuleFlowGroup;
-import org.drools.util.BinaryHeapQueue;
-import org.drools.util.Iterator;
-import org.drools.util.ObjectHashMap;
-import org.drools.util.ObjectHashSet;
-import org.drools.util.ObjectHashSet.ObjectEntry;
-
-public class InputPersister {
- public static ReteooStatefulSession readSession(WMSerialisationInContext context,
- int id,
- ExecutorService executor) throws IOException,
- ClassNotFoundException {
- FactHandleFactory handleFactory = context.ruleBase.newFactHandleFactory( context.readInt(),
- context.readLong() );
-
- InitialFactHandle initialFactHandle = new InitialFactHandle( new DefaultFactHandle( context.readInt(), //id
- new InitialFactHandleDummyObject(),
- context.readLong() ) ); //recency
- context.handles.put( initialFactHandle.getId(),
- initialFactHandle );
-
- long propagationCounter = context.readLong();
-
- DefaultAgenda agenda = new DefaultAgenda( context.ruleBase, false );
- readAgenda( context, agenda );
- ReteooStatefulSession session = new ReteooStatefulSession( id,
- context.ruleBase,
- executor,
- handleFactory,
- initialFactHandle,
- propagationCounter,
- agenda );
-
- // RuleFlowGroups need to reference the session
- for ( RuleFlowGroup group : agenda.getRuleFlowGroupsMap().values() ) {
- ((RuleFlowGroupImpl) group).setWorkingMemory( session );
- }
- context.wm = session;
-
- readFactHandles( context );
-
- readActionQueue( context );
-
- if ( context.readBoolean() ) {
- readTruthMaintenanceSystem( context );
- }
-
- return session;
- }
-
- public static void readAgenda(WMSerialisationInContext context, DefaultAgenda agenda) throws IOException {
- ObjectInputStream stream = context.stream;
- while ( stream.readInt() == PersisterEnums.AGENDA_GROUP ) {
- BinaryHeapQueueAgendaGroup group = new BinaryHeapQueueAgendaGroup( stream.readUTF(), context.ruleBase );
- group.setActive( stream.readBoolean() );
- agenda.getAgendaGroupsMap().put( group.getName(), group );
- }
-
- while ( stream.readInt() == PersisterEnums.AGENDA_GROUP ) {
- String agendaGroupName = stream.readUTF();
- agenda.getStackList().add( agenda.getAgendaGroup( agendaGroupName ) );
- }
-
- while ( stream.readInt() == PersisterEnums.RULE_FLOW_GROUP ) {
- String rfgName = stream.readUTF();
- boolean active = stream.readBoolean();
- boolean autoDeactivate = stream.readBoolean();
- RuleFlowGroup rfg = new RuleFlowGroupImpl( rfgName, active, autoDeactivate );
- agenda.getRuleFlowGroupsMap().put( rfgName, rfg );
- }
-
- }
-
- public static void readActionQueue(WMSerialisationInContext context) throws IOException {
- ReteooWorkingMemory wm = (ReteooWorkingMemory) context.wm;
- Queue actionQueue = wm.getActionQueue();
- while ( context.readInt() == PersisterEnums.WORKING_MEMORY_ACTION ) {
- actionQueue.offer( PersisterHelper.readWorkingMemoryAction( context ) );
- }
- }
-
- public static void readTruthMaintenanceSystem(WMSerialisationInContext context) throws IOException {
- ObjectInputStream stream = context.stream;
-
- TruthMaintenanceSystem tms = context.wm.getTruthMaintenanceSystem();
- while ( stream.readInt() == PersisterEnums.EQUALITY_KEY ) {
- int status = stream.readInt();
- int factHandleId = stream.readInt();
- InternalFactHandle handle = (InternalFactHandle) context.handles.get( factHandleId );
- EqualityKey key = new EqualityKey( handle,
- status );
- handle.setEqualityKey( key );
- while ( stream.readInt() == PersisterEnums.FACT_HANDLE ) {
- factHandleId = stream.readInt();
- handle = (InternalFactHandle) context.handles.get( factHandleId );
- key.addFactHandle( handle );
- handle.setEqualityKey( key );
- }
- tms.put( key );
- }
- }
-
- public static void readFactHandles(WMSerialisationInContext context) throws IOException,
- ClassNotFoundException {
- ObjectInputStream stream = context.stream;
- InternalRuleBase ruleBase = context.ruleBase;
- PlaceholderResolverStrategyFactory resolverStrategyFactory = context.resolverStrategyFactory;
- InternalWorkingMemory wm = context.wm;
-
- if ( stream.readBoolean() ) {
- InternalFactHandle initialFactHandle = wm.getInitialFactHandle();
- int sinkId = stream.readInt();
- ObjectTypeNode initialFactNode = (ObjectTypeNode) context.sinks.get( sinkId );
- ObjectHashSet initialFactMemory = (ObjectHashSet) context.wm.getNodeMemory( initialFactNode );
-
- initialFactMemory.add( initialFactHandle );
- readRightTuples( initialFactHandle,
- context );
- }
-
- int size = stream.readInt();
-
- // load the handles
- InternalFactHandle[] handles = new InternalFactHandle[size];
- for ( int i = 0; i < size; i++ ) {
- int id = stream.readInt();
- long recency = stream.readLong();
-
- int strategyIndex = stream.readInt();
- PlaceholderResolverStrategy strategy = resolverStrategyFactory.getStrategy( strategyIndex );
- ObjectPlaceholder placeHolder = strategy.read( stream );
-
- Object object = placeHolder.resolveObject();
-
- InternalFactHandle handle = new DefaultFactHandle( id,
- object,
- recency );
- context.handles.put( id,
- handle );
- handles[i] = handle;
-
- context.wm.getObjectStore().addHandle( handle,
- object );
-
- readRightTuples( handle,
- context );
- }
-
- EntryPointNode node = ruleBase.getRete().getEntryPointNode( EntryPoint.DEFAULT );
- Map<ObjectType, ObjectTypeNode> objectTypeNodes = node.getObjectTypeNodes();
-
- // add handles to object type nodes
- for ( InternalFactHandle handle : handles ) {
- Object object = handle.getObject();
- ClassObjectType objectType = new ClassObjectType( object.getClass() );
- ObjectTypeNode objectTypeNode = objectTypeNodes.get( objectType );
- ObjectHashSet set = (ObjectHashSet) context.wm.getNodeMemory( objectTypeNode );
- set.add( handle,
- false );
- }
-
- InternalFactHandle handle = wm.getInitialFactHandle();
- while ( stream.readInt() == PersisterEnums.LEFT_TUPLE ) {
- LeftTupleSink sink = (LeftTupleSink) context.sinks.get( stream.readInt() );
- LeftTuple leftTuple = new LeftTuple( handle,
- sink,
- true );
- readLeftTuple( leftTuple,
- context );
- }
-
- readLeftTuples( context );
-
- readPropagationContexts( context );
-
- 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;
-
- RightTupleSink sink = (RightTupleSink) context.sinks.get( stream.readInt() );
-
- BetaMemory memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
-
- RightTuple rightTuple = new RightTuple( factHandle,
- sink );
- context.rightTuples.put( new RightTupleKey( factHandle.getId(),
- sink ),
- rightTuple );
-
- memory.getRightTupleMemory().add( rightTuple );
- }
-
- 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();
- LeftTuple leftTuple = new LeftTuple( context.handles.get( factHandleId ),
- sink,
- true );
- readLeftTuple( leftTuple,
- context );
- }
- }
-
- public static void readLeftTuple(LeftTuple parentLeftTuple,
- WMSerialisationInContext context) throws IOException {
- ObjectInputStream stream = context.stream;
- InternalRuleBase ruleBase = context.ruleBase;
- InternalWorkingMemory wm = context.wm;
- Map<Integer, BaseNode> sinks = context.sinks;
-
- LeftTupleSink sink = parentLeftTuple.getLeftTupleSink();
-
- if ( sink instanceof JoinNode ) {
- BetaMemory memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
- memory.getLeftTupleMemory().add( parentLeftTuple );
-
- while ( stream.readInt() == PersisterEnums.RIGHT_TUPLE ) {
- LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
- int factHandleId = stream.readInt();
- RightTupleKey key = new RightTupleKey( factHandleId,
- sink );
- RightTuple rightTuple = context.rightTuples.get( key );
- LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,
- rightTuple,
- childSink,
- true );
- readLeftTuple( childLeftTuple,
- context );
- }
-
- } else if ( sink instanceof EvalConditionNode ) {
- final EvalMemory memory = (EvalMemory) context.wm.getNodeMemory( (EvalConditionNode) sink );
- memory.tupleMemory.add( parentLeftTuple );
- while ( stream.readInt() == PersisterEnums.LEFT_TUPLE ) {
- LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
- LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,
- childSink,
- true );
- readLeftTuple( childLeftTuple,
- context );
- }
- } else if ( sink instanceof NotNode ) {
- BetaMemory memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
- int type = stream.readInt();
- if ( type == PersisterEnums.LEFT_TUPLE_NOT_BLOCKED ) {
- memory.getLeftTupleMemory().add( parentLeftTuple );
-
- while ( stream.readInt() == PersisterEnums.LEFT_TUPLE ) {
- LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
- LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,
- childSink,
- true );
- readLeftTuple( childLeftTuple,
- context );
- }
-
- } else {
- int factHandleId = stream.readInt();
- RightTupleKey key = new RightTupleKey( factHandleId,
- sink );
- RightTuple rightTuple = context.rightTuples.get( key );
-
- parentLeftTuple.setBlocker( rightTuple );
- rightTuple.setBlocked( parentLeftTuple );
- }
- } else if ( sink instanceof ExistsNode ) {
- BetaMemory memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
- int type = stream.readInt();
- if ( type == PersisterEnums.LEFT_TUPLE_NOT_BLOCKED ) {
- memory.getLeftTupleMemory().add( parentLeftTuple );
- } else {
- int factHandleId = stream.readInt();
- RightTupleKey key = new RightTupleKey( factHandleId,
- sink );
- RightTuple rightTuple = context.rightTuples.get( key );
-
- parentLeftTuple.setBlocker( rightTuple );
- rightTuple.setBlocked( parentLeftTuple );
-
- while ( stream.readInt() == PersisterEnums.LEFT_TUPLE ) {
- LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
- LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,
- childSink,
- true );
- readLeftTuple( childLeftTuple,
- context );
- }
- }
- } else if ( sink instanceof RuleTerminalNode ) {
- RuleTerminalNode ruleTerminalNode = (RuleTerminalNode) sink;
- TerminalNodeMemory memory = (TerminalNodeMemory) wm.getNodeMemory( ruleTerminalNode );
- memory.getTupleMemory().add( parentLeftTuple );
-
- int pos = context.terminalTupleMap.size();
- context.terminalTupleMap.put( pos,
- parentLeftTuple );
- }
- }
-
- public static void readActivations(WMSerialisationInContext context) throws IOException {
- ObjectInputStream stream = context.stream;
-
- while ( stream.readInt() == PersisterEnums.ACTIVATION ) {
- readActivation( context );
- }
- }
-
- public static Activation readActivation(WMSerialisationInContext context) throws IOException {
- ObjectInputStream stream = context.stream;
- InternalRuleBase ruleBase = context.ruleBase;
- InternalWorkingMemory wm = context.wm;
-
- long activationNumber = stream.readLong();
-
- int pos = stream.readInt();
- LeftTuple leftTuple = context.terminalTupleMap.get( pos );
-
- int salience = stream.readInt();
-
- //PropagationContext context,
- String pkgName = stream.readUTF();
- String ruleName = stream.readUTF();
- Package pkg = ruleBase.getPackage( pkgName );
- Rule rule = pkg.getRule( ruleName );
-
- RuleTerminalNode ruleTerminalNode = (RuleTerminalNode) leftTuple.getLeftTupleSink();
- GroupElement subRule = ruleTerminalNode.getSubRule();
-
- PropagationContext pc = context.propagationContexts.get( stream.readLong() );
-
- AgendaItem activation = new AgendaItem( activationNumber,
- leftTuple,
- salience,
- pc,
- rule,
- subRule );
-
- leftTuple.setActivation( activation );
-
- if ( stream.readBoolean() ) {
- String activationGroupName = stream.readUTF();
- wm.getAgenda().getActivationGroup( activationGroupName ).addActivation( activation );
- }
-
- boolean activated = stream.readBoolean();
- activation.setActivated( activated );
-
- InternalAgendaGroup agendaGroup;
- if ( rule.getAgendaGroup() == null || rule.getAgendaGroup().equals( "" ) || rule.getAgendaGroup().equals( AgendaGroup.MAIN ) ) {
- // Is the Rule AgendaGroup undefined? If it is use MAIN,
- // which is added to the Agenda by default
- agendaGroup = (InternalAgendaGroup) wm.getAgenda().getAgendaGroup( AgendaGroup.MAIN );
- } else {
- // AgendaGroup is defined, so try and get the AgendaGroup
- // from the Agenda
- agendaGroup = (InternalAgendaGroup) wm.getAgenda().getAgendaGroup( rule.getAgendaGroup() );
- }
-
- activation.setAgendaGroup( agendaGroup );
-
- if ( activated ) {
- if ( rule.getRuleFlowGroup() == null ) {
- agendaGroup.add( activation );
- } else {
- InternalRuleFlowGroup rfg = (InternalRuleFlowGroup) wm.getAgenda().getRuleFlowGroup( rule.getRuleFlowGroup() );
- rfg.addActivation( activation );
- }
- }
-
- TruthMaintenanceSystem tms = context.wm.getTruthMaintenanceSystem();
- while ( stream.readInt() == PersisterEnums.LOGICAL_DEPENDENCY ) {
- int factHandleId = stream.readInt();
- InternalFactHandle handle = (InternalFactHandle) context.handles.get( factHandleId );
- tms.addLogicalDependency( handle,
- activation,
- pc,
- rule );
- }
-
- return activation;
- }
-
- public static void readPropagationContexts(WMSerialisationInContext context) throws IOException {
- ObjectInputStream stream = context.stream;
-
- while ( stream.readInt() == PersisterEnums.PROPAGATION_CONTEXT ) {
- readPropagationContext( context );
- }
-
- }
-
- public static void readPropagationContext(WMSerialisationInContext context) throws IOException {
- ObjectInputStream stream = context.stream;
- InternalRuleBase ruleBase = context.ruleBase;
- InternalWorkingMemory wm = context.wm;
-
- int type = stream.readInt();
-
- Rule rule = null;
- if ( stream.readBoolean() ) {
- String pkgName = stream.readUTF();
- String ruleName = stream.readUTF();
- Package pkg = ruleBase.getPackage( pkgName );
- rule = pkg.getRule( ruleName );
- }
-
- LeftTuple leftTuple = null;
- if ( stream.readBoolean() ) {
- int tuplePos = stream.readInt();
- leftTuple = (LeftTuple) context.terminalTupleMap.get( tuplePos );
- }
-
- long propagationNumber = stream.readLong();
-
- int factHandleId = stream.readInt();
- InternalFactHandle factHandle = context.handles.get( factHandleId );
-
- int activeActivations = stream.readInt();
- int dormantActivations = stream.readInt();
- String entryPointId = stream.readUTF();
-
- EntryPoint entryPoint = context.entryPoints.get( entryPointId );
- if ( entryPoint == null ) {
- entryPoint = new EntryPoint( entryPointId );
- context.entryPoints.put( entryPointId,
- entryPoint );
- }
-
- PropagationContext pc = new PropagationContextImpl( propagationNumber,
- type,
- rule,
- leftTuple,
- factHandle,
- activeActivations,
- dormantActivations,
- entryPoint );
- context.propagationContexts.put( propagationNumber,
- pc );
- }
-}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/Marshaller.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/Marshaller.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/Marshaller.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -1,72 +0,0 @@
-package org.drools.marshalling;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.drools.RuleBaseConfiguration;
-import org.drools.StatefulSession;
-import org.drools.common.InternalRuleBase;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.concurrent.ExecutorService;
-import org.drools.reteoo.ReteooStatefulSession;
-import org.drools.spi.GlobalResolver;
-
-public class Marshaller {
- GlobalResolver globalResolver;
- private RuleBaseConfiguration config;
- PlaceholderResolverStrategyFactory factory;
-
- public Marshaller() {
- this( null );
- }
-
- public Marshaller(RuleBaseConfiguration config) {
- this( config, null);
- }
-
- public Marshaller(RuleBaseConfiguration config,
- PlaceholderResolverStrategyFactory factory) {
- this.config = (config != null) ? config : new RuleBaseConfiguration();
-
- if ( factory == null ) {
- this.factory = new PlaceholderResolverStrategyFactory();
- ClassPlaceholderResolverStrategyAcceptor acceptor = new ClassPlaceholderResolverStrategyAcceptor( "*.*" );
- IdentityPlaceholderResolverStrategy strategy = new IdentityPlaceholderResolverStrategy( acceptor );
- this.factory.addStrategy( strategy );
- } else {
- this.factory = factory;
- }
- }
-
- public ReteooStatefulSession read(final InputStream stream,
- final InternalRuleBase ruleBase,
- final int id,
- final ExecutorService executor) throws IOException,
- ClassNotFoundException {
- WMSerialisationInContext context = new WMSerialisationInContext( stream,
- ruleBase,
- RuleBaseNodes.getNodeMap( ruleBase ),
- factory );
-
- ReteooStatefulSession session = InputPersister.readSession( context,
- id,
- executor );
- context.close();
- return session;
-
- }
-
- public void write(final OutputStream stream,
- final InternalRuleBase ruleBase,
- final StatefulSession session) throws IOException {
- WMSerialisationOutContext context = new WMSerialisationOutContext( stream,
- ruleBase,
- (InternalWorkingMemory) session,
- RuleBaseNodes.getNodeMap( ruleBase ),
- this.factory );
- OutputPersister.writeSession( context );
- context.close();
- }
-
-}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/MarshallerReaderContext.java (from rev 19998, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/WMSerialisationInContext.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/MarshallerReaderContext.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/MarshallerReaderContext.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -0,0 +1,52 @@
+/**
+ *
+ */
+package org.drools.marshalling;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.common.BaseNode;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.LeftTuple;
+import org.drools.reteoo.RightTuple;
+import org.drools.rule.EntryPoint;
+import org.drools.spi.PropagationContext;
+
+public class MarshallerReaderContext extends ObjectInputStream {
+ public final MarshallerReaderContext stream;
+ public final InternalRuleBase ruleBase;
+ public InternalWorkingMemory wm;
+ public final Map<Integer, BaseNode> sinks;
+
+ public Map<Integer, InternalFactHandle> handles;
+
+ public final Map<RightTupleKey, RightTuple> rightTuples;
+ public final Map<Integer, LeftTuple> terminalTupleMap;
+
+ public final PlaceholderResolverStrategyFactory resolverStrategyFactory;
+ public final Map<String, EntryPoint> entryPoints;
+
+ public final Map<Long, PropagationContext> propagationContexts;
+
+ public MarshallerReaderContext(InputStream stream,
+ InternalRuleBase ruleBase,
+ Map<Integer, BaseNode> sinks,
+ PlaceholderResolverStrategyFactory resolverStrategyFactory) throws IOException {
+ super( stream );
+ this.stream = this;
+ this.ruleBase = ruleBase;
+ this.sinks = sinks;
+ this.handles = new HashMap<Integer, InternalFactHandle>();
+ this.rightTuples = new HashMap<RightTupleKey, RightTuple>();
+ this.terminalTupleMap = new HashMap<Integer, LeftTuple>();
+ this.entryPoints = new HashMap<String, EntryPoint>();
+ this.propagationContexts = new HashMap<Long, PropagationContext>();
+ this.resolverStrategyFactory = resolverStrategyFactory;
+ }
+}
\ No newline at end of file
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/MarshallerWriteContext.java (from rev 19998, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/WMSerialisationOutContext.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/MarshallerWriteContext.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/MarshallerWriteContext.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -0,0 +1,47 @@
+/**
+ *
+ */
+package org.drools.marshalling;
+
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import org.drools.common.BaseNode;
+import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.LeftTuple;
+
+public class MarshallerWriteContext extends ObjectOutputStream {
+ public final MarshallerWriteContext stream;
+ public final InternalRuleBase ruleBase;
+ public final InternalWorkingMemory wm;
+ public final Map<Integer, BaseNode> sinks;
+
+ public final PrintStream out = System.out;
+
+ public final PlaceholderResolverStrategyFactory resolverStrategyFactory;
+
+ public final Map<LeftTuple, Integer> terminalTupleMap;
+
+ public MarshallerWriteContext(OutputStream stream,
+ InternalRuleBase ruleBase,
+ InternalWorkingMemory wm,
+ Map<Integer, BaseNode> sinks,
+ PlaceholderResolverStrategyFactory resolverStrategyFactory) throws IOException {
+ super( stream );
+ this.stream = this;
+ this.ruleBase = ruleBase;
+ this.wm = wm;
+ this.sinks = sinks;
+
+ this.resolverStrategyFactory = resolverStrategyFactory;
+
+ this.terminalTupleMap = new IdentityHashMap<LeftTuple, Integer>();
+ }
+}
\ No newline at end of file
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java (from rev 19998, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputPersister.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -0,0 +1,587 @@
+package org.drools.marshalling;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.drools.InitialFact;
+import org.drools.base.ClassObjectType;
+import org.drools.base.ShadowProxy;
+import org.drools.common.AbstractFactHandleFactory;
+import org.drools.common.AgendaItem;
+import org.drools.common.BinaryHeapQueueAgendaGroup;
+import org.drools.common.DefaultAgenda;
+import org.drools.common.EqualityKey;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.common.LogicalDependency;
+import org.drools.common.ObjectStore;
+import org.drools.common.PropagationContextImpl;
+import org.drools.common.RuleFlowGroupImpl;
+import org.drools.common.WorkingMemoryAction;
+import org.drools.marshalling.Placeholders.PlaceholderEntry;
+import org.drools.reteoo.BetaMemory;
+import org.drools.reteoo.BetaNode;
+import org.drools.reteoo.EvalConditionNode;
+import org.drools.reteoo.ExistsNode;
+import org.drools.reteoo.JoinNode;
+import org.drools.reteoo.LeftInputAdapterNode;
+import org.drools.reteoo.LeftTuple;
+import org.drools.reteoo.LeftTupleSink;
+import org.drools.reteoo.NotNode;
+import org.drools.reteoo.ObjectTypeNode;
+import org.drools.reteoo.ReteooFactHandleFactory;
+import org.drools.reteoo.ReteooWorkingMemory;
+import org.drools.reteoo.RightTuple;
+import org.drools.reteoo.RightTupleSink;
+import org.drools.reteoo.RuleTerminalNode;
+import org.drools.reteoo.EvalConditionNode.EvalMemory;
+import org.drools.rule.EntryPoint;
+import org.drools.rule.Rule;
+import org.drools.spi.Activation;
+import org.drools.spi.ActivationGroup;
+import org.drools.spi.AgendaGroup;
+import org.drools.spi.FactHandleFactory;
+import org.drools.spi.PropagationContext;
+import org.drools.spi.RuleFlowGroup;
+import org.drools.util.ObjectHashMap;
+import org.drools.util.ObjectHashSet;
+import org.drools.util.ObjectHashSet.ObjectEntry;
+
+public class OutputMarshaller {
+ public static void writeSession(MarshallerWriteContext context) throws IOException {
+ ReteooWorkingMemory wm = (ReteooWorkingMemory) context.wm;
+
+ context.writeInt( wm.getFactHandleFactory().getId() );
+ context.writeLong( wm.getFactHandleFactory().getRecency() );
+ System.out.println( "FactHandleFactory int:" + wm.getFactHandleFactory().getId() + " long:" + wm.getFactHandleFactory().getRecency() );
+
+ InternalFactHandle handle = context.wm.getInitialFactHandle();
+ context.writeInt( handle.getId() );
+ context.writeLong( handle.getRecency() );
+ context.out.println( "InitialFact int:" + handle.getId() + " long:" + handle.getRecency() );
+
+ context.writeLong( wm.getPropagationIdCounter() );
+ System.out.println( "PropagationCounter long:" + wm.getPropagationIdCounter() );
+
+ writeAgenda( context );
+
+ writeFactHandles( context );
+
+ writeActionQueue( context );
+
+ if ( wm.getTruthMaintenanceSystem() != null ) {
+ context.writeBoolean( true );
+ writeTruthMaintenanceSystem( context );
+ } else {
+ context.writeBoolean( false );
+ }
+ }
+
+ public static void writeAgenda(MarshallerWriteContext context) throws IOException {
+ InternalWorkingMemory wm = context.wm;
+ DefaultAgenda agenda = (DefaultAgenda) wm.getAgenda();
+
+ Map<String, ActivationGroup> activationGroups = agenda.getActivationGroupsMap();
+
+ AgendaGroup[] agendaGroups = (AgendaGroup[]) agenda.getAgendaGroupsMap().values().toArray( new AgendaGroup[agenda.getAgendaGroupsMap().size()] );
+ Arrays.sort( agendaGroups,
+ AgendaGroupSorter.instance );
+
+ for ( AgendaGroup group : agendaGroups ) {
+ context.writeInt( PersisterEnums.AGENDA_GROUP );
+ context.writeUTF( group.getName() );
+ context.writeBoolean( group.isActive() );
+ }
+ context.writeInt( PersisterEnums.END );
+
+ LinkedList<AgendaGroup> focusStack = agenda.getStackList();
+ for ( Iterator<AgendaGroup> it = focusStack.iterator(); it.hasNext(); ) {
+ AgendaGroup group = it.next();
+ context.writeInt( PersisterEnums.AGENDA_GROUP );
+ context.writeUTF( group.getName() );
+ }
+ context.writeInt( PersisterEnums.END );
+
+ RuleFlowGroupImpl[] ruleFlowGroups = (RuleFlowGroupImpl[]) agenda.getRuleFlowGroupsMap().values().toArray( new RuleFlowGroupImpl[agenda.getRuleFlowGroupsMap().size()] );
+ Arrays.sort( ruleFlowGroups,
+ RuleFlowGroupSorter.instance );
+
+ for ( RuleFlowGroupImpl group : ruleFlowGroups ) {
+ context.writeInt( PersisterEnums.RULE_FLOW_GROUP );
+ //group.write( context );
+ context.writeUTF( group.getName() );
+ context.writeBoolean( group.isActive() );
+ context.writeBoolean( group.isAutoDeactivate() );
+ }
+ context.writeInt( PersisterEnums.END );
+ }
+
+ public static class AgendaGroupSorter
+ implements
+ Comparator<AgendaGroup> {
+ public static final AgendaGroupSorter instance = new AgendaGroupSorter();
+
+ public int compare(AgendaGroup group1,
+ AgendaGroup group2) {
+ return group1.getName().compareTo( group2.getName() );
+ }
+ }
+
+ public static class RuleFlowGroupSorter
+ implements
+ Comparator<RuleFlowGroup> {
+ public static final RuleFlowGroupSorter instance = new RuleFlowGroupSorter();
+
+ public int compare(RuleFlowGroup group1,
+ RuleFlowGroup group2) {
+ return group1.getName().compareTo( group2.getName() );
+ }
+ }
+
+ public static void writeActionQueue(MarshallerWriteContext context) throws IOException {
+ ReteooWorkingMemory wm = (ReteooWorkingMemory) context.wm;
+
+ WorkingMemoryAction[] queue = wm.getActionQueue().toArray( new WorkingMemoryAction[wm.getActionQueue().size()] );
+ for ( int i = queue.length - 1; i >= 0; i-- ) {
+ context.writeInt( PersisterEnums.WORKING_MEMORY_ACTION );
+ queue[i].write( context );
+ }
+ context.writeInt( PersisterEnums.END );
+ }
+
+ public static void writeTruthMaintenanceSystem(MarshallerWriteContext context) throws IOException {
+ ObjectOutputStream stream = context.stream;
+
+ ObjectHashMap assertMap = context.wm.getTruthMaintenanceSystem().getAssertMap();
+
+ EqualityKey[] keys = new EqualityKey[assertMap.size()];
+ org.drools.util.Iterator it = assertMap.iterator();
+ int i = 0;
+ for ( org.drools.util.ObjectHashMap.ObjectEntry entry = (org.drools.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.util.ObjectHashMap.ObjectEntry) it.next() ) {
+ EqualityKey key = (EqualityKey) entry.getKey();
+ keys[i++] = key;
+ }
+
+ Arrays.sort( keys,
+ EqualityKeySorter.instance );
+
+ // write the assert map of Equality keys
+ for ( EqualityKey key : keys ) {
+ stream.writeInt( PersisterEnums.EQUALITY_KEY );
+ stream.writeInt( key.getStatus() );
+ InternalFactHandle handle = key.getFactHandle();
+ stream.writeInt( handle.getId() );
+ context.out.println( "EqualityKey int:" + key.getStatus() + " int:" + handle.getId() );
+ if ( key.getOtherFactHandle() != null && !key.getOtherFactHandle().isEmpty() ) {
+ for ( InternalFactHandle handle2 : key.getOtherFactHandle() ) {
+ stream.writeInt( PersisterEnums.FACT_HANDLE );
+ stream.writeInt( handle2.getId() );
+ context.out.println( "OtherHandle int:" + handle2.getId() );
+ }
+ }
+ stream.writeInt( PersisterEnums.END );
+ }
+ stream.writeInt( PersisterEnums.END );
+ }
+
+ public static class EqualityKeySorter
+ implements
+ Comparator<EqualityKey> {
+ public static final EqualityKeySorter instance = new EqualityKeySorter();
+
+ public int compare(EqualityKey key1,
+ EqualityKey key2) {
+ return key1.getFactHandle().getId() - key2.getFactHandle().getId();
+ }
+ }
+
+ public static void writeFactHandles(MarshallerWriteContext context) throws IOException {
+ ObjectOutputStream stream = context.stream;
+ InternalWorkingMemory wm = context.wm;
+ PlaceholderResolverStrategyFactory resolverStrategyFactory = context.resolverStrategyFactory;
+
+ writeInitialFactHandleRightTuples( context );
+
+ stream.writeInt( wm.getObjectStore().size() );
+
+ // Write out FactHandles
+ for ( InternalFactHandle handle : orderFacts( wm.getObjectStore() ) ) {
+ //stream.writeInt( PersisterEnums.FACT_HANDLE );
+ //InternalFactHandle handle = (InternalFactHandle) it.next();
+ stream.writeInt( handle.getId() );
+ stream.writeLong( handle.getRecency() );
+
+ context.out.println( "Object : int:" + handle.getId() + " long:" + handle.getRecency() );
+ context.out.println( handle.getObject() );
+
+ Object object = handle.getObject();
+ if ( object instanceof ShadowProxy ) {
+ object = ((ShadowProxy) object).getShadowedObject();
+ }
+
+ PlaceholderResolverStrategy strategy = resolverStrategyFactory.getStrategy( handle.getObject() );
+
+ stream.writeInt( strategy.getIndex() );
+
+ strategy.write( stream,
+ object );
+
+ writeRightTuples( handle,
+ context );
+ }
+
+ writeInitialFactHandleLeftTuples( context );
+
+ writeLeftTuples( context );
+
+ writePropagationContexts( context );
+
+ writeActivations( context );
+ }
+
+ public static InternalFactHandle[] orderFacts(ObjectStore objectStore) {
+ // this method is just needed for testing purposes, to allow round tripping
+ int size = objectStore.size();
+ InternalFactHandle[] handles = new InternalFactHandle[size];
+ int i = 0;
+ for ( Iterator it = objectStore.iterateFactHandles(); it.hasNext(); ) {
+ handles[i++] = (InternalFactHandle) it.next();
+ }
+
+ Arrays.sort( handles,
+ new HandleSorter() );
+
+ return handles;
+ }
+
+ public static class HandleSorter
+ implements
+ Comparator<InternalFactHandle> {
+ public int compare(InternalFactHandle h1,
+ InternalFactHandle h2) {
+ return h1.getId() - h2.getId();
+ }
+ }
+
+ public static void writeInitialFactHandleRightTuples(MarshallerWriteContext context) throws IOException {
+ ObjectOutputStream stream = context.stream;
+ InternalRuleBase ruleBase = context.ruleBase;
+
+ ObjectTypeNode initialFactNode = ruleBase.getRete().getEntryPointNode( EntryPoint.DEFAULT ).getObjectTypeNodes().get( new ClassObjectType( InitialFact.class ) );
+
+ // do we write the fact to the objecttypenode memory
+ if ( initialFactNode != null ) {
+ ObjectHashSet initialFactMemory = (ObjectHashSet) context.wm.getNodeMemory( initialFactNode );
+ if ( initialFactMemory != null && !initialFactMemory.isEmpty() ) {
+ context.out.println( "InitialFactMemory true int:" + initialFactNode.getId() );
+ stream.writeBoolean( true );
+ stream.writeInt( initialFactNode.getId() );
+
+ context.out.println( "InitialFact RightTuples" );
+ writeRightTuples( context.wm.getInitialFactHandle(),
+ context );
+ } else {
+ context.out.println( "InitialFactMemory false " );
+ stream.writeBoolean( false );
+ }
+ } else {
+ context.out.println( "InitialFactMemory false " );
+ stream.writeBoolean( false );
+ }
+ }
+
+ public static void writeInitialFactHandleLeftTuples(MarshallerWriteContext context) throws IOException {
+ ObjectOutputStream stream = context.stream;
+
+ context.out.println( "InitialFact LeftTuples Start" );
+ InternalFactHandle handle = context.wm.getInitialFactHandle();
+ for ( LeftTuple leftTuple = getLeftTuple( handle.getLeftTuple() ); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
+ stream.writeInt( PersisterEnums.LEFT_TUPLE );
+
+ stream.writeInt( leftTuple.getLeftTupleSink().getId() );
+ context.out.println( "LeftTuple int:" + leftTuple.getLeftTupleSink().getId() );
+ writeLeftTuple( leftTuple,
+ context );
+ }
+ stream.writeInt( PersisterEnums.END );
+ context.out.println( "InitialFact LeftTuples End" );
+ }
+
+ public static void writeRightTuples(InternalFactHandle handle,
+ MarshallerWriteContext context) throws IOException {
+ ObjectOutputStream stream = context.stream;
+ context.out.println( "RightTuples Start" );
+
+ RightTuple rightTuple = handle.getRightTuple();
+ for ( RightTuple tempRightTuple = rightTuple; tempRightTuple != null; tempRightTuple = (RightTuple) tempRightTuple.getHandleNext() ) {
+ rightTuple = tempRightTuple;
+ }
+ for ( ; rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandlePrevious() ) {
+ stream.writeInt( PersisterEnums.RIGHT_TUPLE );
+ writeRightTuple( rightTuple,
+ context );
+ }
+ stream.writeInt( PersisterEnums.END );
+ context.out.println( "RightTuples END" );
+ }
+
+ public static void writeRightTuple(RightTuple rightTuple,
+ MarshallerWriteContext context) throws IOException {
+ ObjectOutputStream stream = context.stream;
+ InternalWorkingMemory wm = context.wm;
+ stream.writeInt( rightTuple.getRightTupleSink().getId() );
+ context.out.println( "RightTuple int:" + rightTuple.getRightTupleSink().getId() );
+ }
+
+ public static void writeLeftTuples(MarshallerWriteContext context) throws IOException {
+ ObjectOutputStream stream = context.stream;
+ InternalWorkingMemory wm = context.wm;
+
+ // Write out LeftTuples
+ context.out.println( "LeftTuples Start" );
+ for ( InternalFactHandle handle : orderFacts( wm.getObjectStore() ) ) {
+ //InternalFactHandle handle = (InternalFactHandle) it.next();
+
+ for ( LeftTuple leftTuple = getLeftTuple( handle.getLeftTuple() ); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
+ stream.writeInt( PersisterEnums.LEFT_TUPLE );
+
+ stream.writeInt( leftTuple.getLeftTupleSink().getId() );
+ stream.writeInt( handle.getId() );
+
+ context.out.println( "LeftTuple int:" + leftTuple.getLeftTupleSink().getId() + " int:" + handle.getId() );
+ writeLeftTuple( leftTuple,
+ context );
+ }
+ }
+ stream.writeInt( PersisterEnums.END );
+ context.out.println( "LeftTuples End" );
+ }
+
+ public static void writeLeftTuple(LeftTuple leftTuple,
+ MarshallerWriteContext context) throws IOException {
+ ObjectOutputStream stream = context.stream;
+ InternalRuleBase ruleBase = context.ruleBase;
+ InternalWorkingMemory wm = context.wm;
+
+ LeftTupleSink sink = leftTuple.getLeftTupleSink();
+
+ if ( sink instanceof JoinNode ) {
+ context.out.println( "JoinNode" );
+
+ for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.getBetaChildren() ); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentPrevious() ) {
+ stream.writeInt( PersisterEnums.RIGHT_TUPLE );
+ stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
+ stream.writeInt( childLeftTuple.getRightParent().getFactHandle().getId() );
+ context.out.println( "RightTuple int:" + childLeftTuple.getLeftTupleSink().getId() + " int:" + childLeftTuple.getRightParent().getFactHandle().getId() );
+ writeLeftTuple( childLeftTuple,
+ context );
+ }
+ stream.writeInt( PersisterEnums.END );
+ } else if ( sink instanceof EvalConditionNode ) {
+ context.out.println( "EvalConditionNode" );
+ for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.getBetaChildren() ); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentPrevious() ) {
+ stream.writeInt( PersisterEnums.LEFT_TUPLE );
+ stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
+ writeLeftTuple( childLeftTuple,
+ context );
+ }
+ stream.writeInt( PersisterEnums.END );
+ } else if ( sink instanceof NotNode ) {
+ if ( leftTuple.getBlocker() == null ) {
+ // is not blocked so has children
+ stream.writeInt( PersisterEnums.LEFT_TUPLE_NOT_BLOCKED );
+
+ for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.getBetaChildren() ); childLeftTuple != null; childLeftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
+ stream.writeInt( PersisterEnums.LEFT_TUPLE );
+ stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
+ writeLeftTuple( childLeftTuple,
+ context );
+ }
+ stream.writeInt( PersisterEnums.END );
+
+ } else {
+ stream.writeInt( PersisterEnums.LEFT_TUPLE_BLOCKED );
+ stream.writeInt( leftTuple.getBlocker().getFactHandle().getId() );
+ }
+ } else if ( sink instanceof ExistsNode ) {
+ if ( leftTuple.getBlocker() == null ) {
+ // is blocked so has children
+ stream.writeInt( PersisterEnums.LEFT_TUPLE_NOT_BLOCKED );
+ } else {
+ stream.writeInt( PersisterEnums.LEFT_TUPLE_BLOCKED );
+ stream.writeInt( leftTuple.getBlocker().getFactHandle().getId() );
+
+ for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.getBetaChildren() ); childLeftTuple != null; childLeftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
+ stream.writeInt( PersisterEnums.LEFT_TUPLE );
+ stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
+ writeLeftTuple( childLeftTuple,
+ context );
+ }
+ stream.writeInt( PersisterEnums.END );
+ }
+ } else if ( sink instanceof RuleTerminalNode ) {
+ context.out.println( "RuleTerminalNode" );
+ int pos = context.terminalTupleMap.size();
+ context.terminalTupleMap.put( leftTuple,
+ pos );
+ }
+ }
+
+ public static LeftTuple getLeftTuple(LeftTuple leftTuple) {
+ for ( LeftTuple tempLeftTuple = leftTuple; tempLeftTuple != null; tempLeftTuple = (LeftTuple) tempLeftTuple.getLeftParentNext() ) {
+ leftTuple = tempLeftTuple;
+ }
+ return leftTuple;
+ }
+
+ public static void writeActivations(MarshallerWriteContext context) throws IOException {
+ ObjectOutputStream stream = context.stream;
+
+ Entry<LeftTuple, Integer>[] entries = context.terminalTupleMap.entrySet().toArray( new Entry[ context.terminalTupleMap.size() ] );
+ Arrays.sort( entries, TupleSorter.instance );
+
+ //Map<LeftTuple, Integer> tuples = context.terminalTupleMap;
+ if ( entries.length != 0 ) {
+ for ( Entry<LeftTuple, Integer> entry : entries ) {
+ LeftTuple leftTuple = entry.getKey();
+ stream.writeInt( PersisterEnums.ACTIVATION );
+ writeActivation( context,
+ leftTuple,
+ (AgendaItem) leftTuple.getActivation(),
+ (RuleTerminalNode) leftTuple.getLeftTupleSink() );
+ }
+ }
+ stream.writeInt( PersisterEnums.END );
+ }
+
+ public static class TupleSorter
+ implements
+ Comparator<Entry<LeftTuple, Integer>> {
+ public static final TupleSorter instance = new TupleSorter();
+ public int compare(Entry<LeftTuple, Integer> e1,
+ Entry<LeftTuple, Integer> e2) {
+ return e1.getValue() - e2.getValue();
+ }
+ }
+
+ public static void writeActivation(MarshallerWriteContext context,
+ LeftTuple leftTuple,
+ AgendaItem agendaItem,
+ RuleTerminalNode ruleTerminalNode) throws IOException {
+ ObjectOutputStream stream = context.stream;
+
+ stream.writeLong( agendaItem.getActivationNumber() );
+
+ stream.writeInt( context.terminalTupleMap.get( leftTuple ) );
+
+ stream.writeInt( agendaItem.getSalience() );
+
+ Rule rule = agendaItem.getRule();
+ stream.writeUTF( rule.getPackage() );
+ stream.writeUTF( rule.getName() );
+
+ context.out.println( "Rule " + rule.getPackage() + "." + rule.getName() );
+
+ context.out.println( "AgendaItem long:" + agendaItem.getPropagationContext().getPropagationNumber() );
+ stream.writeLong( agendaItem.getPropagationContext().getPropagationNumber() );
+
+ if ( agendaItem.getActivationGroupNode() != null ) {
+ stream.writeBoolean( true );
+ context.out.println( "ActivationGroup bool:" + true );
+ stream.writeUTF( agendaItem.getActivationGroupNode().getActivationGroup().getName() );
+ context.out.println( "ActivationGroup string:" + agendaItem.getActivationGroupNode().getActivationGroup().getName() );
+ } else {
+ stream.writeBoolean( false );
+ context.out.println( "ActivationGroup bool:" + false );
+ }
+
+ stream.writeBoolean( agendaItem.isActivated() );
+ context.out.println( "AgendaItem bool:" + agendaItem.isActivated() );
+
+ org.drools.util.LinkedList list = agendaItem.getLogicalDependencies();
+ if ( list != null && !list.isEmpty() ) {
+ for ( LogicalDependency node = (LogicalDependency) list.getFirst(); node != null; node = (LogicalDependency) node.getNext() ) {
+ stream.writeInt( PersisterEnums.LOGICAL_DEPENDENCY );
+ stream.writeInt( ((InternalFactHandle) node.getFactHandle()).getId() );
+ context.out.println( "Logical Depenency : int " + ((InternalFactHandle) node.getFactHandle()).getId() );
+ }
+ }
+ stream.writeInt( PersisterEnums.END );
+ }
+
+ public static void writePropagationContexts(MarshallerWriteContext context) throws IOException {
+ ObjectOutputStream stream = context.stream;
+
+ Entry<LeftTuple, Integer>[] entries = context.terminalTupleMap.entrySet().toArray( new Entry[ context.terminalTupleMap.size() ] );
+ Arrays.sort( entries, TupleSorter.instance );
+
+ //Map<LeftTuple, Integer> tuples = context.terminalTupleMap;
+ if ( entries.length != 0 ) {
+ Map<Long, PropagationContext> pcMap = new HashMap<Long, PropagationContext>();
+ for ( Entry<LeftTuple, Integer> entry : entries ) {
+ LeftTuple leftTuple = entry.getKey();
+ PropagationContext pc = leftTuple.getActivation().getPropagationContext();
+ if ( !pcMap.containsKey( pc.getPropagationNumber() ) ) {
+ stream.writeInt( PersisterEnums.PROPAGATION_CONTEXT );
+ writePropagationContext( context,
+ pc );
+ pcMap.put( pc.getPropagationNumber(),
+ pc );
+ }
+ }
+ }
+
+ stream.writeInt( PersisterEnums.END );
+ }
+
+ public static void writePropagationContext(MarshallerWriteContext context,
+ PropagationContext pc) throws IOException {
+ ObjectOutputStream stream = context.stream;
+ Map<LeftTuple, Integer> tuples = context.terminalTupleMap;
+
+ stream.writeInt( pc.getType() );
+
+ Rule ruleOrigin = pc.getRuleOrigin();
+ if ( ruleOrigin != null ) {
+ stream.writeBoolean( true );
+ stream.writeUTF( ruleOrigin.getPackage() );
+ stream.writeUTF( ruleOrigin.getName() );
+ } else {
+ stream.writeBoolean( false );
+ }
+
+ LeftTuple tupleOrigin = pc.getLeftTupleOrigin();
+ if ( tupleOrigin != null ) {
+ stream.writeBoolean( true );
+ stream.writeInt( tuples.get( tupleOrigin ) );
+ } else {
+ stream.writeBoolean( false );
+ }
+
+ stream.writeLong( pc.getPropagationNumber() );
+ if ( pc.getFactHandleOrigin() != null ) {
+ stream.writeInt( pc.getFactHandleOrigin().getId() );
+ } else {
+ stream.writeInt( -1 );
+ }
+
+ stream.writeInt( pc.getActiveActivations() );
+ stream.writeInt( pc.getDormantActivations() );
+
+ stream.writeUTF( pc.getEntryPoint().getEntryPointId() );
+ }
+
+}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputPersister.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputPersister.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputPersister.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -1,587 +0,0 @@
-package org.drools.marshalling;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.drools.InitialFact;
-import org.drools.base.ClassObjectType;
-import org.drools.base.ShadowProxy;
-import org.drools.common.AbstractFactHandleFactory;
-import org.drools.common.AgendaItem;
-import org.drools.common.BinaryHeapQueueAgendaGroup;
-import org.drools.common.DefaultAgenda;
-import org.drools.common.EqualityKey;
-import org.drools.common.InternalFactHandle;
-import org.drools.common.InternalRuleBase;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.common.LogicalDependency;
-import org.drools.common.ObjectStore;
-import org.drools.common.PropagationContextImpl;
-import org.drools.common.RuleFlowGroupImpl;
-import org.drools.common.WorkingMemoryAction;
-import org.drools.marshalling.Placeholders.PlaceholderEntry;
-import org.drools.reteoo.BetaMemory;
-import org.drools.reteoo.BetaNode;
-import org.drools.reteoo.EvalConditionNode;
-import org.drools.reteoo.ExistsNode;
-import org.drools.reteoo.JoinNode;
-import org.drools.reteoo.LeftInputAdapterNode;
-import org.drools.reteoo.LeftTuple;
-import org.drools.reteoo.LeftTupleSink;
-import org.drools.reteoo.NotNode;
-import org.drools.reteoo.ObjectTypeNode;
-import org.drools.reteoo.ReteooFactHandleFactory;
-import org.drools.reteoo.ReteooWorkingMemory;
-import org.drools.reteoo.RightTuple;
-import org.drools.reteoo.RightTupleSink;
-import org.drools.reteoo.RuleTerminalNode;
-import org.drools.reteoo.EvalConditionNode.EvalMemory;
-import org.drools.rule.EntryPoint;
-import org.drools.rule.Rule;
-import org.drools.spi.Activation;
-import org.drools.spi.ActivationGroup;
-import org.drools.spi.AgendaGroup;
-import org.drools.spi.FactHandleFactory;
-import org.drools.spi.PropagationContext;
-import org.drools.spi.RuleFlowGroup;
-import org.drools.util.ObjectHashMap;
-import org.drools.util.ObjectHashSet;
-import org.drools.util.ObjectHashSet.ObjectEntry;
-
-public class OutputPersister {
- public static void writeSession(WMSerialisationOutContext context) throws IOException {
- ReteooWorkingMemory wm = (ReteooWorkingMemory) context.wm;
-
- context.writeInt( wm.getFactHandleFactory().getId() );
- context.writeLong( wm.getFactHandleFactory().getRecency() );
- System.out.println( "FactHandleFactory int:" + wm.getFactHandleFactory().getId() + " long:" + wm.getFactHandleFactory().getRecency() );
-
- InternalFactHandle handle = context.wm.getInitialFactHandle();
- context.writeInt( handle.getId() );
- context.writeLong( handle.getRecency() );
- context.out.println( "InitialFact int:" + handle.getId() + " long:" + handle.getRecency() );
-
- context.writeLong( wm.getPropagationIdCounter() );
- System.out.println( "PropagationCounter long:" + wm.getPropagationIdCounter() );
-
- writeAgenda( context );
-
- writeFactHandles( context );
-
- writeActionQueue( context );
-
- if ( wm.getTruthMaintenanceSystem() != null ) {
- context.writeBoolean( true );
- writeTruthMaintenanceSystem( context );
- } else {
- context.writeBoolean( false );
- }
- }
-
- public static void writeAgenda(WMSerialisationOutContext context) throws IOException {
- InternalWorkingMemory wm = context.wm;
- DefaultAgenda agenda = (DefaultAgenda) wm.getAgenda();
-
- Map<String, ActivationGroup> activationGroups = agenda.getActivationGroupsMap();
-
- AgendaGroup[] agendaGroups = (AgendaGroup[]) agenda.getAgendaGroupsMap().values().toArray( new AgendaGroup[agenda.getAgendaGroupsMap().size()] );
- Arrays.sort( agendaGroups,
- AgendaGroupSorter.instance );
-
- for ( AgendaGroup group : agendaGroups ) {
- context.writeInt( PersisterEnums.AGENDA_GROUP );
- context.writeUTF( group.getName() );
- context.writeBoolean( group.isActive() );
- }
- context.writeInt( PersisterEnums.END );
-
- LinkedList<AgendaGroup> focusStack = agenda.getStackList();
- for ( Iterator<AgendaGroup> it = focusStack.iterator(); it.hasNext(); ) {
- AgendaGroup group = it.next();
- context.writeInt( PersisterEnums.AGENDA_GROUP );
- context.writeUTF( group.getName() );
- }
- context.writeInt( PersisterEnums.END );
-
- RuleFlowGroupImpl[] ruleFlowGroups = (RuleFlowGroupImpl[]) agenda.getRuleFlowGroupsMap().values().toArray( new RuleFlowGroupImpl[agenda.getRuleFlowGroupsMap().size()] );
- Arrays.sort( ruleFlowGroups,
- RuleFlowGroupSorter.instance );
-
- for ( RuleFlowGroupImpl group : ruleFlowGroups ) {
- context.writeInt( PersisterEnums.RULE_FLOW_GROUP );
- //group.write( context );
- context.writeUTF( group.getName() );
- context.writeBoolean( group.isActive() );
- context.writeBoolean( group.isAutoDeactivate() );
- }
- context.writeInt( PersisterEnums.END );
- }
-
- public static class AgendaGroupSorter
- implements
- Comparator<AgendaGroup> {
- public static final AgendaGroupSorter instance = new AgendaGroupSorter();
-
- public int compare(AgendaGroup group1,
- AgendaGroup group2) {
- return group1.getName().compareTo( group2.getName() );
- }
- }
-
- public static class RuleFlowGroupSorter
- implements
- Comparator<RuleFlowGroup> {
- public static final RuleFlowGroupSorter instance = new RuleFlowGroupSorter();
-
- public int compare(RuleFlowGroup group1,
- RuleFlowGroup group2) {
- return group1.getName().compareTo( group2.getName() );
- }
- }
-
- public static void writeActionQueue(WMSerialisationOutContext context) throws IOException {
- ReteooWorkingMemory wm = (ReteooWorkingMemory) context.wm;
-
- WorkingMemoryAction[] queue = wm.getActionQueue().toArray( new WorkingMemoryAction[wm.getActionQueue().size()] );
- for ( int i = queue.length - 1; i >= 0; i-- ) {
- context.writeInt( PersisterEnums.WORKING_MEMORY_ACTION );
- queue[i].write( context );
- }
- context.writeInt( PersisterEnums.END );
- }
-
- public static void writeTruthMaintenanceSystem(WMSerialisationOutContext context) throws IOException {
- ObjectOutputStream stream = context.stream;
-
- ObjectHashMap assertMap = context.wm.getTruthMaintenanceSystem().getAssertMap();
-
- EqualityKey[] keys = new EqualityKey[assertMap.size()];
- org.drools.util.Iterator it = assertMap.iterator();
- int i = 0;
- for ( org.drools.util.ObjectHashMap.ObjectEntry entry = (org.drools.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.util.ObjectHashMap.ObjectEntry) it.next() ) {
- EqualityKey key = (EqualityKey) entry.getKey();
- keys[i++] = key;
- }
-
- Arrays.sort( keys,
- EqualityKeySorter.instance );
-
- // write the assert map of Equality keys
- for ( EqualityKey key : keys ) {
- stream.writeInt( PersisterEnums.EQUALITY_KEY );
- stream.writeInt( key.getStatus() );
- InternalFactHandle handle = key.getFactHandle();
- stream.writeInt( handle.getId() );
- context.out.println( "EqualityKey int:" + key.getStatus() + " int:" + handle.getId() );
- if ( key.getOtherFactHandle() != null && !key.getOtherFactHandle().isEmpty() ) {
- for ( InternalFactHandle handle2 : key.getOtherFactHandle() ) {
- stream.writeInt( PersisterEnums.FACT_HANDLE );
- stream.writeInt( handle2.getId() );
- context.out.println( "OtherHandle int:" + handle2.getId() );
- }
- }
- stream.writeInt( PersisterEnums.END );
- }
- stream.writeInt( PersisterEnums.END );
- }
-
- public static class EqualityKeySorter
- implements
- Comparator<EqualityKey> {
- public static final EqualityKeySorter instance = new EqualityKeySorter();
-
- public int compare(EqualityKey key1,
- EqualityKey key2) {
- return key1.getFactHandle().getId() - key2.getFactHandle().getId();
- }
- }
-
- public static void writeFactHandles(WMSerialisationOutContext context) throws IOException {
- ObjectOutputStream stream = context.stream;
- InternalWorkingMemory wm = context.wm;
- PlaceholderResolverStrategyFactory resolverStrategyFactory = context.resolverStrategyFactory;
-
- writeInitialFactHandleRightTuples( context );
-
- stream.writeInt( wm.getObjectStore().size() );
-
- // Write out FactHandles
- for ( InternalFactHandle handle : orderFacts( wm.getObjectStore() ) ) {
- //stream.writeInt( PersisterEnums.FACT_HANDLE );
- //InternalFactHandle handle = (InternalFactHandle) it.next();
- stream.writeInt( handle.getId() );
- stream.writeLong( handle.getRecency() );
-
- context.out.println( "Object : int:" + handle.getId() + " long:" + handle.getRecency() );
- context.out.println( handle.getObject() );
-
- Object object = handle.getObject();
- if ( object instanceof ShadowProxy ) {
- object = ((ShadowProxy) object).getShadowedObject();
- }
-
- PlaceholderResolverStrategy strategy = resolverStrategyFactory.getStrategy( handle.getObject() );
-
- stream.writeInt( strategy.getIndex() );
-
- strategy.write( stream,
- object );
-
- writeRightTuples( handle,
- context );
- }
-
- writeInitialFactHandleLeftTuples( context );
-
- writeLeftTuples( context );
-
- writePropagationContexts( context );
-
- writeActivations( context );
- }
-
- public static InternalFactHandle[] orderFacts(ObjectStore objectStore) {
- // this method is just needed for testing purposes, to allow round tripping
- int size = objectStore.size();
- InternalFactHandle[] handles = new InternalFactHandle[size];
- int i = 0;
- for ( Iterator it = objectStore.iterateFactHandles(); it.hasNext(); ) {
- handles[i++] = (InternalFactHandle) it.next();
- }
-
- Arrays.sort( handles,
- new HandleSorter() );
-
- return handles;
- }
-
- public static class HandleSorter
- implements
- Comparator<InternalFactHandle> {
- public int compare(InternalFactHandle h1,
- InternalFactHandle h2) {
- return h1.getId() - h2.getId();
- }
- }
-
- public static void writeInitialFactHandleRightTuples(WMSerialisationOutContext context) throws IOException {
- ObjectOutputStream stream = context.stream;
- InternalRuleBase ruleBase = context.ruleBase;
-
- ObjectTypeNode initialFactNode = ruleBase.getRete().getEntryPointNode( EntryPoint.DEFAULT ).getObjectTypeNodes().get( new ClassObjectType( InitialFact.class ) );
-
- // do we write the fact to the objecttypenode memory
- if ( initialFactNode != null ) {
- ObjectHashSet initialFactMemory = (ObjectHashSet) context.wm.getNodeMemory( initialFactNode );
- if ( initialFactMemory != null && !initialFactMemory.isEmpty() ) {
- context.out.println( "InitialFactMemory true int:" + initialFactNode.getId() );
- stream.writeBoolean( true );
- stream.writeInt( initialFactNode.getId() );
-
- context.out.println( "InitialFact RightTuples" );
- writeRightTuples( context.wm.getInitialFactHandle(),
- context );
- } else {
- context.out.println( "InitialFactMemory false " );
- stream.writeBoolean( false );
- }
- } else {
- context.out.println( "InitialFactMemory false " );
- stream.writeBoolean( false );
- }
- }
-
- public static void writeInitialFactHandleLeftTuples(WMSerialisationOutContext context) throws IOException {
- ObjectOutputStream stream = context.stream;
-
- context.out.println( "InitialFact LeftTuples Start" );
- InternalFactHandle handle = context.wm.getInitialFactHandle();
- for ( LeftTuple leftTuple = getLeftTuple( handle.getLeftTuple() ); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
- stream.writeInt( PersisterEnums.LEFT_TUPLE );
-
- stream.writeInt( leftTuple.getLeftTupleSink().getId() );
- context.out.println( "LeftTuple int:" + leftTuple.getLeftTupleSink().getId() );
- writeLeftTuple( leftTuple,
- context );
- }
- stream.writeInt( PersisterEnums.END );
- context.out.println( "InitialFact LeftTuples End" );
- }
-
- public static void writeRightTuples(InternalFactHandle handle,
- WMSerialisationOutContext context) throws IOException {
- ObjectOutputStream stream = context.stream;
- context.out.println( "RightTuples Start" );
-
- RightTuple rightTuple = handle.getRightTuple();
- for ( RightTuple tempRightTuple = rightTuple; tempRightTuple != null; tempRightTuple = (RightTuple) tempRightTuple.getHandleNext() ) {
- rightTuple = tempRightTuple;
- }
- for ( ; rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandlePrevious() ) {
- stream.writeInt( PersisterEnums.RIGHT_TUPLE );
- writeRightTuple( rightTuple,
- context );
- }
- stream.writeInt( PersisterEnums.END );
- context.out.println( "RightTuples END" );
- }
-
- public static void writeRightTuple(RightTuple rightTuple,
- WMSerialisationOutContext context) throws IOException {
- ObjectOutputStream stream = context.stream;
- InternalWorkingMemory wm = context.wm;
- stream.writeInt( rightTuple.getRightTupleSink().getId() );
- context.out.println( "RightTuple int:" + rightTuple.getRightTupleSink().getId() );
- }
-
- public static void writeLeftTuples(WMSerialisationOutContext context) throws IOException {
- ObjectOutputStream stream = context.stream;
- InternalWorkingMemory wm = context.wm;
-
- // Write out LeftTuples
- context.out.println( "LeftTuples Start" );
- for ( InternalFactHandle handle : orderFacts( wm.getObjectStore() ) ) {
- //InternalFactHandle handle = (InternalFactHandle) it.next();
-
- for ( LeftTuple leftTuple = getLeftTuple( handle.getLeftTuple() ); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
- stream.writeInt( PersisterEnums.LEFT_TUPLE );
-
- stream.writeInt( leftTuple.getLeftTupleSink().getId() );
- stream.writeInt( handle.getId() );
-
- context.out.println( "LeftTuple int:" + leftTuple.getLeftTupleSink().getId() + " int:" + handle.getId() );
- writeLeftTuple( leftTuple,
- context );
- }
- }
- stream.writeInt( PersisterEnums.END );
- context.out.println( "LeftTuples End" );
- }
-
- public static void writeLeftTuple(LeftTuple leftTuple,
- WMSerialisationOutContext context) throws IOException {
- ObjectOutputStream stream = context.stream;
- InternalRuleBase ruleBase = context.ruleBase;
- InternalWorkingMemory wm = context.wm;
-
- LeftTupleSink sink = leftTuple.getLeftTupleSink();
-
- if ( sink instanceof JoinNode ) {
- context.out.println( "JoinNode" );
-
- for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.getBetaChildren() ); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentPrevious() ) {
- stream.writeInt( PersisterEnums.RIGHT_TUPLE );
- stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
- stream.writeInt( childLeftTuple.getRightParent().getFactHandle().getId() );
- context.out.println( "RightTuple int:" + childLeftTuple.getLeftTupleSink().getId() + " int:" + childLeftTuple.getRightParent().getFactHandle().getId() );
- writeLeftTuple( childLeftTuple,
- context );
- }
- stream.writeInt( PersisterEnums.END );
- } else if ( sink instanceof EvalConditionNode ) {
- context.out.println( "EvalConditionNode" );
- for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.getBetaChildren() ); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentPrevious() ) {
- stream.writeInt( PersisterEnums.LEFT_TUPLE );
- stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
- writeLeftTuple( childLeftTuple,
- context );
- }
- stream.writeInt( PersisterEnums.END );
- } else if ( sink instanceof NotNode ) {
- if ( leftTuple.getBlocker() == null ) {
- // is not blocked so has children
- stream.writeInt( PersisterEnums.LEFT_TUPLE_NOT_BLOCKED );
-
- for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.getBetaChildren() ); childLeftTuple != null; childLeftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
- stream.writeInt( PersisterEnums.LEFT_TUPLE );
- stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
- writeLeftTuple( childLeftTuple,
- context );
- }
- stream.writeInt( PersisterEnums.END );
-
- } else {
- stream.writeInt( PersisterEnums.LEFT_TUPLE_BLOCKED );
- stream.writeInt( leftTuple.getBlocker().getFactHandle().getId() );
- }
- } else if ( sink instanceof ExistsNode ) {
- if ( leftTuple.getBlocker() == null ) {
- // is blocked so has children
- stream.writeInt( PersisterEnums.LEFT_TUPLE_NOT_BLOCKED );
- } else {
- stream.writeInt( PersisterEnums.LEFT_TUPLE_BLOCKED );
- stream.writeInt( leftTuple.getBlocker().getFactHandle().getId() );
-
- for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.getBetaChildren() ); childLeftTuple != null; childLeftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
- stream.writeInt( PersisterEnums.LEFT_TUPLE );
- stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
- writeLeftTuple( childLeftTuple,
- context );
- }
- stream.writeInt( PersisterEnums.END );
- }
- } else if ( sink instanceof RuleTerminalNode ) {
- context.out.println( "RuleTerminalNode" );
- int pos = context.terminalTupleMap.size();
- context.terminalTupleMap.put( leftTuple,
- pos );
- }
- }
-
- public static LeftTuple getLeftTuple(LeftTuple leftTuple) {
- for ( LeftTuple tempLeftTuple = leftTuple; tempLeftTuple != null; tempLeftTuple = (LeftTuple) tempLeftTuple.getLeftParentNext() ) {
- leftTuple = tempLeftTuple;
- }
- return leftTuple;
- }
-
- public static void writeActivations(WMSerialisationOutContext context) throws IOException {
- ObjectOutputStream stream = context.stream;
-
- Entry<LeftTuple, Integer>[] entries = context.terminalTupleMap.entrySet().toArray( new Entry[ context.terminalTupleMap.size() ] );
- Arrays.sort( entries, TupleSorter.instance );
-
- //Map<LeftTuple, Integer> tuples = context.terminalTupleMap;
- if ( entries.length != 0 ) {
- for ( Entry<LeftTuple, Integer> entry : entries ) {
- LeftTuple leftTuple = entry.getKey();
- stream.writeInt( PersisterEnums.ACTIVATION );
- writeActivation( context,
- leftTuple,
- (AgendaItem) leftTuple.getActivation(),
- (RuleTerminalNode) leftTuple.getLeftTupleSink() );
- }
- }
- stream.writeInt( PersisterEnums.END );
- }
-
- public static class TupleSorter
- implements
- Comparator<Entry<LeftTuple, Integer>> {
- public static final TupleSorter instance = new TupleSorter();
- public int compare(Entry<LeftTuple, Integer> e1,
- Entry<LeftTuple, Integer> e2) {
- return e1.getValue() - e2.getValue();
- }
- }
-
- public static void writeActivation(WMSerialisationOutContext context,
- LeftTuple leftTuple,
- AgendaItem agendaItem,
- RuleTerminalNode ruleTerminalNode) throws IOException {
- ObjectOutputStream stream = context.stream;
-
- stream.writeLong( agendaItem.getActivationNumber() );
-
- stream.writeInt( context.terminalTupleMap.get( leftTuple ) );
-
- stream.writeInt( agendaItem.getSalience() );
-
- Rule rule = agendaItem.getRule();
- stream.writeUTF( rule.getPackage() );
- stream.writeUTF( rule.getName() );
-
- context.out.println( "Rule " + rule.getPackage() + "." + rule.getName() );
-
- context.out.println( "AgendaItem long:" + agendaItem.getPropagationContext().getPropagationNumber() );
- stream.writeLong( agendaItem.getPropagationContext().getPropagationNumber() );
-
- if ( agendaItem.getActivationGroupNode() != null ) {
- stream.writeBoolean( true );
- context.out.println( "ActivationGroup bool:" + true );
- stream.writeUTF( agendaItem.getActivationGroupNode().getActivationGroup().getName() );
- context.out.println( "ActivationGroup string:" + agendaItem.getActivationGroupNode().getActivationGroup().getName() );
- } else {
- stream.writeBoolean( false );
- context.out.println( "ActivationGroup bool:" + false );
- }
-
- stream.writeBoolean( agendaItem.isActivated() );
- context.out.println( "AgendaItem bool:" + agendaItem.isActivated() );
-
- org.drools.util.LinkedList list = agendaItem.getLogicalDependencies();
- if ( list != null && !list.isEmpty() ) {
- for ( LogicalDependency node = (LogicalDependency) list.getFirst(); node != null; node = (LogicalDependency) node.getNext() ) {
- stream.writeInt( PersisterEnums.LOGICAL_DEPENDENCY );
- stream.writeInt( ((InternalFactHandle) node.getFactHandle()).getId() );
- context.out.println( "Logical Depenency : int " + ((InternalFactHandle) node.getFactHandle()).getId() );
- }
- }
- stream.writeInt( PersisterEnums.END );
- }
-
- public static void writePropagationContexts(WMSerialisationOutContext context) throws IOException {
- ObjectOutputStream stream = context.stream;
-
- Entry<LeftTuple, Integer>[] entries = context.terminalTupleMap.entrySet().toArray( new Entry[ context.terminalTupleMap.size() ] );
- Arrays.sort( entries, TupleSorter.instance );
-
- //Map<LeftTuple, Integer> tuples = context.terminalTupleMap;
- if ( entries.length != 0 ) {
- Map<Long, PropagationContext> pcMap = new HashMap<Long, PropagationContext>();
- for ( Entry<LeftTuple, Integer> entry : entries ) {
- LeftTuple leftTuple = entry.getKey();
- PropagationContext pc = leftTuple.getActivation().getPropagationContext();
- if ( !pcMap.containsKey( pc.getPropagationNumber() ) ) {
- stream.writeInt( PersisterEnums.PROPAGATION_CONTEXT );
- writePropagationContext( context,
- pc );
- pcMap.put( pc.getPropagationNumber(),
- pc );
- }
- }
- }
-
- stream.writeInt( PersisterEnums.END );
- }
-
- public static void writePropagationContext(WMSerialisationOutContext context,
- PropagationContext pc) throws IOException {
- ObjectOutputStream stream = context.stream;
- Map<LeftTuple, Integer> tuples = context.terminalTupleMap;
-
- stream.writeInt( pc.getType() );
-
- Rule ruleOrigin = pc.getRuleOrigin();
- if ( ruleOrigin != null ) {
- stream.writeBoolean( true );
- stream.writeUTF( ruleOrigin.getPackage() );
- stream.writeUTF( ruleOrigin.getName() );
- } else {
- stream.writeBoolean( false );
- }
-
- LeftTuple tupleOrigin = pc.getLeftTupleOrigin();
- if ( tupleOrigin != null ) {
- stream.writeBoolean( true );
- stream.writeInt( tuples.get( tupleOrigin ) );
- } else {
- stream.writeBoolean( false );
- }
-
- stream.writeLong( pc.getPropagationNumber() );
- if ( pc.getFactHandleOrigin() != null ) {
- stream.writeInt( pc.getFactHandleOrigin().getId() );
- } else {
- stream.writeInt( -1 );
- }
-
- stream.writeInt( pc.getActiveActivations() );
- stream.writeInt( pc.getDormantActivations() );
-
- stream.writeUTF( pc.getEntryPoint().getEntryPointId() );
- }
-
-}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/PersisterHelper.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/PersisterHelper.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/PersisterHelper.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -12,7 +12,7 @@
import org.drools.common.TruthMaintenanceSystem;
public class PersisterHelper {
- public static WorkingMemoryAction readWorkingMemoryAction(WMSerialisationInContext context) throws IOException {
+ public static WorkingMemoryAction readWorkingMemoryAction(MarshallerReaderContext context) throws IOException {
int type = context.readInt();
switch(type) {
case WorkingMemoryAction.WorkingMemoryReteAssertAction : {
@@ -31,7 +31,7 @@
return null;
}
- public void write(WMSerialisationOutContext context) throws IOException {
+ public void write(MarshallerWriteContext context) throws IOException {
}
}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/WMSerialisationInContext.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/WMSerialisationInContext.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/WMSerialisationInContext.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -1,52 +0,0 @@
-/**
- *
- */
-package org.drools.marshalling;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.drools.common.BaseNode;
-import org.drools.common.InternalFactHandle;
-import org.drools.common.InternalRuleBase;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.reteoo.LeftTuple;
-import org.drools.reteoo.RightTuple;
-import org.drools.rule.EntryPoint;
-import org.drools.spi.PropagationContext;
-
-public class WMSerialisationInContext extends ObjectInputStream {
- public final WMSerialisationInContext stream;
- public final InternalRuleBase ruleBase;
- public InternalWorkingMemory wm;
- public final Map<Integer, BaseNode> sinks;
-
- public Map<Integer, InternalFactHandle> handles;
-
- public final Map<RightTupleKey, RightTuple> rightTuples;
- public final Map<Integer, LeftTuple> terminalTupleMap;
-
- public final PlaceholderResolverStrategyFactory resolverStrategyFactory;
- public final Map<String, EntryPoint> entryPoints;
-
- public final Map<Long, PropagationContext> propagationContexts;
-
- public WMSerialisationInContext(InputStream stream,
- InternalRuleBase ruleBase,
- Map<Integer, BaseNode> sinks,
- PlaceholderResolverStrategyFactory resolverStrategyFactory) throws IOException {
- super( stream );
- this.stream = this;
- this.ruleBase = ruleBase;
- this.sinks = sinks;
- this.handles = new HashMap<Integer, InternalFactHandle>();
- this.rightTuples = new HashMap<RightTupleKey, RightTuple>();
- this.terminalTupleMap = new HashMap<Integer, LeftTuple>();
- this.entryPoints = new HashMap<String, EntryPoint>();
- this.propagationContexts = new HashMap<Long, PropagationContext>();
- this.resolverStrategyFactory = resolverStrategyFactory;
- }
-}
\ No newline at end of file
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/WMSerialisationOutContext.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/WMSerialisationOutContext.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/WMSerialisationOutContext.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -1,50 +0,0 @@
-/**
- *
- */
-package org.drools.marshalling;
-
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-import java.util.Map;
-
-import org.drools.common.BaseNode;
-import org.drools.common.InternalRuleBase;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.reteoo.LeftTuple;
-
-public class WMSerialisationOutContext extends ObjectOutputStream {
- public final WMSerialisationOutContext stream;
- public final InternalRuleBase ruleBase;
- public final InternalWorkingMemory wm;
- public final Map<Integer, BaseNode> sinks;
-
- public final PrintStream out = System.out;
-
- public final PlaceholderResolverStrategyFactory resolverStrategyFactory;
-// public final Placeholders placeholders;
-
- public final Map<LeftTuple, Integer> terminalTupleMap;
-
- public WMSerialisationOutContext(OutputStream stream,
- InternalRuleBase ruleBase,
- InternalWorkingMemory wm,
- Map<Integer, BaseNode> sinks,
- PlaceholderResolverStrategyFactory resolverStrategyFactory) throws IOException {
- //Placeholders placeholders) {
- super( stream );
- this.stream = this;
- this.ruleBase = ruleBase;
- this.wm = wm;
- this.sinks = sinks;
-
- this.resolverStrategyFactory = resolverStrategyFactory;
-// this.placeholders = placeholders;
-
- this.terminalTupleMap = new IdentityHashMap<LeftTuple, Integer>();
- }
-}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -29,8 +29,8 @@
import org.drools.common.InternalWorkingMemory;
import org.drools.common.NodeMemory;
import org.drools.common.WorkingMemoryAction;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.reteoo.builder.BuildContext;
import org.drools.spi.PropagationContext;
@@ -421,11 +421,11 @@
this.node = node;
}
- public PropagateAction(WMSerialisationInContext context) throws IOException {
+ public PropagateAction(MarshallerReaderContext context) throws IOException {
this.node = ( PropagationQueuingNode ) context.sinks.get( context.readInt() );
}
- public void write(WMSerialisationOutContext context) throws IOException {
+ public void write(MarshallerWriteContext context) throws IOException {
context.write( node.getId() );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -28,8 +28,8 @@
import org.drools.common.EventFactHandle;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.rule.TypeDeclaration;
import org.drools.spi.FactHandleFactory;
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 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -41,14 +41,14 @@
import org.drools.concurrent.CommandExecutor;
import org.drools.concurrent.ExecutorService;
import org.drools.event.RuleBaseEventListener;
-import org.drools.marshalling.InputPersister;
+import org.drools.marshalling.InputMarshaller;
import org.drools.marshalling.Marshaller;
-import org.drools.marshalling.OutputPersister;
+import org.drools.marshalling.OutputMarshaller;
import org.drools.marshalling.PlaceholderResolverStrategyFactory;
import org.drools.marshalling.RuleBaseNodes;
import org.drools.marshalling.SerializablePlaceholderResolverStrategy;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.reteoo.ReteooWorkingMemory.WorkingMemoryReteAssertAction;
import org.drools.reteoo.builder.BuildContext;
import org.drools.rule.EntryPoint;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -18,8 +18,8 @@
import org.drools.concurrent.RetractObject;
import org.drools.concurrent.UpdateObject;
import org.drools.event.RuleBaseEventListener;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.spi.AgendaFilter;
import org.drools.spi.FactHandleFactory;
import org.drools.spi.RuleBaseUpdateListener;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooTemporalSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooTemporalSession.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooTemporalSession.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -24,8 +24,8 @@
import org.drools.TemporalSession;
import org.drools.common.InternalRuleBase;
import org.drools.concurrent.ExecutorService;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.temporal.SessionClock;
/**
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -37,10 +37,10 @@
import org.drools.common.PropagationContextImpl;
import org.drools.common.WorkingMemoryAction;
import org.drools.event.RuleBaseEventListener;
-import org.drools.marshalling.InputPersister;
-import org.drools.marshalling.OutputPersister;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.InputMarshaller;
+import org.drools.marshalling.OutputMarshaller;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.rule.EntryPoint;
import org.drools.rule.Package;
import org.drools.rule.Query;
@@ -201,7 +201,7 @@
this.leftTuple = leftTuple;
}
- public WorkingMemoryReteAssertAction(WMSerialisationInContext context) throws IOException {
+ public WorkingMemoryReteAssertAction(MarshallerReaderContext context) throws IOException {
this.factHandle = context.handles.get( context.readInt() );
this.removeLogical = context.readBoolean();
this.updateEqualsMap = context.readBoolean();
@@ -217,7 +217,7 @@
}
}
- public void write(WMSerialisationOutContext context) throws IOException {
+ public void write(MarshallerWriteContext context) throws IOException {
context.writeInt( WorkingMemoryAction.WorkingMemoryReteAssertAction );
context.writeInt( this.factHandle.getId() );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -22,8 +22,8 @@
import org.drools.FactHandle;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
-import org.drools.marshalling.WMSerialisationInContext;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.reteoo.ObjectTypeConf;
/**
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java 2008-05-18 03:33:07 UTC (rev 19999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java 2008-05-18 03:33:38 UTC (rev 20000)
@@ -28,7 +28,7 @@
import org.drools.common.DroolsObjectInputStream;
import org.drools.common.InternalWorkingMemory;
import org.drools.common.WorkingMemoryAction;
-import org.drools.marshalling.WMSerialisationOutContext;
+import org.drools.marshalling.MarshallerWriteContext;
import org.drools.reteoo.ReteooTemporalSession;
import org.drools.rule.Behavior;
@@ -204,7 +204,7 @@
return "ScheduledItem( timestamp="+timestamp+", behavior="+behavior+" )";
}
- public void write(WMSerialisationOutContext context) throws IOException {
+ public void write(MarshallerWriteContext context) throws IOException {
// TODO Auto-generated method stub
}
More information about the jboss-svn-commits
mailing list