[jboss-svn-commits] JBL Code SVN: r19181 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/reteoo/builder and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Mar 21 14:10:36 EDT 2008
Author: mark.proctor at jboss.com
Date: 2008-03-21 14:10:36 -0400 (Fri, 21 Mar 2008)
New Revision: 19181
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyObjectSinkAdapter.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSink.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSinkNodeList.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSinkPropagator.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTupleSinkNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleObjectSinkAdapter.java
Removed:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeRightTupleSinkAdapter.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleSinkAdapter.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyRightTupleSinkAdapter.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkNodeList.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkPropagator.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleRightTupleSinkAdapter.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactHandle.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LIANodePropagation.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSink.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkNodeList.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.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/QueryTerminalNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteStatelessSessionResult.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.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/ReteooStatelessSession.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/reteoo/RightInputAdapterNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleRemovalContext.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TerminalNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/BetaNodeTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSink.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSource.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectSourceTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java
Log:
JBRULES-1520 RightTuple merge for asynchronous Rete propagations
-mid refactor, bit of a mess, but wan't to be prepared in case eclipse refactoring screws up.
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -49,7 +49,7 @@
*/
public class AccumulateNode extends BetaNode {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
private boolean unwrapRightObject;
private Accumulate accumulate;
@@ -61,7 +61,7 @@
public AccumulateNode(final int id,
final LeftTupleSource leftInput,
- final RightTupleSource rightInput,
+ final ObjectSource rightInput,
final AlphaNodeFieldConstraint[] resultConstraints,
final BetaConstraints sourceBinder,
final BetaConstraints resultBinder,
@@ -79,22 +79,23 @@
this.tupleMemoryEnabled = context.isTupleMemoryEnabled();
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- unwrapRightObject = in.readBoolean();
- accumulate = (Accumulate)in.readObject();
- resultConstraints = (AlphaNodeFieldConstraint[])in.readObject();
- resultBinder = (BetaConstraints)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ unwrapRightObject = in.readBoolean();
+ accumulate = (Accumulate) in.readObject();
+ resultConstraints = (AlphaNodeFieldConstraint[]) in.readObject();
+ resultBinder = (BetaConstraints) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeBoolean(unwrapRightObject);
- out.writeObject(accumulate);
- out.writeObject(resultConstraints);
- out.writeObject(resultBinder);
+ super.writeExternal( out );
+ out.writeBoolean( unwrapRightObject );
+ out.writeObject( accumulate );
+ out.writeObject( resultConstraints );
+ out.writeObject( resultBinder );
}
-
+
/**
* @inheritDoc
*
@@ -115,8 +116,8 @@
*
*/
public void assertLeftTuple(final LeftTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final AccumulateMemory memory = (AccumulateMemory) workingMemory.getNodeMemory( this );
@@ -125,8 +126,8 @@
if ( this.tupleMemoryEnabled ) {
memory.betaMemory.getLeftTupleMemory().add( leftTuple );
memory.betaMemory.getCreatedHandles().put( leftTuple,
- accresult,
- false );
+ accresult,
+ false );
}
final Object accContext = this.accumulate.createContext();
@@ -172,13 +173,15 @@
leftTuple,
workingMemory );
- if( result == null ) {
- throw new RuntimeDroolsException("Accumulate must not return a null value.");
+ if ( result == null ) {
+ throw new RuntimeDroolsException( "Accumulate must not return a null value." );
}
// First alpha node filters
boolean isAllowed = true;
- final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result, false, workingMemory ); // so far, result is not an event
+ final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result,
+ false,
+ workingMemory ); // so far, result is not an event
for ( int i = 0, length = this.resultConstraints.length; i < length; i++ ) {
if ( !this.resultConstraints[i].isAllowed( handle,
@@ -197,9 +200,9 @@
accresult.handle = handle;
this.sink.propagateAssertLeftTuple( leftTuple,
- handle,
- context,
- workingMemory );
+ handle,
+ context,
+ workingMemory );
} else {
workingMemory.getFactHandleFactory().destroyFactHandle( handle );
}
@@ -217,10 +220,10 @@
*
*/
public void retractLeftTuple(final LeftTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final AccumulateMemory memory = (AccumulateMemory) workingMemory.getNodeMemory( this );
- if( memory.betaMemory.getLeftTupleMemory().remove( leftTuple ) == null) {
+ if ( memory.betaMemory.getLeftTupleMemory().remove( leftTuple ) == null ) {
return;
}
final AccumulateResult accresult = (AccumulateResult) memory.betaMemory.getCreatedHandles().remove( leftTuple );
@@ -228,9 +231,9 @@
// if tuple was propagated
if ( accresult.handle != null ) {
this.sink.propagateRetractLeftTuple( leftTuple,
- accresult.handle,
- context,
- workingMemory );
+ accresult.handle,
+ context,
+ workingMemory );
// Destroying the acumulate result object
workingMemory.getFactHandleFactory().destroyFactHandle( accresult.handle );
@@ -254,7 +257,7 @@
final AccumulateMemory memory = (AccumulateMemory) workingMemory.getNodeMemory( this );
memory.betaMemory.getRightTupleMemory().add( factHandle );
- if ( ! this.tupleMemoryEnabled ) {
+ if ( !this.tupleMemoryEnabled ) {
// do nothing here, as we know there are no left tuples at this stage in sequential mode.
return;
}
@@ -278,11 +281,11 @@
} else {
// context is MODIFICATION and does not supports reverse
this.retractLeftTuple( tuple,
- context,
- workingMemory );
+ context,
+ workingMemory );
this.assertLeftTuple( tuple,
- context,
- workingMemory );
+ context,
+ workingMemory );
}
}
}
@@ -321,11 +324,11 @@
workingMemory );
} else {
this.retractLeftTuple( tuple,
- context,
- workingMemory );
+ context,
+ workingMemory );
this.assertLeftTuple( tuple,
- context,
- workingMemory );
+ context,
+ workingMemory );
}
}
}
@@ -345,9 +348,9 @@
// if tuple was propagated
if ( accresult.handle != null ) {
this.sink.propagateRetractLeftTuple( leftTuple,
- accresult.handle,
- context,
- workingMemory );
+ accresult.handle,
+ context,
+ workingMemory );
// Destroying the acumulate result object
workingMemory.getFactHandleFactory().destroyFactHandle( accresult.handle );
@@ -379,9 +382,7 @@
tuple,
handle,
workingMemory );
- } else if ( context.getType() == PropagationContext.MODIFICATION ||
- context.getType() == PropagationContext.RULE_ADDITION ||
- context.getType() == PropagationContext.RULE_REMOVAL ) {
+ } else if ( context.getType() == PropagationContext.MODIFICATION || context.getType() == PropagationContext.RULE_ADDITION || context.getType() == PropagationContext.RULE_REMOVAL ) {
// modification
if ( isAssert ) {
this.accumulate.accumulate( memory.workingMemoryContext,
@@ -410,13 +411,15 @@
leftTuple,
workingMemory );
- if( result == null ) {
- throw new RuntimeDroolsException("Accumulate must not return a null value.");
+ if ( result == null ) {
+ throw new RuntimeDroolsException( "Accumulate must not return a null value." );
}
// First alpha node filters
boolean isAllowed = true;
- final InternalFactHandle createdHandle = workingMemory.getFactHandleFactory().newFactHandle( result, false, workingMemory ); // so far, result is not an event
+ final InternalFactHandle createdHandle = workingMemory.getFactHandleFactory().newFactHandle( result,
+ false,
+ workingMemory ); // so far, result is not an event
for ( int i = 0, length = this.resultConstraints.length; i < length; i++ ) {
if ( !this.resultConstraints[i].isAllowed( createdHandle,
workingMemory,
@@ -434,9 +437,9 @@
accresult.handle = createdHandle;
this.sink.propagateAssertLeftTuple( leftTuple,
- createdHandle,
- context,
- workingMemory );
+ createdHandle,
+ context,
+ workingMemory );
} else {
workingMemory.getFactHandleFactory().destroyFactHandle( createdHandle );
}
@@ -457,9 +460,9 @@
for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
AccumulateResult accresult = (AccumulateResult) entry.getValue();
sink.assertLeftTuple( new LeftTuple( (LeftTuple) entry.getKey(),
- accresult.handle ),
- context,
- workingMemory );
+ accresult.handle ),
+ context,
+ workingMemory );
}
}
@@ -511,43 +514,49 @@
return memory;
}
- public static class AccumulateMemory implements Externalizable {
+ public static class AccumulateMemory
+ implements
+ Externalizable {
private static final long serialVersionUID = 400L;
- public Object workingMemoryContext;
- public BetaMemory betaMemory;
- public ContextEntry[] resultsContext;
- public ContextEntry[] alphaContexts;
+ public Object workingMemoryContext;
+ public BetaMemory betaMemory;
+ public ContextEntry[] resultsContext;
+ public ContextEntry[] alphaContexts;
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- workingMemoryContext = in.readObject();
- betaMemory = (BetaMemory)in.readObject();
- resultsContext = (ContextEntry[])in.readObject();
- alphaContexts = (ContextEntry[])in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ workingMemoryContext = in.readObject();
+ betaMemory = (BetaMemory) in.readObject();
+ resultsContext = (ContextEntry[]) in.readObject();
+ alphaContexts = (ContextEntry[]) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(workingMemoryContext);
- out.writeObject(betaMemory);
- out.writeObject(resultsContext);
- out.writeObject(alphaContexts);
+ out.writeObject( workingMemoryContext );
+ out.writeObject( betaMemory );
+ out.writeObject( resultsContext );
+ out.writeObject( alphaContexts );
}
}
- public static class AccumulateResult implements Externalizable {
+ public static class AccumulateResult
+ implements
+ Externalizable {
// keeping attributes public just for performance
public InternalFactHandle handle;
public Object context;
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- handle = (InternalFactHandle)in.readObject();
- context = in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ handle = (InternalFactHandle) in.readObject();
+ context = in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(handle);
- out.writeObject(context);
+ out.writeObject( handle );
+ out.writeObject( context );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -46,9 +46,9 @@
* @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
*
*/
-public class AlphaNode extends RightTupleSource
+public class AlphaNode extends ObjectSource
implements
- RightTupleSinkNode,
+ ObjectTupleSinkNode,
NodeMemory {
/**
@@ -59,8 +59,8 @@
/** The <code>FieldConstraint</code> */
private AlphaNodeFieldConstraint constraint;
- private RightTupleSinkNode previousRightTupleSinkNode;
- private RightTupleSinkNode nextRightTupleSinkNode;
+ private ObjectTupleSinkNode previousRightTupleSinkNode;
+ private ObjectTupleSinkNode nextRightTupleSinkNode;
public AlphaNode() {
@@ -80,7 +80,7 @@
*/
public AlphaNode(final int id,
final AlphaNodeFieldConstraint constraint,
- final RightTupleSource objectSource,
+ final ObjectSource objectSource,
final BuildContext context) {
super( id,
objectSource,
@@ -92,8 +92,8 @@
ClassNotFoundException {
super.readExternal( in );
constraint = (AlphaNodeFieldConstraint) in.readObject();
- previousRightTupleSinkNode = (RightTupleSinkNode) in.readObject();
- nextRightTupleSinkNode = (RightTupleSinkNode) in.readObject();
+ previousRightTupleSinkNode = (ObjectTupleSinkNode) in.readObject();
+ nextRightTupleSinkNode = (ObjectTupleSinkNode) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
@@ -144,25 +144,19 @@
workingMemory,
memory.context ) ) {
- this.sink.propagateAssertFact( factHandle,
- context,
- workingMemory );
+ this.sink.propagateAssertObject( factHandle,
+ context,
+ workingMemory );
}
}
- public void retractRightTuple(RightTuple rightTuple,
- PropagationContext context,
- InternalWorkingMemory workingMemory) {
- throw new UnsupportedOperationException( "AlphaNode.retractRightTuple is not supported." );
- }
-
- public void updateSink(final RightTupleSink sink,
+ public void updateSink(final ObjectSink sink,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
AlphaMemory memory = (AlphaMemory) workingMemory.getNodeMemory( this );
// get the objects from the parent
- RightTupleSinkUpdateAdapter adapter = new RightTupleSinkUpdateAdapter( sink,
- this.constraint );
+ ObjectSinkUpdateAdapter adapter = new ObjectSinkUpdateAdapter( sink,
+ this.constraint );
this.source.updateSink( adapter,
context,
workingMemory );
@@ -173,7 +167,7 @@
final BaseNode node,
final InternalWorkingMemory[] workingMemories) {
if ( !node.isInUse() ) {
- removeObjectSink( (RightTupleSink) node );
+ removeObjectSink( (ObjectSink) node );
}
if ( !this.isInUse() ) {
for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
@@ -198,7 +192,7 @@
/**
* @inheritDoc
*/
- protected void addObjectSink(final RightTupleSink objectSink) {
+ protected void addObjectSink(final ObjectSink objectSink) {
super.addObjectSink( objectSink );
}
@@ -234,7 +228,7 @@
* @return
* The next ObjectSinkNode
*/
- public RightTupleSinkNode getNextRightTupleSinkNode() {
+ public ObjectTupleSinkNode getNextObjectSinkNode() {
return this.nextRightTupleSinkNode;
}
@@ -243,7 +237,7 @@
* @param next
* The next ObjectSinkNode
*/
- public void setNextRightTupleSinkNode(final RightTupleSinkNode next) {
+ public void setNextObjectSinkNode(final ObjectTupleSinkNode next) {
this.nextRightTupleSinkNode = next;
}
@@ -252,7 +246,7 @@
* @return
* The previous ObjectSinkNode
*/
- public RightTupleSinkNode getPreviousRightTupleSinkNode() {
+ public ObjectTupleSinkNode getPreviousObjectSinkNode() {
return this.previousRightTupleSinkNode;
}
@@ -261,7 +255,7 @@
* @param previous
* The previous ObjectSinkNode
*/
- public void setPreviousRightTupleSinkNode(final RightTupleSinkNode previous) {
+ public void setPreviousObjectSinkNode(final ObjectTupleSinkNode previous) {
this.previousRightTupleSinkNode = previous;
}
@@ -288,14 +282,14 @@
* @author mproctor
*
*/
- private static class RightTupleSinkUpdateAdapter
+ private static class ObjectSinkUpdateAdapter
implements
- RightTupleSink {
- private final RightTupleSink sink;
+ ObjectSink {
+ private final ObjectSink sink;
private final AlphaNodeFieldConstraint constraint;
- public RightTupleSinkUpdateAdapter(final RightTupleSink sink,
- final AlphaNodeFieldConstraint constraint) {
+ public ObjectSinkUpdateAdapter(final ObjectSink sink,
+ final AlphaNodeFieldConstraint constraint) {
this.sink = sink;
this.constraint = constraint;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -48,28 +48,29 @@
abstract class BetaNode extends LeftTupleSource
implements
LeftTupleSinkNode,
- RightTupleSinkNode,
+ ObjectTupleSinkNode,
+ RightTupleSink,
NodeMemory {
// ------------------------------------------------------------
// Instance members
// ------------------------------------------------------------
/** The left input <code>TupleSource</code>. */
- protected LeftTupleSource leftInput;
+ protected LeftTupleSource leftInput;
/** The right input <code>TupleSource</code>. */
- protected RightTupleSource rightInput;
+ protected ObjectSource rightInput;
- protected BetaConstraints constraints;
+ protected BetaConstraints constraints;
- private LeftTupleSinkNode previousTupleSinkNode;
- private LeftTupleSinkNode nextTupleSinkNode;
+ private LeftTupleSinkNode previousTupleSinkNode;
+ private LeftTupleSinkNode nextTupleSinkNode;
- private RightTupleSinkNode previousObjectSinkNode;
- private RightTupleSinkNode nextObjectSinkNode;
+ private ObjectTupleSinkNode previousObjectSinkNode;
+ private ObjectTupleSinkNode nextObjectSinkNode;
- protected boolean objectMemory = true; // hard coded to true
- protected boolean tupleMemoryEnabled;
+ protected boolean objectMemory = true; // hard coded to true
+ protected boolean tupleMemoryEnabled;
// ------------------------------------------------------------
// Constructors
@@ -88,7 +89,7 @@
*/
BetaNode(final int id,
final LeftTupleSource leftInput,
- final RightTupleSource rightInput,
+ final ObjectSource rightInput,
final BetaConstraints constraints) {
super( id );
this.leftInput = leftInput;
@@ -100,30 +101,31 @@
}
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- constraints = (BetaConstraints)in.readObject();
- leftInput = (LeftTupleSource)in.readObject();
- rightInput = (RightTupleSource)in.readObject();
- previousTupleSinkNode = (LeftTupleSinkNode)in.readObject();
- nextTupleSinkNode = (LeftTupleSinkNode)in.readObject();
- previousObjectSinkNode = (RightTupleSinkNode)in.readObject();
- nextObjectSinkNode = (RightTupleSinkNode)in.readObject();
- objectMemory = in.readBoolean();
- tupleMemoryEnabled = in.readBoolean();
- super.readExternal(in);
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ constraints = (BetaConstraints) in.readObject();
+ leftInput = (LeftTupleSource) in.readObject();
+ rightInput = (ObjectSource) in.readObject();
+ previousTupleSinkNode = (LeftTupleSinkNode) in.readObject();
+ nextTupleSinkNode = (LeftTupleSinkNode) in.readObject();
+ previousObjectSinkNode = (ObjectTupleSinkNode) in.readObject();
+ nextObjectSinkNode = (ObjectTupleSinkNode) in.readObject();
+ objectMemory = in.readBoolean();
+ tupleMemoryEnabled = in.readBoolean();
+ super.readExternal( in );
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(constraints);
- out.writeObject(leftInput);
- out.writeObject(rightInput);
- out.writeObject(previousTupleSinkNode);
- out.writeObject(nextTupleSinkNode);
- out.writeObject(previousObjectSinkNode);
- out.writeObject(nextObjectSinkNode);
- out.writeBoolean(objectMemory);
- out.writeBoolean(tupleMemoryEnabled);
- super.writeExternal(out);
+ out.writeObject( constraints );
+ out.writeObject( leftInput );
+ out.writeObject( rightInput );
+ out.writeObject( previousTupleSinkNode );
+ out.writeObject( nextTupleSinkNode );
+ out.writeObject( previousObjectSinkNode );
+ out.writeObject( nextObjectSinkNode );
+ out.writeBoolean( objectMemory );
+ out.writeBoolean( tupleMemoryEnabled );
+ super.writeExternal( out );
}
public BetaNodeFieldConstraint[] getConstraints() {
@@ -166,7 +168,7 @@
}
public ObjectTypeNode getObjectTypeNode() {
- RightTupleSource source = this.rightInput;
+ ObjectSource source = this.rightInput;
while ( !(source instanceof ObjectTypeNode) ) {
source = source.source;
}
@@ -209,7 +211,7 @@
builder,
this,
workingMemories );
- if( !context.alreadyVisited( this.leftInput )) {
+ if ( !context.alreadyVisited( this.leftInput ) ) {
this.leftInput.remove( context,
builder,
this,
@@ -271,7 +273,7 @@
* Creates a BetaMemory for the BetaNode's memory.
*/
public Object createMemory(final RuleBaseConfiguration config) {
- return this.constraints.createBetaMemory(config);
+ return this.constraints.createBetaMemory( config );
}
/**
@@ -315,7 +317,7 @@
* @return
* The next ObjectSinkNode
*/
- public RightTupleSinkNode getNextRightTupleSinkNode() {
+ public ObjectTupleSinkNode getNextObjectSinkNode() {
return this.nextObjectSinkNode;
}
@@ -324,7 +326,7 @@
* @param next
* The next ObjectSinkNode
*/
- public void setNextRightTupleSinkNode(final RightTupleSinkNode next) {
+ public void setNextObjectSinkNode(final ObjectTupleSinkNode next) {
this.nextObjectSinkNode = next;
}
@@ -333,7 +335,7 @@
* @return
* The previous ObjectSinkNode
*/
- public RightTupleSinkNode getPreviousRightTupleSinkNode() {
+ public ObjectTupleSinkNode getPreviousObjectSinkNode() {
return this.previousObjectSinkNode;
}
@@ -342,7 +344,7 @@
* @param previous
* The previous ObjectSinkNode
*/
- public void setPreviousRightTupleSinkNode(final RightTupleSinkNode previous) {
+ public void setPreviousObjectSinkNode(final ObjectTupleSinkNode previous) {
this.previousObjectSinkNode = previous;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -46,9 +46,9 @@
ObjectTypeConf,
Externalizable {
- private static final long serialVersionUID = 8218802585428841926L;
-
- private Class<?> cls;
+ private static final long serialVersionUID = 8218802585428841926L;
+
+ private Class< ? > cls;
private transient InternalRuleBase ruleBase;
private ObjectTypeNode[] objectTypeNodes;
@@ -64,13 +64,13 @@
}
public ClassObjectTypeConf(final EntryPoint entryPoint,
- final Class<?> clazz,
+ final Class< ? > clazz,
final InternalRuleBase ruleBase) {
this.cls = clazz;
this.ruleBase = ruleBase;
this.entryPoint = entryPoint;
TypeDeclaration type = ruleBase.getTypeDeclaration( clazz );
- final boolean isEvent = type != null && type.getRole() == TypeDeclaration.Role.EVENT;
+ final boolean isEvent = type != null && type.getRole() == TypeDeclaration.Role.EVENT;
ObjectType objectType = new ClassObjectType( clazz,
isEvent );
@@ -102,25 +102,25 @@
}
public void readExternal(ObjectInput stream) throws IOException,
- ClassNotFoundException {
- ruleBase = (InternalRuleBase)stream.readObject();
- cls = (Class)stream.readObject();
- objectTypeNodes = (ObjectTypeNode[])stream.readObject();
+ ClassNotFoundException {
+ ruleBase = (InternalRuleBase) stream.readObject();
+ cls = (Class) stream.readObject();
+ objectTypeNodes = (ObjectTypeNode[]) stream.readObject();
shadowEnabled = stream.readBoolean();
- shadowClass = (Class)stream.readObject();
- concreteObjectTypeNode = (ObjectTypeNode)stream.readObject();
- entryPoint = (EntryPoint)stream.readObject();
- defineShadowProxyData(cls);
+ shadowClass = (Class) stream.readObject();
+ concreteObjectTypeNode = (ObjectTypeNode) stream.readObject();
+ entryPoint = (EntryPoint) stream.readObject();
+ defineShadowProxyData( cls );
}
public void writeExternal(ObjectOutput stream) throws IOException {
- stream.writeObject(ruleBase);
- stream.writeObject(cls);
- stream.writeObject(objectTypeNodes);
- stream.writeBoolean(shadowEnabled);
- stream.writeObject(shadowClass);
- stream.writeObject(concreteObjectTypeNode);
- stream.writeObject(entryPoint);
+ stream.writeObject( ruleBase );
+ stream.writeObject( cls );
+ stream.writeObject( objectTypeNodes );
+ stream.writeBoolean( shadowEnabled );
+ stream.writeObject( shadowClass );
+ stream.writeObject( concreteObjectTypeNode );
+ stream.writeObject( entryPoint );
}
public boolean isAssignableFrom(Object object) {
@@ -178,7 +178,7 @@
* This will return the package name - if the package is null, it will
* work it out from the class name (this is in cases where funky classloading is used).
*/
- public static String getPackageName(Class<?> clazz,
+ public static String getPackageName(Class< ? > clazz,
Package pkg) {
String pkgName = "";
if ( pkg == null ) {
@@ -278,7 +278,7 @@
proxy.setShadowedObject( fact );
} catch ( final Exception e ) {
- System.out.println( "shadow: " +proxy.getClass() + ":" + fact.getClass() );
+ System.out.println( "shadow: " + proxy.getClass() + ":" + fact.getClass() );
throw new RuntimeDroolsException( "Error creating shadow fact for object: " + fact,
e );
}
@@ -305,7 +305,7 @@
private ObjectTypeNode[] getMatchingObjectTypes(final Class clazz) throws FactException {
final List<ObjectTypeNode> cache = new ArrayList<ObjectTypeNode>();
- for( ObjectTypeNode node : ruleBase.getRete().getObjectTypeNodes( this.entryPoint ).values() ) {
+ for ( ObjectTypeNode node : ruleBase.getRete().getObjectTypeNodes( this.entryPoint ).values() ) {
if ( node.isAssignableFrom( clazz ) ) {
cache.add( node );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -44,9 +44,9 @@
public class CollectNode extends BetaNode
implements
LeftTupleSink,
- RightTupleSink {
+ ObjectSink {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
private Collect collect;
private AlphaNodeFieldConstraint[] resultConstraints;
@@ -76,7 +76,7 @@
*/
public CollectNode(final int id,
final LeftTupleSource leftInput,
- final RightTupleSource rightInput,
+ final ObjectSource rightInput,
final AlphaNodeFieldConstraint[] resultConstraints,
final BetaConstraints sourceBinder,
final BetaConstraints resultsBinder,
@@ -94,21 +94,23 @@
this.tupleMemoryEnabled = context.isTupleMemoryEnabled();
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- collect = (Collect)in.readObject();
- resultConstraints = (AlphaNodeFieldConstraint[])in.readObject();
- resultsBinder = (BetaConstraints)in.readObject();
- unwrapRightObject = in.readBoolean();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ collect = (Collect) in.readObject();
+ resultConstraints = (AlphaNodeFieldConstraint[]) in.readObject();
+ resultsBinder = (BetaConstraints) in.readObject();
+ unwrapRightObject = in.readBoolean();
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeObject(collect);
- out.writeObject(resultConstraints);
- out.writeObject(resultsBinder);
- out.writeBoolean(unwrapRightObject);
+ super.writeExternal( out );
+ out.writeObject( collect );
+ out.writeObject( resultConstraints );
+ out.writeObject( resultsBinder );
+ out.writeBoolean( unwrapRightObject );
}
+
/**
* @inheritDoc
*
@@ -123,8 +125,8 @@
*
*/
public void assertLeftTuple(final LeftTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
@@ -167,7 +169,7 @@
for ( int i = 0, length = this.resultConstraints.length; i < length; i++ ) {
if ( !this.resultConstraints[i].isAllowed( resultHandle,
workingMemory,
- memory.alphaContexts[i]) ) {
+ memory.alphaContexts[i] ) ) {
isAllowed = false;
break;
}
@@ -180,9 +182,9 @@
resultHandle ) ) {
colresult.propagated = true;
this.sink.propagateAssertLeftTuple( leftTuple,
- resultHandle,
- context,
- workingMemory );
+ resultHandle,
+ context,
+ workingMemory );
}
this.resultsBinder.resetTuple( memory.resultsContext );
}
@@ -192,11 +194,11 @@
* @inheritDoc
*/
public void retractLeftTuple(final LeftTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
- if( memory.betaMemory.getLeftTupleMemory().remove( leftTuple ) == null ) {
+ if ( memory.betaMemory.getLeftTupleMemory().remove( leftTuple ) == null ) {
return;
}
CollectResult result = (CollectResult) memory.betaMemory.getCreatedHandles().remove( leftTuple );
@@ -206,9 +208,9 @@
if ( result.propagated ) {
this.sink.propagateRetractLeftTuple( leftTuple,
- handle,
- context,
- workingMemory );
+ handle,
+ context,
+ workingMemory );
// Destroying the acumulate result object
workingMemory.getFactHandleFactory().destroyFactHandle( handle );
@@ -316,9 +318,9 @@
// if tuple was propagated
if ( result.propagated ) {
this.sink.propagateRetractLeftTuple( leftTuple,
- result.handle,
- context,
- workingMemory );
+ result.handle,
+ context,
+ workingMemory );
result.propagated = false;
}
@@ -357,9 +359,9 @@
result.handle ) ) {
result.propagated = true;
this.sink.propagateAssertLeftTuple( leftTuple,
- result.handle,
- context,
- workingMemory );
+ result.handle,
+ context,
+ workingMemory );
}
this.resultsBinder.resetTuple( memory.resultsContext );
@@ -376,9 +378,9 @@
for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
CollectResult result = (CollectResult) entry.getValue();
sink.assertLeftTuple( new LeftTuple( (LeftTuple) entry.getKey(),
- result.handle ),
- context,
- workingMemory );
+ result.handle ),
+ context,
+ workingMemory );
}
}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -0,0 +1,193 @@
+package org.drools.reteoo;
+
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.spi.PropagationContext;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+public class CompositeLeftTupleSinkAdapter
+ implements
+ LeftTupleSinkPropagator {
+ private LeftTupleSinkNodeList sinks;
+
+ public CompositeLeftTupleSinkAdapter() {
+ this.sinks = new LeftTupleSinkNodeList();
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ sinks = (LeftTupleSinkNodeList) in.readObject();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject( sinks );
+ }
+
+ public void addTupleSink(final LeftTupleSink sink) {
+ this.sinks.add( (LeftTupleSinkNode) sink );
+ }
+
+ public void removeTupleSink(final LeftTupleSink sink) {
+ this.sinks.remove( (LeftTupleSinkNode) sink );
+ }
+
+ public void propagateAssertLeftTuple(final LeftTuple tuple,
+ final RightTuple rightTuple,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+
+ for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
+ sink.assertLeftTuple( new LeftTuple( tuple,
+ rightTuple,
+ sink ),
+ context,
+ workingMemory );
+ }
+ }
+
+ public void propagateAssertLeftTuple(final LeftTuple tuple,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+ for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
+ sink.assertLeftTuple( new LeftTuple( tuple,
+ sink ),
+ context,
+ workingMemory );
+ }
+ }
+
+ public void propagateRetractLeftTuple(final LeftTuple tuple,
+ final RightTuple rightTuple,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+ for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
+ sink.retractLeftTuple( new LeftTuple( tuple,
+ rightTuple,
+ sink ),
+ context,
+ workingMemory );
+ }
+ }
+
+ public void propagateRetractLeftTuple(final LeftTuple tuple,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+ for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
+ sink.retractLeftTuple( new LeftTuple( tuple,
+ sink ),
+ context,
+ workingMemory );
+ }
+ }
+
+ public void propagateRetractRightTuple(final RightTuple rightTuple,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+ LeftTuple child = rightTuple.getBetaChildren();
+ while ( child != null ) {
+ LeftTuple temp = child.getRightParentNext();
+ //child.unlinkFromParents();
+ child.getSink().retractLeftTuple( child,
+ context,
+ workingMemory );
+ child.unlinkFromLeftParent();
+ //child = child.getRightParentNext();
+ child = temp;
+ }
+ rightTuple.setBetaChildren( null );
+ }
+
+ public void createAndPropagateAssertLeftTuple(final InternalFactHandle factHandle,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+ for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
+ sink.assertLeftTuple( new LeftTuple( factHandle,
+ sink ),
+ context,
+ workingMemory );
+ }
+ }
+
+ public LeftTupleSink[] getSinks() {
+ final LeftTupleSink[] sinkArray = new LeftTupleSink[this.sinks.size()];
+
+ int i = 0;
+ for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
+ sinkArray[i++] = sink;
+ }
+
+ return sinkArray;
+ }
+
+ // public void propagateNewTupleSink(TupleMatch tupleMatch,
+ // PropagationContext context,
+ // InternalWorkingMemory workingMemory) {
+ //
+ // final TupleSink sink = sinks.getLast();
+ // final ReteTuple tuple = new ReteTuple( tupleMatch.getTuple(),
+ // tupleMatch.getObjectMatches().getFactHandle(),
+ // sink );
+ // tupleMatch.addJoinedTuple( tuple );
+ // tuple.assertTuple( context,
+ // workingMemory );
+ // }
+ //
+ // public void propagateNewTupleSink(ReteTuple tuple,
+ // PropagationContext context,
+ // InternalWorkingMemory workingMemory) {
+ //
+ // final TupleSink sink = sinks.getLast();
+ // ReteTuple child = new ReteTuple( tuple,
+ // sink );
+ // tuple.addChildEntry( child );
+ // child.assertTuple( context,
+ // workingMemory );
+ // }
+ //
+ // public void propagateNewTupleSink(InternalFactHandle handle,
+ // LinkedList list,
+ // PropagationContext context,
+ // InternalWorkingMemory workingMemory) {
+ // TupleSink sink = this.sinks.getLast();
+ // ReteTuple tuple = new ReteTuple( handle,
+ // sink );
+ // list.add( new LinkedListEntry( tuple ) );
+ // tuple.assertTuple( context,
+ // workingMemory );
+ // }
+ //
+ // /**
+ // * @inheritDoc
+ // */
+ // public List getPropagatedTuples(final Map memory,
+ // final InternalWorkingMemory workingMemory,
+ // final TupleSink sink) {
+ // int index = 0;
+ // for ( TupleSinkNode node = this.sinks.getFirst(); node != null; node = node.getNextTupleSinkNode() ) {
+ // if ( node.equals( sink ) ) {
+ // break;
+ // }
+ // index++;
+ // }
+ //
+ // final List propagatedTuples = new ArrayList( memory.size() );
+ //
+ // for ( final Iterator it = memory.values().iterator(); it.hasNext(); ) {
+ // final LinkedList tuples = (LinkedList) it.next();
+ // LinkedListEntry wrapper = (LinkedListEntry) tuples.getFirst();
+ // for ( int i = 0; i < index; i++ ) {
+ // wrapper = (LinkedListEntry) wrapper.getNext();
+ // }
+ // propagatedTuples.add( wrapper.getObject() );
+ // }
+ //
+ // return propagatedTuples;
+ // }
+
+ public int size() {
+ return this.sinks.size();
+ }
+}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java (from rev 19178, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeRightTupleSinkAdapter.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -0,0 +1,753 @@
+package org.drools.reteoo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Externalizable;
+
+import org.drools.base.ValueType;
+import org.drools.base.evaluators.Operator;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.LiteralConstraint;
+import org.drools.spi.AlphaNodeFieldConstraint;
+import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
+import org.drools.spi.FieldExtractor;
+import org.drools.spi.FieldValue;
+import org.drools.spi.PropagationContext;
+import org.drools.util.Iterator;
+import org.drools.util.LinkedList;
+import org.drools.util.LinkedListNode;
+import org.drools.util.ObjectHashMap;
+import org.drools.util.ObjectHashMap.ObjectEntry;
+
+public class CompositeObjectSinkAdapter
+ implements
+ ObjectSinkPropagator {
+
+ // /** You can override this property via a system property (eg -Ddrools.hashThreshold=4) */
+ // public static final String HASH_THRESHOLD_SYSTEM_PROPERTY = "drools.hashThreshold";
+ //
+ // /** The threshold for when hashing kicks in */
+ // public static final int THRESHOLD_TO_HASH = Integer.parseInt( System.getProperty( HASH_THRESHOLD_SYSTEM_PROPERTY,
+ // "3" ) );
+
+ private static final long serialVersionUID = 400L;
+ ObjectSinkNodeList otherSinks;
+ ObjectSinkNodeList hashableSinks;
+
+ LinkedList hashedFieldIndexes;
+
+ ObjectHashMap hashedSinkMap;
+
+ private int alphaNodeHashingThreshold;
+
+ public CompositeObjectSinkAdapter() {
+ this( 3 );
+ }
+
+ public CompositeObjectSinkAdapter(final int alphaNodeHashingThreshold) {
+ this.alphaNodeHashingThreshold = alphaNodeHashingThreshold;
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ otherSinks = (ObjectSinkNodeList) in.readObject();
+ hashableSinks = (ObjectSinkNodeList) in.readObject();
+ hashedFieldIndexes = (LinkedList) in.readObject();
+ hashedSinkMap = (ObjectHashMap) in.readObject();
+ alphaNodeHashingThreshold = in.readInt();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject( otherSinks );
+ out.writeObject( hashableSinks );
+ out.writeObject( hashedFieldIndexes );
+ out.writeObject( hashedSinkMap );
+ out.writeInt( alphaNodeHashingThreshold );
+ }
+
+ public void addObjectSink(final ObjectSink sink) {
+ if ( sink instanceof AlphaNode ) {
+ final AlphaNode alphaNode = (AlphaNode) sink;
+ final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
+
+ if ( fieldConstraint instanceof LiteralConstraint ) {
+ final LiteralConstraint literalConstraint = (LiteralConstraint) fieldConstraint;
+ final Evaluator evaluator = literalConstraint.getEvaluator();
+
+ if ( evaluator.getOperator() == Operator.EQUAL && literalConstraint.getFieldExtractor().getValueType() != ValueType.OBJECT_TYPE ) {
+ final int index = literalConstraint.getFieldExtractor().getIndex();
+ final FieldIndex fieldIndex = registerFieldIndex( index,
+ literalConstraint.getFieldExtractor() );
+
+ if ( fieldIndex.getCount() >= this.alphaNodeHashingThreshold && this.alphaNodeHashingThreshold != 0 ) {
+ if ( !fieldIndex.isHashed() ) {
+ hashSinks( fieldIndex );
+ }
+ final FieldValue value = literalConstraint.getField();
+ // no need to check, we know the sink does not exist
+ this.hashedSinkMap.put( new HashKey( index,
+ value,
+ fieldIndex.getFieldExtractor() ),
+ sink,
+ false );
+ } else {
+ if ( this.hashableSinks == null ) {
+ this.hashableSinks = new ObjectSinkNodeList();
+ }
+ this.hashableSinks.add( (ObjectTupleSinkNode) sink );
+ }
+ return;
+ }
+
+ }
+ }
+
+ if ( this.otherSinks == null ) {
+ this.otherSinks = new ObjectSinkNodeList();
+ }
+
+ this.otherSinks.add( (ObjectTupleSinkNode) sink );
+ }
+
+ public void removeObjectSink(final ObjectSink sink) {
+ if ( sink instanceof AlphaNode ) {
+ final AlphaNode alphaNode = (AlphaNode) sink;
+ final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
+
+ if ( fieldConstraint instanceof LiteralConstraint ) {
+ final LiteralConstraint literalConstraint = (LiteralConstraint) fieldConstraint;
+ final Evaluator evaluator = literalConstraint.getEvaluator();
+ final FieldValue value = literalConstraint.getField();
+
+ if ( evaluator.getOperator() == Operator.EQUAL && literalConstraint.getFieldExtractor().getValueType() != ValueType.OBJECT_TYPE ) {
+ final int index = literalConstraint.getFieldExtractor().getIndex();
+ final FieldIndex fieldIndex = unregisterFieldIndex( index );
+
+ if ( fieldIndex.isHashed() ) {
+ HashKey hashKey = new HashKey( index,
+ value,
+ fieldIndex.getFieldExtractor() );
+ this.hashedSinkMap.remove( hashKey );
+ if ( fieldIndex.getCount() <= this.alphaNodeHashingThreshold - 1 ) {
+ // we have less than three so unhash
+ unHashSinks( fieldIndex );
+ }
+ } else {
+ this.hashableSinks.remove( (ObjectTupleSinkNode) sink );
+ }
+
+ if ( this.hashableSinks != null && this.hashableSinks.isEmpty() ) {
+ this.hashableSinks = null;
+ }
+
+ return;
+ }
+ }
+ }
+
+ this.otherSinks.remove( (ObjectTupleSinkNode) sink );
+
+ if ( this.otherSinks.isEmpty() ) {
+ this.otherSinks = null;
+ }
+ }
+
+ public void hashSinks(final FieldIndex fieldIndex) {
+ final int index = fieldIndex.getIndex();
+
+ final List list = new ArrayList();
+
+ if ( this.hashedSinkMap == null ) {
+ this.hashedSinkMap = new ObjectHashMap();
+ }
+
+ for ( ObjectTupleSinkNode sink = this.hashableSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
+ final AlphaNode alphaNode = (AlphaNode) sink;
+ final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
+ final LiteralConstraint literalConstraint = (LiteralConstraint) fieldConstraint;
+ final Evaluator evaluator = literalConstraint.getEvaluator();
+ if ( evaluator.getOperator() == Operator.EQUAL && index == literalConstraint.getFieldExtractor().getIndex() ) {
+ final FieldValue value = literalConstraint.getField();
+ list.add( sink );
+ this.hashedSinkMap.put( new HashKey( index,
+ value,
+ fieldIndex.getFieldExtractor() ),
+ sink );
+ }
+ }
+
+ for ( final java.util.Iterator it = list.iterator(); it.hasNext(); ) {
+ final ObjectTupleSinkNode sink = (ObjectTupleSinkNode) it.next();
+ this.hashableSinks.remove( sink );
+ }
+
+ if ( this.hashableSinks.isEmpty() ) {
+ this.hashableSinks = null;
+ }
+
+ fieldIndex.setHashed( true );
+ }
+
+ public void unHashSinks(final FieldIndex fieldIndex) {
+ final int index = fieldIndex.getIndex();
+
+ final List sinks = new ArrayList();
+
+ //iterate twice as custom iterator is immutable
+ final Iterator mapIt = this.hashedSinkMap.newIterator();
+ for ( ObjectHashMap.ObjectEntry e = (ObjectHashMap.ObjectEntry) mapIt.next(); e != null; ) {
+
+ sinks.add( e.getValue() );
+ e = (ObjectHashMap.ObjectEntry) mapIt.next();
+ }
+
+ for ( final java.util.Iterator iter = sinks.iterator(); iter.hasNext(); ) {
+ final AlphaNode sink = (AlphaNode) iter.next();
+ final AlphaNode alphaNode = sink;
+ final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
+ final LiteralConstraint literalConstraint = (LiteralConstraint) fieldConstraint;
+ final Evaluator evaluator = literalConstraint.getEvaluator();
+ if ( evaluator.getOperator() == Operator.EQUAL && index == literalConstraint.getFieldExtractor().getIndex() ) {
+ final FieldValue value = literalConstraint.getField();
+ if ( this.hashableSinks == null ) {
+ this.hashableSinks = new ObjectSinkNodeList();
+ }
+ this.hashableSinks.add( sink );
+ this.hashedSinkMap.remove( new HashKey( index,
+ value,
+ fieldIndex.getFieldExtractor() ) );
+ };
+ }
+
+ if ( this.hashedSinkMap.isEmpty() ) {
+ this.hashedSinkMap = null;
+ }
+
+ fieldIndex.setHashed( false );
+ }
+
+ /**
+ * Returns a FieldIndex which Keeps a count on how many times a particular field is used with an equality check in the sinks.
+ * @param index
+ * @param fieldExtractor
+ * @return
+ */
+ private FieldIndex registerFieldIndex(final int index,
+ final FieldExtractor fieldExtractor) {
+ FieldIndex fieldIndex = null;
+
+ // is linkedlist null, if so create and add
+ if ( this.hashedFieldIndexes == null ) {
+ this.hashedFieldIndexes = new LinkedList();
+ fieldIndex = new FieldIndex( index,
+ fieldExtractor );
+ this.hashedFieldIndexes.add( fieldIndex );
+ }
+
+ // still null, so see if it already exists
+ if ( fieldIndex == null ) {
+ fieldIndex = findFieldIndex( index );
+ }
+
+ // doesn't exist so create it
+ if ( fieldIndex == null ) {
+ fieldIndex = new FieldIndex( index,
+ fieldExtractor );
+ this.hashedFieldIndexes.add( fieldIndex );
+ }
+
+ fieldIndex.increaseCounter();
+
+ return fieldIndex;
+ }
+
+ private FieldIndex unregisterFieldIndex(final int index) {
+ final FieldIndex fieldIndex = findFieldIndex( index );
+ fieldIndex.decreaseCounter();
+
+ // if the fieldcount is 0 then remove it from the linkedlist
+ if ( fieldIndex.getCount() == 0 ) {
+ this.hashedFieldIndexes.remove( fieldIndex );
+
+ // if the linkedlist is empty then null it
+ if ( this.hashedFieldIndexes.isEmpty() ) {
+ this.hashedFieldIndexes = null;
+ }
+ }
+
+ return fieldIndex;
+ }
+
+ private FieldIndex findFieldIndex(final int index) {
+ for ( FieldIndex node = (FieldIndex) this.hashedFieldIndexes.getFirst(); node != null; node = (FieldIndex) node.getNext() ) {
+ if ( node.getIndex() == index ) {
+ return node;
+ }
+ }
+
+ return null;
+ }
+
+ public void propagateAssertObject(final InternalFactHandle factHandle,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+ final Object object = factHandle.getObject();
+
+ // Iterates t he FieldIndex collection, which tells you if particularly field is hashed or not
+ // if the field is hashed then it builds the hashkey to return the correct sink for the current objects slot's
+ // value, one object may have multiple fields indexed.
+ if ( this.hashedFieldIndexes != null ) {
+ // Iterate the FieldIndexes to see if any are hashed
+ for ( FieldIndex fieldIndex = (FieldIndex) this.hashedFieldIndexes.getFirst(); fieldIndex != null; fieldIndex = (FieldIndex) fieldIndex.getNext() ) {
+ if ( !fieldIndex.isHashed() ) {
+ continue;
+ }
+ // this field is hashed so set the existing hashKey and see if there is a sink for it
+ final int index = fieldIndex.getIndex();
+ final FieldExtractor extractor = fieldIndex.getFieldExtactor();
+ HashKey hashKey = new HashKey( index,
+ object,
+ fieldIndex.getFieldExtractor() );
+ final ObjectSink sink = (ObjectSink) this.hashedSinkMap.get( hashKey );
+ if ( sink != null ) {
+ // The sink exists so propagate
+ sink.assertObject( factHandle,
+ context,
+ workingMemory );
+ }
+ }
+ }
+
+ // propagate unhashed
+ if ( this.hashableSinks != null ) {
+ for ( ObjectTupleSinkNode sink = this.hashableSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
+ sink.assertObject( factHandle,
+ context,
+ workingMemory );
+ }
+ }
+
+ if ( this.otherSinks != null ) {
+ // propagate others
+ for ( ObjectTupleSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
+ sink.assertObject( factHandle,
+ context,
+ workingMemory );
+ }
+ }
+
+ }
+
+ public ObjectSink[] getSinks() {
+ final List list = new ArrayList();
+
+ if ( this.otherSinks != null ) {
+ for ( ObjectTupleSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
+ list.add( sink );
+ }
+ }
+
+ if ( this.hashableSinks != null ) {
+ for ( ObjectTupleSinkNode sink = this.hashableSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
+ list.add( sink );
+ }
+ }
+
+ if ( this.hashedSinkMap != null ) {
+ final Iterator it = this.hashedSinkMap.newIterator();
+ for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
+ final ObjectSink sink = (ObjectSink) entry.getValue();
+ list.add( sink );
+ }
+ }
+
+ return (ObjectSink[]) list.toArray( new ObjectSink[list.size()] );
+ }
+
+ public int size() {
+ int size = 0;
+ size += ((this.otherSinks != null) ? this.otherSinks.size() : 0);
+ size += ((this.hashableSinks != null) ? this.hashableSinks.size() : 0);
+ size += ((this.hashedSinkMap != null) ? this.hashedSinkMap.size() : 0);
+ return size;
+ }
+
+ public static class HashKey
+ implements
+ Externalizable {
+ private static final long serialVersionUID = 400L;
+
+ private static final byte OBJECT = 1;
+ private static final byte LONG = 2;
+ private static final byte DOUBLE = 3;
+ private static final byte BOOL = 4;
+
+ private int index;
+
+ private byte type;
+ private Object ovalue;
+ private long lvalue;
+ private boolean bvalue;
+ private double dvalue;
+
+ private boolean isNull;
+
+ private int hashCode;
+
+ public HashKey() {
+ }
+
+ public HashKey(final int index,
+ final FieldValue value,
+ final Extractor extractor) {
+ this.setValue( index,
+ extractor,
+ value );
+ }
+
+ public HashKey(final int index,
+ final Object value,
+ final Extractor extractor) {
+ this.setValue( index,
+ value,
+ extractor );
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ index = in.readInt();
+ type = in.readByte();
+ ovalue = in.readObject();
+ lvalue = in.readLong();
+ bvalue = in.readBoolean();
+ dvalue = in.readDouble();
+ isNull = in.readBoolean();
+ hashCode = in.readInt();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeInt( index );
+ out.writeByte( type );
+ out.writeObject( ovalue );
+ out.writeLong( lvalue );
+ out.writeBoolean( bvalue );
+ out.writeDouble( dvalue );
+ out.writeBoolean( isNull );
+ out.writeInt( hashCode );
+ }
+
+ public int getIndex() {
+ return this.index;
+ }
+
+ public void setValue(final int index,
+ final Object value,
+ final Extractor extractor) {
+ this.index = index;
+ final ValueType vtype = extractor.getValueType();
+
+ isNull = extractor.isNullValue( null,
+ value );
+
+ if ( vtype.isBoolean() ) {
+ this.type = BOOL;
+ if ( !isNull ) {
+ this.bvalue = extractor.getBooleanValue( null,
+ value );
+ this.setHashCode( this.bvalue ? 1231 : 1237 );
+ } else {
+ this.setHashCode( 0 );
+ }
+ } else if ( vtype.isIntegerNumber() || vtype.isChar() ) {
+ this.type = LONG;
+ if ( !isNull ) {
+ this.lvalue = extractor.getLongValue( null,
+ value );
+ this.setHashCode( (int) (this.lvalue ^ (this.lvalue >>> 32)) );
+ } else {
+ this.setHashCode( 0 );
+ }
+ } else if ( vtype.isFloatNumber() ) {
+ this.type = DOUBLE;
+ if ( !isNull ) {
+ this.dvalue = extractor.getDoubleValue( null,
+ value );
+ final long temp = Double.doubleToLongBits( this.dvalue );
+ this.setHashCode( (int) (temp ^ (temp >>> 32)) );
+ } else {
+ this.setHashCode( 0 );
+ }
+ } else {
+ this.type = OBJECT;
+ if ( !isNull ) {
+ this.ovalue = extractor.getValue( null,
+ value );
+ this.setHashCode( this.ovalue != null ? this.ovalue.hashCode() : 0 );
+ } else {
+ this.setHashCode( 0 );
+ }
+ }
+ }
+
+ public void setValue(final int index,
+ final Extractor extractor,
+ final FieldValue value) {
+ this.index = index;
+
+ this.isNull = value.isNull();
+ final ValueType vtype = extractor.getValueType();
+
+ if ( vtype.isBoolean() ) {
+ this.type = BOOL;
+ if ( !isNull ) {
+ this.bvalue = value.getBooleanValue();
+ this.setHashCode( this.bvalue ? 1231 : 1237 );
+ } else {
+ this.setHashCode( 0 );
+ }
+ } else if ( vtype.isIntegerNumber() ) {
+ this.type = LONG;
+ if ( !isNull ) {
+ this.lvalue = value.getLongValue();
+ this.setHashCode( (int) (this.lvalue ^ (this.lvalue >>> 32)) );
+ } else {
+ this.setHashCode( 0 );
+ }
+ } else if ( vtype.isFloatNumber() ) {
+ this.type = DOUBLE;
+ if ( !isNull ) {
+ this.dvalue = value.getDoubleValue();
+ final long temp = Double.doubleToLongBits( this.dvalue );
+ this.setHashCode( (int) (temp ^ (temp >>> 32)) );
+ } else {
+ this.setHashCode( 0 );
+ }
+ } else {
+ this.type = OBJECT;
+ if ( !isNull ) {
+ this.ovalue = value.getValue();
+ this.setHashCode( this.ovalue != null ? this.ovalue.hashCode() : 0 );
+ } else {
+ this.setHashCode( 0 );
+ }
+ }
+ }
+
+ private void setHashCode(final int hashSeed) {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + hashSeed;
+ result = PRIME * result + this.index;
+ this.hashCode = result;
+ }
+
+ public boolean getBooleanValue() {
+ switch ( this.type ) {
+ case BOOL :
+ return this.bvalue;
+ case OBJECT :
+ if ( this.ovalue == null ) {
+ return false;
+ } else if ( this.ovalue instanceof Boolean ) {
+ return ((Boolean) this.ovalue).booleanValue();
+ } else if ( this.ovalue instanceof String ) {
+ return Boolean.valueOf( (String) this.ovalue ).booleanValue();
+ } else {
+ throw new ClassCastException( "Can't convert " + this.ovalue.getClass() + " to a boolean value." );
+ }
+ case LONG :
+ throw new ClassCastException( "Can't convert long to a boolean value." );
+ case DOUBLE :
+ throw new ClassCastException( "Can't convert double to a boolean value." );
+
+ }
+ return false;
+ }
+
+ public long getLongValue() {
+ switch ( this.type ) {
+ case BOOL :
+ return this.bvalue ? 1 : 0;
+ case OBJECT :
+ if ( this.ovalue == null ) {
+ return 0;
+ } else if ( this.ovalue instanceof Number ) {
+ return ((Number) this.ovalue).longValue();
+ } else if ( this.ovalue instanceof String ) {
+ return Long.parseLong( (String) this.ovalue );
+ } else {
+ throw new ClassCastException( "Can't convert " + this.ovalue.getClass() + " to a long value." );
+ }
+ case LONG :
+ return this.lvalue;
+ case DOUBLE :
+ return (long) this.dvalue;
+
+ }
+ return 0;
+ }
+
+ public double getDoubleValue() {
+ switch ( this.type ) {
+ case BOOL :
+ return this.bvalue ? 1 : 0;
+ case OBJECT :
+ if ( this.ovalue == null ) {
+ return 0;
+ } else if ( this.ovalue instanceof Number ) {
+ return ((Number) this.ovalue).doubleValue();
+ } else if ( this.ovalue instanceof String ) {
+ return Double.parseDouble( (String) this.ovalue );
+ } else {
+ throw new ClassCastException( "Can't convert " + this.ovalue.getClass() + " to a double value." );
+ }
+ case LONG :
+ return this.lvalue;
+ case DOUBLE :
+ return this.dvalue;
+ }
+ return 0;
+ }
+
+ public Object getObjectValue() {
+ switch ( this.type ) {
+ case BOOL :
+ return this.bvalue ? Boolean.TRUE : Boolean.FALSE;
+ case OBJECT :
+ return this.ovalue;
+ case LONG :
+ return new Long( this.lvalue );
+ case DOUBLE :
+ return new Double( this.dvalue );
+ }
+ return null;
+ }
+
+ public int hashCode() {
+ return this.hashCode;
+ }
+
+ public boolean equals(final Object object) {
+ final HashKey other = (HashKey) object;
+
+ if ( this.isNull ) {
+ return (other.isNull );
+ }
+
+ switch ( this.type ) {
+ case BOOL :
+ return (this.index == other.index) && (this.bvalue == other.getBooleanValue());
+ case LONG :
+ return (this.index == other.index) && (this.lvalue == other.getLongValue());
+ case DOUBLE :
+ return (this.index == other.index) && (this.dvalue == other.getDoubleValue());
+ case OBJECT :
+ final Object otherValue = other.getObjectValue();
+ if ( (this.ovalue != null) && (this.ovalue instanceof Number) && (otherValue instanceof Number) ) {
+ return (this.index == other.index) && (((Number) this.ovalue).doubleValue() == ((Number) otherValue).doubleValue());
+ }
+ return (this.index == other.index) && (this.ovalue == null ? otherValue == null : this.ovalue.equals( otherValue ));
+ }
+ return false;
+ }
+
+ }
+
+ public static class FieldIndex
+ implements
+ LinkedListNode {
+ private static final long serialVersionUID = 400L;
+ private int index;
+ private FieldExtractor fieldExtactor;
+
+ private int count;
+
+ private boolean hashed;
+
+ private LinkedListNode previous;
+ private LinkedListNode next;
+
+ public FieldIndex() {
+
+ }
+
+ public FieldIndex(final int index,
+ final FieldExtractor fieldExtractor) {
+ this.index = index;
+ this.fieldExtactor = fieldExtractor;
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ index = in.readInt();
+ fieldExtactor = (FieldExtractor) in.readObject();
+ count = in.readInt();
+ hashed = in.readBoolean();
+ previous = (LinkedListNode) in.readObject();
+ next = (LinkedListNode) in.readObject();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeInt( index );
+ out.writeObject( fieldExtactor );
+ out.writeInt( count );
+ out.writeBoolean( hashed );
+ out.writeObject( previous );
+ out.writeObject( next );
+ }
+
+ public FieldExtractor getFieldExtractor() {
+ return this.fieldExtactor;
+ }
+
+ public int getIndex() {
+ return this.index;
+ }
+
+ public int getCount() {
+ return this.count;
+ }
+
+ public FieldExtractor getFieldExtactor() {
+ return this.fieldExtactor;
+ }
+
+ public boolean isHashed() {
+ return this.hashed;
+ }
+
+ public void setHashed(final boolean hashed) {
+ this.hashed = hashed;
+ }
+
+ public void increaseCounter() {
+ this.count++;
+ }
+
+ public void decreaseCounter() {
+ this.count--;
+ }
+
+ public LinkedListNode getNext() {
+ return this.next;
+ }
+
+ public LinkedListNode getPrevious() {
+ return this.previous;
+ }
+
+ public void setNext(final LinkedListNode next) {
+ this.next = next;
+
+ }
+
+ public void setPrevious(final LinkedListNode previous) {
+ this.previous = previous;
+ }
+ }
+}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeRightTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeRightTupleSinkAdapter.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeRightTupleSinkAdapter.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -1,750 +0,0 @@
-package org.drools.reteoo;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.Externalizable;
-
-import org.drools.base.ValueType;
-import org.drools.base.evaluators.Operator;
-import org.drools.common.InternalFactHandle;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.LiteralConstraint;
-import org.drools.spi.AlphaNodeFieldConstraint;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldExtractor;
-import org.drools.spi.FieldValue;
-import org.drools.spi.PropagationContext;
-import org.drools.util.Iterator;
-import org.drools.util.LinkedList;
-import org.drools.util.LinkedListNode;
-import org.drools.util.ObjectHashMap;
-import org.drools.util.ObjectHashMap.ObjectEntry;
-
-public class CompositeRightTupleSinkAdapter
- implements
- RightTupleSinkPropagator {
-
- // /** You can override this property via a system property (eg -Ddrools.hashThreshold=4) */
- // public static final String HASH_THRESHOLD_SYSTEM_PROPERTY = "drools.hashThreshold";
- //
- // /** The threshold for when hashing kicks in */
- // public static final int THRESHOLD_TO_HASH = Integer.parseInt( System.getProperty( HASH_THRESHOLD_SYSTEM_PROPERTY,
- // "3" ) );
-
- private static final long serialVersionUID = 400L;
- RightTupleSinkNodeList otherSinks;
- RightTupleSinkNodeList hashableSinks;
-
- LinkedList hashedFieldIndexes;
-
- ObjectHashMap hashedSinkMap;
-
- private int alphaNodeHashingThreshold;
-
- public CompositeRightTupleSinkAdapter() {
- this( 3 );
- }
-
- public CompositeRightTupleSinkAdapter(final int alphaNodeHashingThreshold) {
- this.alphaNodeHashingThreshold = alphaNodeHashingThreshold;
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- otherSinks = (RightTupleSinkNodeList)in.readObject();
- hashableSinks = (RightTupleSinkNodeList)in.readObject();
- hashedFieldIndexes = (LinkedList)in.readObject();
- hashedSinkMap = (ObjectHashMap)in.readObject();
- alphaNodeHashingThreshold = in.readInt();
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(otherSinks);
- out.writeObject(hashableSinks);
- out.writeObject(hashedFieldIndexes);
- out.writeObject(hashedSinkMap);
- out.writeInt(alphaNodeHashingThreshold);
- }
-
- public void addObjectSink(final RightTupleSink sink) {
- if ( sink instanceof AlphaNode ) {
- final AlphaNode alphaNode = (AlphaNode) sink;
- final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
-
- if ( fieldConstraint instanceof LiteralConstraint ) {
- final LiteralConstraint literalConstraint = (LiteralConstraint) fieldConstraint;
- final Evaluator evaluator = literalConstraint.getEvaluator();
-
- if ( evaluator.getOperator() == Operator.EQUAL && literalConstraint.getFieldExtractor().getValueType() != ValueType.OBJECT_TYPE ) {
- final int index = literalConstraint.getFieldExtractor().getIndex();
- final FieldIndex fieldIndex = registerFieldIndex( index,
- literalConstraint.getFieldExtractor() );
-
- if ( fieldIndex.getCount() >= this.alphaNodeHashingThreshold && this.alphaNodeHashingThreshold != 0 ) {
- if ( !fieldIndex.isHashed() ) {
- hashSinks( fieldIndex );
- }
- final FieldValue value = literalConstraint.getField();
- // no need to check, we know the sink does not exist
- this.hashedSinkMap.put( new HashKey( index,
- value,
- fieldIndex.getFieldExtractor() ),
- sink,
- false );
- } else {
- if ( this.hashableSinks == null ) {
- this.hashableSinks = new RightTupleSinkNodeList();
- }
- this.hashableSinks.add( (RightTupleSinkNode) sink );
- }
- return;
- }
-
- }
- }
-
- if ( this.otherSinks == null ) {
- this.otherSinks = new RightTupleSinkNodeList();
- }
-
- this.otherSinks.add( (RightTupleSinkNode) sink );
- }
-
- public void removeObjectSink(final RightTupleSink sink) {
- if ( sink instanceof AlphaNode ) {
- final AlphaNode alphaNode = (AlphaNode) sink;
- final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
-
- if ( fieldConstraint instanceof LiteralConstraint ) {
- final LiteralConstraint literalConstraint = (LiteralConstraint) fieldConstraint;
- final Evaluator evaluator = literalConstraint.getEvaluator();
- final FieldValue value = literalConstraint.getField();
-
- if ( evaluator.getOperator() == Operator.EQUAL && literalConstraint.getFieldExtractor().getValueType() != ValueType.OBJECT_TYPE ) {
- final int index = literalConstraint.getFieldExtractor().getIndex();
- final FieldIndex fieldIndex = unregisterFieldIndex( index );
-
- if ( fieldIndex.isHashed() ) {
- HashKey hashKey = new HashKey( index,
- value,
- fieldIndex.getFieldExtractor() );
- this.hashedSinkMap.remove( hashKey );
- if ( fieldIndex.getCount() <= this.alphaNodeHashingThreshold - 1 ) {
- // we have less than three so unhash
- unHashSinks( fieldIndex );
- }
- } else {
- this.hashableSinks.remove( (RightTupleSinkNode) sink );
- }
-
- if ( this.hashableSinks != null && this.hashableSinks.isEmpty() ) {
- this.hashableSinks = null;
- }
-
- return;
- }
- }
- }
-
- this.otherSinks.remove( (RightTupleSinkNode) sink );
-
- if ( this.otherSinks.isEmpty() ) {
- this.otherSinks = null;
- }
- }
-
- public void hashSinks(final FieldIndex fieldIndex) {
- final int index = fieldIndex.getIndex();
-
- final List list = new ArrayList();
-
- if ( this.hashedSinkMap == null ) {
- this.hashedSinkMap = new ObjectHashMap();
- }
-
- for ( RightTupleSinkNode sink = this.hashableSinks.getFirst(); sink != null; sink = sink.getNextRightTupleSinkNode() ) {
- final AlphaNode alphaNode = (AlphaNode) sink;
- final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
- final LiteralConstraint literalConstraint = (LiteralConstraint) fieldConstraint;
- final Evaluator evaluator = literalConstraint.getEvaluator();
- if ( evaluator.getOperator() == Operator.EQUAL && index == literalConstraint.getFieldExtractor().getIndex() ) {
- final FieldValue value = literalConstraint.getField();
- list.add( sink );
- this.hashedSinkMap.put( new HashKey( index,
- value,
- fieldIndex.getFieldExtractor() ),
- sink );
- }
- }
-
- for ( final java.util.Iterator it = list.iterator(); it.hasNext(); ) {
- final RightTupleSinkNode sink = (RightTupleSinkNode) it.next();
- this.hashableSinks.remove( sink );
- }
-
- if ( this.hashableSinks.isEmpty() ) {
- this.hashableSinks = null;
- }
-
- fieldIndex.setHashed( true );
- }
-
- public void unHashSinks(final FieldIndex fieldIndex) {
- final int index = fieldIndex.getIndex();
-
- final List sinks = new ArrayList();
-
- //iterate twice as custom iterator is immutable
- final Iterator mapIt = this.hashedSinkMap.newIterator();
- for ( ObjectHashMap.ObjectEntry e = (ObjectHashMap.ObjectEntry) mapIt.next(); e != null; ) {
-
- sinks.add( e.getValue() );
- e = (ObjectHashMap.ObjectEntry) mapIt.next();
- }
-
- for ( final java.util.Iterator iter = sinks.iterator(); iter.hasNext(); ) {
- final AlphaNode sink = (AlphaNode) iter.next();
- final AlphaNode alphaNode = sink;
- final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
- final LiteralConstraint literalConstraint = (LiteralConstraint) fieldConstraint;
- final Evaluator evaluator = literalConstraint.getEvaluator();
- if ( evaluator.getOperator() == Operator.EQUAL && index == literalConstraint.getFieldExtractor().getIndex() ) {
- final FieldValue value = literalConstraint.getField();
- if ( this.hashableSinks == null ) {
- this.hashableSinks = new RightTupleSinkNodeList();
- }
- this.hashableSinks.add( sink );
- this.hashedSinkMap.remove( new HashKey( index,
- value,
- fieldIndex.getFieldExtractor() ) );
- };
- }
-
- if ( this.hashedSinkMap.isEmpty() ) {
- this.hashedSinkMap = null;
- }
-
- fieldIndex.setHashed( false );
- }
-
- /**
- * Returns a FieldIndex which Keeps a count on how many times a particular field is used with an equality check in the sinks.
- * @param index
- * @param fieldExtractor
- * @return
- */
- private FieldIndex registerFieldIndex(final int index,
- final FieldExtractor fieldExtractor) {
- FieldIndex fieldIndex = null;
-
- // is linkedlist null, if so create and add
- if ( this.hashedFieldIndexes == null ) {
- this.hashedFieldIndexes = new LinkedList();
- fieldIndex = new FieldIndex( index,
- fieldExtractor );
- this.hashedFieldIndexes.add( fieldIndex );
- }
-
- // still null, so see if it already exists
- if ( fieldIndex == null ) {
- fieldIndex = findFieldIndex( index );
- }
-
- // doesn't exist so create it
- if ( fieldIndex == null ) {
- fieldIndex = new FieldIndex( index,
- fieldExtractor );
- this.hashedFieldIndexes.add( fieldIndex );
- }
-
- fieldIndex.increaseCounter();
-
- return fieldIndex;
- }
-
- private FieldIndex unregisterFieldIndex(final int index) {
- final FieldIndex fieldIndex = findFieldIndex( index );
- fieldIndex.decreaseCounter();
-
- // if the fieldcount is 0 then remove it from the linkedlist
- if ( fieldIndex.getCount() == 0 ) {
- this.hashedFieldIndexes.remove( fieldIndex );
-
- // if the linkedlist is empty then null it
- if ( this.hashedFieldIndexes.isEmpty() ) {
- this.hashedFieldIndexes = null;
- }
- }
-
- return fieldIndex;
- }
-
- private FieldIndex findFieldIndex(final int index) {
- for ( FieldIndex node = (FieldIndex) this.hashedFieldIndexes.getFirst(); node != null; node = (FieldIndex) node.getNext() ) {
- if ( node.getIndex() == index ) {
- return node;
- }
- }
-
- return null;
- }
-
- public void propagateAssertFact(final InternalFactHandle factHandle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- final Object object = factHandle.getObject();
-
- // Iterates t he FieldIndex collection, which tells you if particularly field is hashed or not
- // if the field is hashed then it builds the hashkey to return the correct sink for the current objects slot's
- // value, one object may have multiple fields indexed.
- if ( this.hashedFieldIndexes != null ) {
- // Iterate the FieldIndexes to see if any are hashed
- for ( FieldIndex fieldIndex = (FieldIndex) this.hashedFieldIndexes.getFirst(); fieldIndex != null; fieldIndex = (FieldIndex) fieldIndex.getNext() ) {
- if ( !fieldIndex.isHashed() ) {
- continue;
- }
- // this field is hashed so set the existing hashKey and see if there is a sink for it
- final int index = fieldIndex.getIndex();
- final FieldExtractor extractor = fieldIndex.getFieldExtactor();
- HashKey hashKey = new HashKey( index,
- object,
- fieldIndex.getFieldExtractor() );
- final RightTupleSink sink = (RightTupleSink) this.hashedSinkMap.get( hashKey );
- if ( sink != null ) {
- // The sink exists so propagate
- sink.assertObject( factHandle,
- context,
- workingMemory );
- }
- }
- }
-
- // propagate unhashed
- if ( this.hashableSinks != null ) {
- for ( RightTupleSinkNode sink = this.hashableSinks.getFirst(); sink != null; sink = sink.getNextRightTupleSinkNode() ) {
- sink.assertObject( factHandle,
- context,
- workingMemory );
- }
- }
-
- if ( this.otherSinks != null ) {
- // propagate others
- for ( RightTupleSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextRightTupleSinkNode() ) {
- sink.assertObject( factHandle,
- context,
- workingMemory );
- }
- }
-
- }
-
- public RightTupleSink[] getSinks() {
- final List list = new ArrayList();
-
- if ( this.otherSinks != null ) {
- for ( RightTupleSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextRightTupleSinkNode() ) {
- list.add( sink );
- }
- }
-
- if ( this.hashableSinks != null ) {
- for ( RightTupleSinkNode sink = this.hashableSinks.getFirst(); sink != null; sink = sink.getNextRightTupleSinkNode() ) {
- list.add( sink );
- }
- }
-
- if ( this.hashedSinkMap != null ) {
- final Iterator it = this.hashedSinkMap.newIterator();
- for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
- final RightTupleSink sink = (RightTupleSink) entry.getValue();
- list.add( sink );
- }
- }
-
- return (RightTupleSink[]) list.toArray( new RightTupleSink[list.size()] );
- }
-
- public int size() {
- int size = 0;
- size += ((this.otherSinks != null) ? this.otherSinks.size() : 0);
- size += ((this.hashableSinks != null) ? this.hashableSinks.size() : 0);
- size += ((this.hashedSinkMap != null) ? this.hashedSinkMap.size() : 0);
- return size;
- }
-
- public static class HashKey
- implements
- Externalizable {
- private static final long serialVersionUID = 400L;
-
- private static final byte OBJECT = 1;
- private static final byte LONG = 2;
- private static final byte DOUBLE = 3;
- private static final byte BOOL = 4;
-
- private int index;
-
- private byte type;
- private Object ovalue;
- private long lvalue;
- private boolean bvalue;
- private double dvalue;
-
- private boolean isNull;
-
- private int hashCode;
-
- public HashKey() {
- }
-
- public HashKey(final int index,
- final FieldValue value,
- final Extractor extractor) {
- this.setValue( index,
- extractor,
- value );
- }
-
- public HashKey(final int index,
- final Object value,
- final Extractor extractor) {
- this.setValue( index,
- value,
- extractor );
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- index = in.readInt();
- type = in.readByte();
- ovalue = in.readObject();
- lvalue = in.readLong();
- bvalue = in.readBoolean();
- dvalue = in.readDouble();
- isNull = in.readBoolean();
- hashCode = in.readInt();
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(index);
- out.writeByte(type);
- out.writeObject(ovalue);
- out.writeLong(lvalue);
- out.writeBoolean(bvalue);
- out.writeDouble(dvalue);
- out.writeBoolean(isNull);
- out.writeInt(hashCode);
- }
-
- public int getIndex() {
- return this.index;
- }
-
- public void setValue(final int index,
- final Object value,
- final Extractor extractor) {
- this.index = index;
- final ValueType vtype = extractor.getValueType();
-
- isNull = extractor.isNullValue( null,
- value );
-
- if ( vtype.isBoolean() ) {
- this.type = BOOL;
- if ( !isNull ) {
- this.bvalue = extractor.getBooleanValue( null,
- value );
- this.setHashCode( this.bvalue ? 1231 : 1237 );
- } else {
- this.setHashCode( 0 );
- }
- } else if ( vtype.isIntegerNumber() || vtype.isChar() ) {
- this.type = LONG;
- if ( !isNull ) {
- this.lvalue = extractor.getLongValue( null,
- value );
- this.setHashCode( (int) (this.lvalue ^ (this.lvalue >>> 32)) );
- } else {
- this.setHashCode( 0 );
- }
- } else if ( vtype.isFloatNumber() ) {
- this.type = DOUBLE;
- if ( !isNull ) {
- this.dvalue = extractor.getDoubleValue( null,
- value );
- final long temp = Double.doubleToLongBits( this.dvalue );
- this.setHashCode( (int) (temp ^ (temp >>> 32)) );
- } else {
- this.setHashCode( 0 );
- }
- } else {
- this.type = OBJECT;
- if ( !isNull ) {
- this.ovalue = extractor.getValue( null,
- value );
- this.setHashCode( this.ovalue != null ? this.ovalue.hashCode() : 0 );
- } else {
- this.setHashCode( 0 );
- }
- }
- }
-
- public void setValue(final int index,
- final Extractor extractor,
- final FieldValue value) {
- this.index = index;
-
- this.isNull = value.isNull();
- final ValueType vtype = extractor.getValueType();
-
- if ( vtype.isBoolean() ) {
- this.type = BOOL;
- if ( !isNull ) {
- this.bvalue = value.getBooleanValue();
- this.setHashCode( this.bvalue ? 1231 : 1237 );
- } else {
- this.setHashCode( 0 );
- }
- } else if ( vtype.isIntegerNumber() ) {
- this.type = LONG;
- if ( !isNull ) {
- this.lvalue = value.getLongValue();
- this.setHashCode( (int) (this.lvalue ^ (this.lvalue >>> 32)) );
- } else {
- this.setHashCode( 0 );
- }
- } else if ( vtype.isFloatNumber() ) {
- this.type = DOUBLE;
- if ( !isNull ) {
- this.dvalue = value.getDoubleValue();
- final long temp = Double.doubleToLongBits( this.dvalue );
- this.setHashCode( (int) (temp ^ (temp >>> 32)) );
- } else {
- this.setHashCode( 0 );
- }
- } else {
- this.type = OBJECT;
- if ( !isNull ) {
- this.ovalue = value.getValue();
- this.setHashCode( this.ovalue != null ? this.ovalue.hashCode() : 0 );
- } else {
- this.setHashCode( 0 );
- }
- }
- }
-
- private void setHashCode(final int hashSeed) {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + hashSeed;
- result = PRIME * result + this.index;
- this.hashCode = result;
- }
-
- public boolean getBooleanValue() {
- switch ( this.type ) {
- case BOOL :
- return this.bvalue;
- case OBJECT :
- if ( this.ovalue == null ) {
- return false;
- } else if ( this.ovalue instanceof Boolean ) {
- return ((Boolean) this.ovalue).booleanValue();
- } else if ( this.ovalue instanceof String ) {
- return Boolean.valueOf( (String) this.ovalue ).booleanValue();
- } else {
- throw new ClassCastException( "Can't convert " + this.ovalue.getClass() + " to a boolean value." );
- }
- case LONG :
- throw new ClassCastException( "Can't convert long to a boolean value." );
- case DOUBLE :
- throw new ClassCastException( "Can't convert double to a boolean value." );
-
- }
- return false;
- }
-
- public long getLongValue() {
- switch ( this.type ) {
- case BOOL :
- return this.bvalue ? 1 : 0;
- case OBJECT :
- if ( this.ovalue == null ) {
- return 0;
- } else if ( this.ovalue instanceof Number ) {
- return ((Number) this.ovalue).longValue();
- } else if ( this.ovalue instanceof String ) {
- return Long.parseLong( (String) this.ovalue );
- } else {
- throw new ClassCastException( "Can't convert " + this.ovalue.getClass() + " to a long value." );
- }
- case LONG :
- return this.lvalue;
- case DOUBLE :
- return (long) this.dvalue;
-
- }
- return 0;
- }
-
- public double getDoubleValue() {
- switch ( this.type ) {
- case BOOL :
- return this.bvalue ? 1 : 0;
- case OBJECT :
- if ( this.ovalue == null ) {
- return 0;
- } else if ( this.ovalue instanceof Number ) {
- return ((Number) this.ovalue).doubleValue();
- } else if ( this.ovalue instanceof String ) {
- return Double.parseDouble( (String) this.ovalue );
- } else {
- throw new ClassCastException( "Can't convert " + this.ovalue.getClass() + " to a double value." );
- }
- case LONG :
- return this.lvalue;
- case DOUBLE :
- return this.dvalue;
- }
- return 0;
- }
-
- public Object getObjectValue() {
- switch ( this.type ) {
- case BOOL :
- return this.bvalue ? Boolean.TRUE : Boolean.FALSE;
- case OBJECT :
- return this.ovalue;
- case LONG :
- return new Long( this.lvalue );
- case DOUBLE :
- return new Double( this.dvalue );
- }
- return null;
- }
-
- public int hashCode() {
- return this.hashCode;
- }
-
- public boolean equals(final Object object) {
- final HashKey other = (HashKey) object;
-
- if ( this.isNull ) {
- return (other.isNull );
- }
-
- switch ( this.type ) {
- case BOOL :
- return (this.index == other.index) && (this.bvalue == other.getBooleanValue());
- case LONG :
- return (this.index == other.index) && (this.lvalue == other.getLongValue());
- case DOUBLE :
- return (this.index == other.index) && (this.dvalue == other.getDoubleValue());
- case OBJECT :
- final Object otherValue = other.getObjectValue();
- if ( (this.ovalue != null) && (this.ovalue instanceof Number) && (otherValue instanceof Number) ) {
- return (this.index == other.index) && (((Number) this.ovalue).doubleValue() == ((Number) otherValue).doubleValue());
- }
- return (this.index == other.index) && (this.ovalue == null ? otherValue == null : this.ovalue.equals( otherValue ));
- }
- return false;
- }
-
- }
-
- public static class FieldIndex
- implements
- LinkedListNode {
- private static final long serialVersionUID = 400L;
- private int index;
- private FieldExtractor fieldExtactor;
-
- private int count;
-
- private boolean hashed;
-
- private LinkedListNode previous;
- private LinkedListNode next;
-
- public FieldIndex() {
-
- }
-
- public FieldIndex(final int index,
- final FieldExtractor fieldExtractor) {
- this.index = index;
- this.fieldExtactor = fieldExtractor;
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- index = in.readInt();
- fieldExtactor = (FieldExtractor)in.readObject();
- count = in.readInt();
- hashed = in.readBoolean();
- previous = (LinkedListNode)in.readObject();
- next = (LinkedListNode)in.readObject();
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(index);
- out.writeObject(fieldExtactor);
- out.writeInt(count);
- out.writeBoolean(hashed);
- out.writeObject(previous);
- out.writeObject(next);
- }
-
- public FieldExtractor getFieldExtractor() {
- return this.fieldExtactor;
- }
-
- public int getIndex() {
- return this.index;
- }
-
- public int getCount() {
- return this.count;
- }
-
- public FieldExtractor getFieldExtactor() {
- return this.fieldExtactor;
- }
-
- public boolean isHashed() {
- return this.hashed;
- }
-
- public void setHashed(final boolean hashed) {
- this.hashed = hashed;
- }
-
- public void increaseCounter() {
- this.count++;
- }
-
- public void decreaseCounter() {
- this.count--;
- }
-
- public LinkedListNode getNext() {
- return this.next;
- }
-
- public LinkedListNode getPrevious() {
- return this.previous;
- }
-
- public void setNext(final LinkedListNode next) {
- this.next = next;
-
- }
-
- public void setPrevious(final LinkedListNode previous) {
- this.previous = previous;
- }
- }
-}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleSinkAdapter.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleSinkAdapter.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -1,193 +0,0 @@
-package org.drools.reteoo;
-
-import org.drools.common.InternalFactHandle;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.spi.PropagationContext;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-
-public class CompositeTupleSinkAdapter
- implements
- LeftTupleSinkPropagator {
- private LeftTupleSinkNodeList sinks;
-
- public CompositeTupleSinkAdapter() {
- this.sinks = new LeftTupleSinkNodeList();
- }
-
- public void readExternal(ObjectInput in) throws IOException,
- ClassNotFoundException {
- sinks = (LeftTupleSinkNodeList) in.readObject();
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject( sinks );
- }
-
- public void addTupleSink(final LeftTupleSink sink) {
- this.sinks.add( (LeftTupleSinkNode) sink );
- }
-
- public void removeTupleSink(final LeftTupleSink sink) {
- this.sinks.remove( (LeftTupleSinkNode) sink );
- }
-
- public void propagateAssertLeftTuple(final LeftTuple tuple,
- final RightTuple rightTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
-
- for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
- sink.assertLeftTuple( new LeftTuple( tuple,
- rightTuple,
- sink ),
- context,
- workingMemory );
- }
- }
-
- public void propagateAssertLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
- sink.assertLeftTuple( new LeftTuple( tuple,
- sink ),
- context,
- workingMemory );
- }
- }
-
- public void propagateRetractLeftTuple(final LeftTuple tuple,
- final RightTuple rightTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
- sink.retractLeftTuple( new LeftTuple( tuple,
- rightTuple,
- sink ),
- context,
- workingMemory );
- }
- }
-
- public void propagateRetractLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
- sink.retractLeftTuple( new LeftTuple( tuple,
- sink ),
- context,
- workingMemory );
- }
- }
-
- public void propagateRetractRightTuple(final RightTuple rightTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- LeftTuple child = rightTuple.getBetaChildren();
- while ( child != null ) {
- LeftTuple temp = child.getRightParentNext();
- //child.unlinkFromParents();
- child.getSink().retractLeftTuple( child,
- context,
- workingMemory );
- child.unlinkFromLeftParent();
- //child = child.getRightParentNext();
- child = temp;
- }
- rightTuple.setBetaChildren( null );
- }
-
- public void createAndPropagateAssertLeftTuple(final InternalFactHandle factHandle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
- sink.assertLeftTuple( new LeftTuple( factHandle,
- sink ),
- context,
- workingMemory );
- }
- }
-
- public LeftTupleSink[] getSinks() {
- final LeftTupleSink[] sinkArray = new LeftTupleSink[this.sinks.size()];
-
- int i = 0;
- for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
- sinkArray[i++] = sink;
- }
-
- return sinkArray;
- }
-
- // public void propagateNewTupleSink(TupleMatch tupleMatch,
- // PropagationContext context,
- // InternalWorkingMemory workingMemory) {
- //
- // final TupleSink sink = sinks.getLast();
- // final ReteTuple tuple = new ReteTuple( tupleMatch.getTuple(),
- // tupleMatch.getObjectMatches().getFactHandle(),
- // sink );
- // tupleMatch.addJoinedTuple( tuple );
- // tuple.assertTuple( context,
- // workingMemory );
- // }
- //
- // public void propagateNewTupleSink(ReteTuple tuple,
- // PropagationContext context,
- // InternalWorkingMemory workingMemory) {
- //
- // final TupleSink sink = sinks.getLast();
- // ReteTuple child = new ReteTuple( tuple,
- // sink );
- // tuple.addChildEntry( child );
- // child.assertTuple( context,
- // workingMemory );
- // }
- //
- // public void propagateNewTupleSink(InternalFactHandle handle,
- // LinkedList list,
- // PropagationContext context,
- // InternalWorkingMemory workingMemory) {
- // TupleSink sink = this.sinks.getLast();
- // ReteTuple tuple = new ReteTuple( handle,
- // sink );
- // list.add( new LinkedListEntry( tuple ) );
- // tuple.assertTuple( context,
- // workingMemory );
- // }
- //
- // /**
- // * @inheritDoc
- // */
- // public List getPropagatedTuples(final Map memory,
- // final InternalWorkingMemory workingMemory,
- // final TupleSink sink) {
- // int index = 0;
- // for ( TupleSinkNode node = this.sinks.getFirst(); node != null; node = node.getNextTupleSinkNode() ) {
- // if ( node.equals( sink ) ) {
- // break;
- // }
- // index++;
- // }
- //
- // final List propagatedTuples = new ArrayList( memory.size() );
- //
- // for ( final Iterator it = memory.values().iterator(); it.hasNext(); ) {
- // final LinkedList tuples = (LinkedList) it.next();
- // LinkedListEntry wrapper = (LinkedListEntry) tuples.getFirst();
- // for ( int i = 0; i < index; i++ ) {
- // wrapper = (LinkedListEntry) wrapper.getNext();
- // }
- // propagatedTuples.add( wrapper.getObject() );
- // }
- //
- // return propagatedTuples;
- // }
-
- public int size() {
- return this.sinks.size();
- }
-}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -22,26 +22,26 @@
}
public void propagateAssertLeftTuple(final LeftTuple leftTuple,
- final RightTuple rightTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final RightTuple rightTuple,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
}
public void propagateAssertLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
}
public void propagateRetractLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
}
public void createAndPropagateAssertLeftTuple(final InternalFactHandle factHandle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
}
-
+
public void propagateRetractRightTuple(RightTuple tuple,
PropagationContext context,
InternalWorkingMemory workingMemory) {
@@ -53,7 +53,6 @@
public void writeExternal(ObjectOutput out) throws IOException {
}
-
public LeftTupleSink[] getSinks() {
return new LeftTupleSink[]{};
@@ -62,6 +61,5 @@
public int size() {
return 0;
}
-
}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyObjectSinkAdapter.java (from rev 19178, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyRightTupleSinkAdapter.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyObjectSinkAdapter.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyObjectSinkAdapter.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -0,0 +1,59 @@
+package org.drools.reteoo;
+
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.spi.PropagationContext;
+
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+
+public class EmptyObjectSinkAdapter
+ implements
+ ObjectSinkPropagator {
+
+ private static final long serialVersionUID = -631743913176779720L;
+
+ private static final EmptyObjectSinkAdapter instance = new EmptyObjectSinkAdapter();
+
+ private static final ObjectSink[] SINK_LIST = new ObjectSink[0];
+
+ public static EmptyObjectSinkAdapter getInstance() {
+ return instance;
+ }
+
+ public EmptyObjectSinkAdapter() {
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ }
+
+ public void propagateAssertObject(final InternalFactHandle factHandle,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+
+ }
+
+ public void propagateRetractObject(final InternalFactHandle handle,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory,
+ final boolean useHash) {
+ }
+
+ public ObjectSink[] getSinks() {
+ return SINK_LIST;
+ }
+
+ public int size() {
+ return 0;
+ }
+
+ public boolean equals(Object obj) {
+ return obj instanceof EmptyObjectSinkAdapter;
+ }
+
+}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyRightTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyRightTupleSinkAdapter.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyRightTupleSinkAdapter.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -1,58 +0,0 @@
-package org.drools.reteoo;
-
-import org.drools.common.InternalFactHandle;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.spi.PropagationContext;
-
-import java.io.ObjectOutput;
-import java.io.IOException;
-import java.io.ObjectInput;
-
-public class EmptyRightTupleSinkAdapter
- implements
- RightTupleSinkPropagator {
-
- private static final long serialVersionUID = -631743913176779720L;
-
- private static final EmptyRightTupleSinkAdapter instance = new EmptyRightTupleSinkAdapter();
-
- private static final RightTupleSink[] SINK_LIST = new RightTupleSink[0];
-
- public static EmptyRightTupleSinkAdapter getInstance() {
- return instance;
- }
-
- public EmptyRightTupleSinkAdapter() {
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- }
-
- public void propagateAssertFact(final InternalFactHandle factHandle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
-
- }
-
- public void propagateRetractObject(final InternalFactHandle handle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory,
- final boolean useHash) {
- }
-
- public RightTupleSink[] getSinks() {
- return SINK_LIST;
- }
-
- public int size() {
- return 0;
- }
-
- public boolean equals(Object obj) {
- return obj instanceof EmptyRightTupleSinkAdapter;
- }
-
-}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -54,20 +54,20 @@
*
* @author <a href="mailto:tirelli at post.com">Edson Tirelli</a>
*/
-public class EntryPointNode extends RightTupleSource
+public class EntryPointNode extends ObjectSource
implements
Externalizable,
- RightTupleSink {
+ ObjectSink {
// ------------------------------------------------------------
// Instance members
// ------------------------------------------------------------
- private static final long serialVersionUID = 420L;
+ private static final long serialVersionUID = 420L;
/**
* The entry point ID for this node
*/
- private EntryPoint entryPoint;
+ private EntryPoint entryPoint;
/**
* The object type nodes under this node
@@ -82,7 +82,7 @@
}
public EntryPointNode(final int id,
- final RightTupleSource objectSource,
+ final ObjectSource objectSource,
final BuildContext context) {
this( id,
objectSource,
@@ -90,7 +90,7 @@
}
public EntryPointNode(final int id,
- final RightTupleSource objectSource,
+ final ObjectSource objectSource,
final EntryPoint entryPoint) {
super( id,
objectSource,
@@ -103,24 +103,26 @@
// Instance methods
// ------------------------------------------------------------
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- entryPoint = (EntryPoint)in.readObject();
- objectTypeNodes = (Map<ObjectType, ObjectTypeNode>)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ entryPoint = (EntryPoint) in.readObject();
+ objectTypeNodes = (Map<ObjectType, ObjectTypeNode>) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeObject(entryPoint);
- out.writeObject(objectTypeNodes);
+ super.writeExternal( out );
+ out.writeObject( entryPoint );
+ out.writeObject( objectTypeNodes );
}
+
/**
* @return the entryPoint
*/
public EntryPoint getEntryPoint() {
return entryPoint;
}
-
+
public void assertObject(final InternalFactHandle handle,
final PropagationContext context,
final ObjectTypeConf objectTypeConf,
@@ -144,7 +146,7 @@
context,
workingMemory );
}
- }
+ }
/**
* This is the entry point into the network for all asserted Facts. Iterates a cache
@@ -175,10 +177,10 @@
*/
public void retractObject(final InternalFactHandle handle,
final PropagationContext context,
- final ObjectTypeConf objectTypeConf,
+ final ObjectTypeConf objectTypeConf,
final InternalWorkingMemory workingMemory) {
final Object object = handle.getObject();
-
+
ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
if ( cachedNodes == null ) {
@@ -192,9 +194,9 @@
workingMemory );
}
}
-
+
public void retractObject(final InternalFactHandle handle,
- final PropagationContext context,
+ final PropagationContext context,
final InternalWorkingMemory workingMemory) {
// do nothing, dummy method to impl the interface
}
@@ -208,13 +210,13 @@
* <code>Objects</code>. Rete only accepts <code>ObjectTypeNode</code>s
* as parameters to this method, though.
*/
- protected void addObjectSink(final RightTupleSink objectSink) {
+ protected void addObjectSink(final ObjectSink objectSink) {
final ObjectTypeNode node = (ObjectTypeNode) objectSink;
this.objectTypeNodes.put( node.getObjectType(),
node );
}
- protected void removeObjectSink(final RightTupleSink objectSink) {
+ protected void removeObjectSink(final ObjectSink objectSink) {
final ObjectTypeNode node = (ObjectTypeNode) objectSink;
this.objectTypeNodes.remove( node.getObjectType() );
}
@@ -233,8 +235,8 @@
null,
null );
this.source.updateSink( this,
- propagationContext,
- workingMemory );
+ propagationContext,
+ workingMemory );
}
}
@@ -271,17 +273,17 @@
return this.entryPoint.equals( other.entryPoint );
}
- public void updateSink(final RightTupleSink sink,
+ public void updateSink(final ObjectSink sink,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
// JBRULES-612: the cache MUST be invalidated when a new node type is added to the network, so iterate and reset all caches.
final ObjectTypeNode node = (ObjectTypeNode) sink;
-
+
final ObjectType newObjectType = node.getObjectType();
- InternalWorkingMemoryEntryPoint wmEntryPoint = ( InternalWorkingMemoryEntryPoint ) workingMemory.getWorkingMemoryEntryPoint( this.entryPoint.getEntryPointId() );
-
- for ( ObjectTypeConf objectTypeConf : wmEntryPoint.getObjectTypeConfigurationRegistry().values() ) {
+ InternalWorkingMemoryEntryPoint wmEntryPoint = (InternalWorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint( this.entryPoint.getEntryPointId() );
+
+ for ( ObjectTypeConf objectTypeConf : wmEntryPoint.getObjectTypeConfigurationRegistry().values() ) {
if ( newObjectType.isAssignableFrom( objectTypeConf.getConcreteObjectTypeNode().getObjectType() ) ) {
objectTypeConf.resetCache();
ObjectTypeNode sourceNode = objectTypeConf.getConcreteObjectTypeNode();
@@ -305,7 +307,14 @@
}
public String toString() {
- return "[EntryPointNode("+this.id+") "+this.entryPoint+" ]";
+ return "[EntryPointNode(" + this.id + ") " + this.entryPoint + " ]";
}
+ public void retractRightTuple(RightTuple rightTuple,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory) {
+ // TODO Auto-generated method stub
+
+ }
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -58,18 +58,18 @@
/**
*
*/
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
/** The semantic <code>Test</code>. */
- private EvalCondition condition;
+ private EvalCondition condition;
/** The source of incoming <code>Tuples</code>. */
private LeftTupleSource tupleSource;
- protected boolean tupleMemoryEnabled;
+ protected boolean tupleMemoryEnabled;
- private LeftTupleSinkNode previousTupleSinkNode;
- private LeftTupleSinkNode nextTupleSinkNode;
+ private LeftTupleSinkNode previousTupleSinkNode;
+ private LeftTupleSinkNode nextTupleSinkNode;
// ------------------------------------------------------------
// Constructors
@@ -97,23 +97,25 @@
this.tupleMemoryEnabled = context.isTupleMemoryEnabled();
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- condition = (EvalCondition)in.readObject();
- tupleSource = (LeftTupleSource)in.readObject();
- tupleMemoryEnabled = in.readBoolean();
- previousTupleSinkNode = (LeftTupleSinkNode)in.readObject();
- nextTupleSinkNode = (LeftTupleSinkNode)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ condition = (EvalCondition) in.readObject();
+ tupleSource = (LeftTupleSource) in.readObject();
+ tupleMemoryEnabled = in.readBoolean();
+ previousTupleSinkNode = (LeftTupleSinkNode) in.readObject();
+ nextTupleSinkNode = (LeftTupleSinkNode) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeObject(condition);
- out.writeObject(tupleSource);
- out.writeBoolean(tupleMemoryEnabled);
- out.writeObject(previousTupleSinkNode);
- out.writeObject(nextTupleSinkNode);
+ super.writeExternal( out );
+ out.writeObject( condition );
+ out.writeObject( tupleSource );
+ out.writeBoolean( tupleMemoryEnabled );
+ out.writeObject( previousTupleSinkNode );
+ out.writeObject( nextTupleSinkNode );
}
+
/**
* Attaches this node into the network.
*/
@@ -168,8 +170,8 @@
* If an error occurs while asserting.
*/
public void assertLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final EvalMemory memory = (EvalMemory) workingMemory.getNodeMemory( this );
final boolean allowed = this.condition.isAllowed( tuple,
@@ -182,22 +184,22 @@
}
this.sink.propagateAssertLeftTuple( tuple,
- context,
- workingMemory );
+ context,
+ workingMemory );
}
}
public void retractLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final EvalMemory memory = (EvalMemory) workingMemory.getNodeMemory( this );
// can we improve that?
final LeftTuple memTuple = memory.tupleMemory.remove( tuple );
if ( memTuple != null ) {
this.sink.propagateRetractLeftTuple( memTuple,
- context,
- workingMemory );
+ context,
+ workingMemory );
}
}
@@ -229,7 +231,8 @@
}
public Object createMemory(final RuleBaseConfiguration config) {
- return new EvalMemory( this.tupleMemoryEnabled, this.condition.createContext() );
+ return new EvalMemory( this.tupleMemoryEnabled,
+ this.condition.createContext() );
}
/* (non-Javadoc)
@@ -244,8 +247,8 @@
final Iterator it = memory.tupleMemory.iterator();
for ( LeftTuple tuple = (LeftTuple) it.next(); tuple != null; tuple = (LeftTuple) it.next() ) {
sink.assertLeftTuple( tuple,
- context,
- workingMemory );
+ context,
+ workingMemory );
}
}
@@ -262,7 +265,7 @@
workingMemories[i].clearNodeMemory( this );
}
}
- if( ! context.alreadyVisited( this.tupleSource ) ) {
+ if ( !context.alreadyVisited( this.tupleSource ) ) {
this.tupleSource.remove( context,
builder,
this,
@@ -314,31 +317,36 @@
this.previousTupleSinkNode = previous;
}
- public static class EvalMemory implements Externalizable {
+ public static class EvalMemory
+ implements
+ Externalizable {
private static final long serialVersionUID = -2754669682742843929L;
- public TupleHashTable tupleMemory;
- public Object context;
+ public TupleHashTable tupleMemory;
+ public Object context;
public EvalMemory() {
}
- public EvalMemory( final boolean tupleMemoryEnabled, final Object context ) {
+
+ public EvalMemory(final boolean tupleMemoryEnabled,
+ final Object context) {
this.context = context;
- if( tupleMemoryEnabled ) {
+ if ( tupleMemoryEnabled ) {
this.tupleMemory = new TupleHashTable();
}
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- tupleMemory = (TupleHashTable)in.readObject();
- context = in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ tupleMemory = (TupleHashTable) in.readObject();
+ context = in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(tupleMemory);
- out.writeObject(context);
+ out.writeObject( tupleMemory );
+ out.writeObject( context );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -67,7 +67,7 @@
*/
public ExistsNode(final int id,
final LeftTupleSource leftInput,
- final RightTupleSource rightInput,
+ final ObjectSource rightInput,
final BetaConstraints joinNodeBinder,
final BuildContext context) {
super( id,
@@ -90,8 +90,8 @@
* The working memory session.
*/
public void assertLeftTuple(final LeftTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
if ( this.tupleMemoryEnabled ) {
@@ -115,8 +115,8 @@
if ( leftTuple.getMatch() != null ) {
this.sink.propagateAssertLeftTuple( leftTuple,
- context,
- workingMemory );
+ context,
+ workingMemory );
}
}
@@ -149,11 +149,11 @@
factHandle );
for ( LeftTuple tuple = (LeftTuple) it.next(); tuple != null; tuple = (LeftTuple) it.next() ) {
if ( this.constraints.isAllowedCachedRight( memory.getContext(),
- tuple ) && tuple.getMatch() == null) {
- tuple.setMatch( factHandle );
- this.sink.propagateAssertLeftTuple( tuple,
- context,
- workingMemory );
+ tuple ) && tuple.getMatch() == null ) {
+ tuple.setMatch( factHandle );
+ this.sink.propagateAssertLeftTuple( tuple,
+ context,
+ workingMemory );
}
}
@@ -194,7 +194,8 @@
// find next match, remember it and break.
final Iterator tupleIt = memory.getRightTupleMemory().iterator( tuple );
this.constraints.updateFromTuple( memory.getContext(),
- workingMemory, tuple );
+ workingMemory,
+ tuple );
for ( FactEntry entry = (FactEntry) tupleIt.next(); entry != null; entry = (FactEntry) tupleIt.next() ) {
final InternalFactHandle rightHandle = entry.getFactHandle();
@@ -210,8 +211,8 @@
// if there is now no new tuple match then propagate assert.
if ( tuple.getMatch() == null ) {
this.sink.propagateRetractLeftTuple( tuple,
- context,
- workingMemory );
+ context,
+ workingMemory );
}
}
@@ -233,8 +234,8 @@
* The working memory session.
*/
public void retractLeftTuple(final LeftTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
// Must use the tuple in memory as it has the tuple matches count
@@ -243,10 +244,10 @@
return;
}
- if ( tuple.getMatch() != null) {
+ if ( tuple.getMatch() != null ) {
this.sink.propagateRetractLeftTuple( tuple,
- context,
- workingMemory );
+ context,
+ workingMemory );
}
}
@@ -263,14 +264,14 @@
for ( LeftTuple tuple = (LeftTuple) tupleIter.next(); tuple != null; tuple = (LeftTuple) tupleIter.next() ) {
if ( tuple.getMatch() != null ) {
sink.assertLeftTuple( new LeftTuple( tuple ),
- context,
- workingMemory );
+ context,
+ workingMemory );
}
}
}
public String toString() {
- RightTupleSource source = this.rightInput;
+ ObjectSource source = this.rightInput;
while ( source.getClass() != ObjectTypeNode.class ) {
source = source.source;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -39,9 +39,9 @@
private static final long serialVersionUID = 4493660262148247467L;
- private FactTemplate factTemplate;
- private ObjectTypeNode concreteObjectTypeNode;
- private ObjectTypeNode[] cache;
+ private FactTemplate factTemplate;
+ private ObjectTypeNode concreteObjectTypeNode;
+ private ObjectTypeNode[] cache;
public FactTemplateTypeConf() {
}
@@ -73,18 +73,19 @@
this.cache = new ObjectTypeNode[]{this.concreteObjectTypeNode};
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- factTemplate = (FactTemplate)in.readObject();
- concreteObjectTypeNode = (ObjectTypeNode)in.readObject();
- cache = (ObjectTypeNode[])in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ factTemplate = (FactTemplate) in.readObject();
+ concreteObjectTypeNode = (ObjectTypeNode) in.readObject();
+ cache = (ObjectTypeNode[]) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(factTemplate);
- out.writeObject(concreteObjectTypeNode);
- out.writeObject(cache);
+ out.writeObject( factTemplate );
+ out.writeObject( concreteObjectTypeNode );
+ out.writeObject( cache );
}
-
+
public ObjectTypeNode getConcreteObjectTypeNode() {
return this.concreteObjectTypeNode;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -32,12 +32,12 @@
private static final long serialVersionUID = 400L;
private DataProvider dataProvider;
- private LeftTupleSource tupleSource;
+ private LeftTupleSource tupleSource;
private AlphaNodeFieldConstraint[] alphaConstraints;
private BetaConstraints betaConstraints;
- private LeftTupleSinkNode previousTupleSinkNode;
- private LeftTupleSinkNode nextTupleSinkNode;
+ private LeftTupleSinkNode previousTupleSinkNode;
+ private LeftTupleSinkNode nextTupleSinkNode;
protected boolean tupleMemoryEnabled;
@@ -57,33 +57,35 @@
this.tupleMemoryEnabled = false;
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- dataProvider = (DataProvider)in.readObject();
- tupleSource = (LeftTupleSource)in.readObject();
- alphaConstraints = (AlphaNodeFieldConstraint[])in.readObject();
- betaConstraints = (BetaConstraints)in.readObject();
- previousTupleSinkNode = (LeftTupleSinkNode)in.readObject();
- nextTupleSinkNode = (LeftTupleSinkNode)in.readObject();
- tupleMemoryEnabled = in.readBoolean();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ dataProvider = (DataProvider) in.readObject();
+ tupleSource = (LeftTupleSource) in.readObject();
+ alphaConstraints = (AlphaNodeFieldConstraint[]) in.readObject();
+ betaConstraints = (BetaConstraints) in.readObject();
+ previousTupleSinkNode = (LeftTupleSinkNode) in.readObject();
+ nextTupleSinkNode = (LeftTupleSinkNode) in.readObject();
+ tupleMemoryEnabled = in.readBoolean();
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeObject(dataProvider);
- out.writeObject(tupleSource);
- out.writeObject(alphaConstraints);
- out.writeObject(betaConstraints);
- out.writeObject(previousTupleSinkNode);
- out.writeObject(nextTupleSinkNode);
- out.writeBoolean(tupleMemoryEnabled);
+ super.writeExternal( out );
+ out.writeObject( dataProvider );
+ out.writeObject( tupleSource );
+ out.writeObject( alphaConstraints );
+ out.writeObject( betaConstraints );
+ out.writeObject( previousTupleSinkNode );
+ out.writeObject( nextTupleSinkNode );
+ out.writeBoolean( tupleMemoryEnabled );
}
+
/**
* @inheritDoc
*/
public void assertLeftTuple(final LeftTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final FromMemory memory = (FromMemory) workingMemory.getNodeMemory( this );
memory.betaMemory.getLeftTupleMemory().add( leftTuple );
@@ -121,9 +123,9 @@
list.add( new LinkedListEntry( handle ) );
this.sink.propagateAssertLeftTuple( leftTuple,
- handle,
- context,
- workingMemory );
+ handle,
+ context,
+ workingMemory );
} else {
workingMemory.getFactHandleFactory().destroyFactHandle( handle );
}
@@ -139,8 +141,8 @@
}
public void retractLeftTuple(final LeftTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final FromMemory memory = (FromMemory) workingMemory.getNodeMemory( this );
final LeftTuple tuple = memory.betaMemory.getLeftTupleMemory().remove( leftTuple );
@@ -155,9 +157,9 @@
for ( LinkedListEntry entry = (LinkedListEntry) list.getFirst(); entry != null; entry = (LinkedListEntry) entry.getNext() ) {
final InternalFactHandle handle = (InternalFactHandle) entry.getObject();
this.sink.propagateRetractLeftTuple( leftTuple,
- handle,
- context,
- workingMemory );
+ handle,
+ context,
+ workingMemory );
workingMemory.getFactHandleFactory().destroyFactHandle( handle );
}
}
@@ -185,7 +187,7 @@
public void networkUpdated() {
this.tupleSource.networkUpdated();
}
-
+
protected void doRemove(final RuleRemovalContext context,
final ReteooBuilder builder,
final BaseNode node,
@@ -224,9 +226,9 @@
for ( LinkedListEntry entry = (LinkedListEntry) list.getFirst(); entry != null; entry = (LinkedListEntry) entry.getNext() ) {
final InternalFactHandle handle = (InternalFactHandle) entry.getObject();
this.sink.propagateAssertLeftTuple( tuple,
- handle,
- context,
- workingMemory );
+ handle,
+ context,
+ workingMemory );
}
}
}
@@ -299,7 +301,7 @@
this.betaMemory = betaMemory;
this.providerContext = providerContext;
this.alphaContexts = new ContextEntry[constraints.length];
- for( int i = 0; i < constraints.length; i++ ) {
+ for ( int i = 0; i < constraints.length; i++ ) {
this.alphaContexts[i] = constraints[i].createContextEntry();
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactHandle.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactHandle.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -27,15 +27,16 @@
/**
*
*/
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
private InternalFactHandle delegate;
- private Object object;
+ private Object object;
public InitialFactHandle() {
}
+
public InitialFactHandle(final InternalFactHandle delegate) {
super();
this.delegate = delegate;
@@ -45,16 +46,17 @@
// ----------------------------------------------------------------------
// Instance members
// ----------------------------------------------------------------------
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- delegate = (InternalFactHandle)in.readObject();
- object = in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ delegate = (InternalFactHandle) in.readObject();
+ object = in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeObject(delegate);
- out.writeObject(object);
+ super.writeExternal( out );
+ out.writeObject( delegate );
+ out.writeObject( object );
}
/**
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactImpl.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactImpl.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -33,10 +33,11 @@
*/
public final class InitialFactImpl
implements
- InitialFact, Externalizable {
+ InitialFact,
+ Externalizable {
private static final InitialFact INSTANCE = new InitialFactImpl();
- private final int hashCode = "InitialFactImpl".hashCode();
+ private final int hashCode = "InitialFactImpl".hashCode();
public static InitialFact getInstance() {
return InitialFactImpl.INSTANCE;
@@ -45,12 +46,14 @@
public InitialFactImpl() {
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
}
public void writeExternal(ObjectOutput out) throws IOException {
}
+
public int hashCode() {
return this.hashCode;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -65,7 +65,7 @@
public JoinNode(final int id,
final LeftTupleSource leftInput,
- final RightTupleSource rightInput,
+ final ObjectSource rightInput,
final BetaConstraints binder,
final BuildContext context) {
super( id,
@@ -138,12 +138,12 @@
* The working memory seesion.
*/
public void assertObject(final InternalFactHandle factHandle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
-
+
RightTuple rightTuple = new RightTuple( factHandle,
- this );
+ this );
memory.getRightTupleMemory().add( rightTuple );
if ( !this.tupleMemoryEnabled ) {
@@ -178,11 +178,11 @@
* The working memory seesion.
*/
public void retractRightTuple(final RightTuple rightTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
memory.getRightTupleMemory().remove( rightTuple );
-
+
if ( rightTuple.getBetaChildren() != null ) {
this.sink.propagateRetractRightTuple( rightTuple,
context,
@@ -244,7 +244,7 @@
}
public String toString() {
- RightTupleSource source = this.rightInput;
+ ObjectSource source = this.rightInput;
while ( !(source instanceof ObjectTypeNode) ) {
source = source.source;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LIANodePropagation.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LIANodePropagation.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LIANodePropagation.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -9,35 +9,39 @@
import java.io.ObjectOutput;
import java.io.ObjectInput;
-public class LIANodePropagation implements Externalizable {
+public class LIANodePropagation
+ implements
+ Externalizable {
private LeftInputAdapterNode node;
- private InternalFactHandle handle;
- private PropagationContext context;
+ private InternalFactHandle handle;
+ private PropagationContext context;
public LIANodePropagation(final LeftInputAdapterNode node,
final InternalFactHandle handle,
- final PropagationContext context ) {
+ final PropagationContext context) {
super();
this.node = node;
this.handle = handle;
this.context = context;
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- node = (LeftInputAdapterNode)in.readObject();
- handle = (InternalFactHandle)in.readObject();
- context = (PropagationContext)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ node = (LeftInputAdapterNode) in.readObject();
+ handle = (InternalFactHandle) in.readObject();
+ context = (PropagationContext) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(node);
- out.writeObject(handle);
- out.writeObject(context);
+ out.writeObject( node );
+ out.writeObject( handle );
+ out.writeObject( context );
}
public void doPropagation(InternalWorkingMemory workingMemory) {
- node.getSinkPropagator().createAndPropagateAssertLeftTuple( handle, context, workingMemory );
+ node.getSinkPropagator().createAndPropagateAssertLeftTuple( handle,
+ context,
+ workingMemory );
}
-
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -44,17 +44,17 @@
*/
public class LeftInputAdapterNode extends LeftTupleSource
implements
- RightTupleSinkNode,
+ ObjectTupleSinkNode,
NodeMemory {
/**
*
*/
- private static final long serialVersionUID = 400L;
- private RightTupleSource objectSource;
+ private static final long serialVersionUID = 400L;
+ private ObjectSource objectSource;
- private RightTupleSinkNode previousRightTupleSinkNode;
- private RightTupleSinkNode nextRightTupleSinkNode;
+ private ObjectTupleSinkNode previousRightTupleSinkNode;
+ private ObjectTupleSinkNode nextRightTupleSinkNode;
public LeftInputAdapterNode() {
@@ -73,7 +73,7 @@
* a predicate is used in the first pattern, for instance
*/
public LeftInputAdapterNode(final int id,
- final RightTupleSource source,
+ final ObjectSource source,
final BuildContext context) {
super( id );
this.objectSource = source;
@@ -82,9 +82,9 @@
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
super.readExternal( in );
- objectSource = (RightTupleSource) in.readObject();
- previousRightTupleSinkNode = (RightTupleSinkNode) in.readObject();
- nextRightTupleSinkNode = (RightTupleSinkNode) in.readObject();
+ objectSource = (ObjectSource) in.readObject();
+ previousRightTupleSinkNode = (ObjectTupleSinkNode) in.readObject();
+ nextRightTupleSinkNode = (ObjectTupleSinkNode) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
@@ -132,8 +132,8 @@
* the <code>WorkingMemory</code> session.
*/
public void assertObject(final InternalFactHandle factHandle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
if ( !workingMemory.isSequential() ) {
this.sink.createAndPropagateAssertLeftTuple( factHandle,
context,
@@ -144,23 +144,6 @@
}
}
- /**
- * Retract an existing <code>FactHandleImpl</code> by placing it in a new <code>ReteTuple</code> before
- * proagating to the <code>TupleSinks</code>
- *
- * @param handle
- * The <code>FactHandle/code> to retract.
- * @param context
- * The <code>PropagationContext</code> of the <code>WorkingMemory<code> action.
- * @param workingMemory
- * the <code>WorkingMemory</code> session.
- */
- public void retractRightTuple(final RightTuple rightTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- throw new UnsupportedOperationException( "LeftInputAdapterNode.retractRightTuple is not supported." );
- }
-
public void updateSink(final LeftTupleSink sink,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
@@ -194,7 +177,7 @@
* @return
* The next ObjectSinkNode
*/
- public RightTupleSinkNode getNextRightTupleSinkNode() {
+ public ObjectTupleSinkNode getNextObjectSinkNode() {
return this.nextRightTupleSinkNode;
}
@@ -203,7 +186,7 @@
* @param next
* The next ObjectSinkNode
*/
- public void setNextRightTupleSinkNode(final RightTupleSinkNode next) {
+ public void setNextObjectSinkNode(final ObjectTupleSinkNode next) {
this.nextRightTupleSinkNode = next;
}
@@ -212,7 +195,7 @@
* @return
* The previous ObjectSinkNode
*/
- public RightTupleSinkNode getPreviousRightTupleSinkNode() {
+ public ObjectTupleSinkNode getPreviousObjectSinkNode() {
return this.previousRightTupleSinkNode;
}
@@ -221,7 +204,7 @@
* @param previous
* The previous ObjectSinkNode
*/
- public void setPreviousRightTupleSinkNode(final RightTupleSinkNode previous) {
+ public void setPreviousObjectSinkNode(final ObjectTupleSinkNode previous) {
this.previousRightTupleSinkNode = previous;
}
@@ -255,7 +238,7 @@
*/
private static class RightTupleSinkAdapter
implements
- RightTupleSink {
+ ObjectSink {
private LeftTupleSink sink;
public RightTupleSinkAdapter(final LeftTupleSink sink) {
@@ -263,8 +246,8 @@
}
public void assertObject(final InternalFactHandle factHandle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final LeftTuple tuple = new LeftTuple( factHandle,
this.sink );
this.sink.assertLeftTuple( tuple,
@@ -273,8 +256,8 @@
}
public void retractRightTuple(final RightTuple rightTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
throw new UnsupportedOperationException( "ObjectSinkAdapter onlys supports assertObject method calls" );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -74,14 +74,14 @@
this.hashCode = h;
this.sink = sink;
-
+
LeftTuple currentFirst = handle.getLeftTuple();
if ( currentFirst != null ) {
- currentFirst.leftParentPrevious = this;
+ currentFirst.leftParentPrevious = this;
this.leftParentNext = currentFirst;
}
-
- handle.setLeftTuple( this );
+
+ handle.setLeftTuple( this );
}
public LeftTuple(final LeftTuple leftTuple,
@@ -125,7 +125,7 @@
this.leftParent.children = this;
this.sink = sink;
}
-
+
public void unlinkFromLeftParent() {
LeftTuple previous = (LeftTuple) this.leftParentPrevious;
LeftTuple next = (LeftTuple) this.leftParentNext;
@@ -150,9 +150,9 @@
this.leftParent = null;
this.leftParentPrevious = null;
this.leftParentNext = null;
-//
+ //
this.blocker = null;
-//
+ //
this.rightParent = null;
this.rightParentPrevious = null;
this.rightParentNext = null;
@@ -257,14 +257,14 @@
}
return entry.handle;
}
-
+
public TupleHashTable getMemory() {
return this.memory;
}
public void setMemory(TupleHashTable memory) {
this.memory = memory;
- }
+ }
public Entry getPrevious() {
return previous;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleMemory.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleMemory.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -19,8 +19,8 @@
public int size();
-// public Entry[] getTable();
-
+ // public Entry[] getTable();
+
public Entry[] toArray();
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSink.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSink.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSink.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -47,8 +47,8 @@
* the <code>WorkingMemory</code> session.
*/
void assertLeftTuple(LeftTuple leftTuple,
- PropagationContext context,
- InternalWorkingMemory workingMemory);
+ PropagationContext context,
+ InternalWorkingMemory workingMemory);
void retractLeftTuple(LeftTuple leftTuple,
PropagationContext context,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkNodeList.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkNodeList.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkNodeList.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -52,8 +52,8 @@
Externalizable {
private static final long serialVersionUID = 400L;
- private LeftTupleSinkNode firstNode;
- private LeftTupleSinkNode lastNode;
+ private LeftTupleSinkNode firstNode;
+ private LeftTupleSinkNode lastNode;
private int size;
@@ -63,17 +63,19 @@
public LeftTupleSinkNodeList() {
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- firstNode = (LeftTupleSinkNode)in.readObject();
- lastNode = (LeftTupleSinkNode)in.readObject();
- size = in.readInt();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ firstNode = (LeftTupleSinkNode) in.readObject();
+ lastNode = (LeftTupleSinkNode) in.readObject();
+ size = in.readInt();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(firstNode);
- out.writeObject(lastNode);
- out.writeInt(size);
+ out.writeObject( firstNode );
+ out.writeObject( lastNode );
+ out.writeInt( size );
}
+
/**
* Add a <code>TupleSinkNode</code> to the list. If the <code>LinkedList</code> is empty then the first and
* last nodes are set to the added node.
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSource.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSource.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -91,12 +91,12 @@
if ( this.sink instanceof EmptyLeftTupleSinkAdapter ) {
this.sink = new SingleLeftTupleSinkAdapter( tupleSink );
} else if ( this.sink instanceof SingleLeftTupleSinkAdapter ) {
- final CompositeTupleSinkAdapter sinkAdapter = new CompositeTupleSinkAdapter();
+ final CompositeLeftTupleSinkAdapter sinkAdapter = new CompositeLeftTupleSinkAdapter();
sinkAdapter.addTupleSink( this.sink.getSinks()[0] );
sinkAdapter.addTupleSink( tupleSink );
this.sink = sinkAdapter;
} else {
- ((CompositeTupleSinkAdapter) this.sink).addTupleSink( tupleSink );
+ ((CompositeLeftTupleSinkAdapter) this.sink).addTupleSink( tupleSink );
}
}
@@ -114,7 +114,7 @@
if ( this.sink instanceof SingleLeftTupleSinkAdapter ) {
this.sink = EmptyLeftTupleSinkAdapter.getInstance();
} else {
- final CompositeTupleSinkAdapter sinkAdapter = (CompositeTupleSinkAdapter) this.sink;
+ final CompositeLeftTupleSinkAdapter sinkAdapter = (CompositeLeftTupleSinkAdapter) this.sink;
sinkAdapter.removeTupleSink( tupleSink );
if ( sinkAdapter.size() == 1 ) {
this.sink = new SingleLeftTupleSinkAdapter( sinkAdapter.getSinks()[0] );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -17,7 +17,9 @@
import org.drools.util.ReflectiveVisitor;
import org.drools.util.FactHandleIndexHashTable.FieldIndexEntry;
-public class MemoryVisitor extends ReflectiveVisitor implements Externalizable {
+public class MemoryVisitor extends ReflectiveVisitor
+ implements
+ Externalizable {
private InternalWorkingMemory workingMemory;
private int indent = 0;
@@ -31,14 +33,15 @@
this.workingMemory = workingMemory;
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- workingMemory = (InternalWorkingMemory)in.readObject();
- indent = in.readInt();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ workingMemory = (InternalWorkingMemory) in.readObject();
+ indent = in.readInt();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(workingMemory);
- out.writeInt(indent);
+ out.writeObject( workingMemory );
+ out.writeInt( indent );
}
/**
@@ -52,7 +55,7 @@
* Rete visits each of its ObjectTypeNodes.
*/
public void visitRete(final Rete rete) {
- for( ObjectTypeNode node : rete.getObjectTypeNodes() ) {
+ for ( ObjectTypeNode node : rete.getObjectTypeNodes() ) {
visit( node );
}
}
@@ -65,10 +68,10 @@
this.indent++;
try {
- final Field field = RightTupleSource.class.getDeclaredField( "sink" );
+ final Field field = ObjectSource.class.getDeclaredField( "sink" );
field.setAccessible( true );
- final RightTupleSinkPropagator sink = (RightTupleSinkPropagator) field.get( node );
- final RightTupleSink[] sinks = sink.getSinks();
+ final ObjectSinkPropagator sink = (ObjectSinkPropagator) field.get( node );
+ final ObjectSink[] sinks = sink.getSinks();
for ( int i = 0, length = sinks.length; i < length; i++ ) {
visit( sinks[i] );
}
@@ -86,10 +89,10 @@
this.indent++;
try {
- final Field field = RightTupleSource.class.getDeclaredField( "sink" );
+ final Field field = ObjectSource.class.getDeclaredField( "sink" );
field.setAccessible( true );
- final RightTupleSinkPropagator sink = (RightTupleSinkPropagator) field.get( node );
- final RightTupleSink[] sinks = sink.getSinks();
+ final ObjectSinkPropagator sink = (ObjectSinkPropagator) field.get( node );
+ final ObjectSink[] sinks = sink.getSinks();
for ( int i = 0, length = sinks.length; i < length; i++ ) {
visit( sinks[i] );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -65,7 +65,7 @@
*/
public NotNode(final int id,
final LeftTupleSource leftInput,
- final RightTupleSource rightInput,
+ final ObjectSource rightInput,
final BetaConstraints joinNodeBinder,
final BuildContext context) {
super( id,
@@ -126,8 +126,8 @@
}
this.sink.propagateAssertLeftTuple( leftTuple,
- context,
- workingMemory );
+ context,
+ workingMemory );
}
}
@@ -144,12 +144,13 @@
* The working memory seesion.
*/
public void assertObject(final InternalFactHandle factHandle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- final RightTuple rightTuple = new RightTuple( factHandle, this);
-
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+ final RightTuple rightTuple = new RightTuple( factHandle,
+ this );
+
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
- memory.getRightTupleMemory().add( rightTuple );
+ memory.getRightTupleMemory().add( rightTuple );
if ( !this.tupleMemoryEnabled ) {
// do nothing here, as we know there are no left tuples at this stage in sequential mode.
@@ -162,7 +163,7 @@
for ( LeftTuple leftTuple = memory.getLeftTupleMemory().getFirst( rightTuple ); leftTuple != null; ) {
// preserve next now, in case we remove this leftTuple
LeftTuple temp = (LeftTuple) leftTuple.getNext();
-
+
// we know that only unblocked LeftTuples are still in the memory
if ( this.constraints.isAllowedCachedRight( memory.getContext(),
leftTuple ) ) {
@@ -175,17 +176,16 @@
}
rightTuple.setBlocked( leftTuple );
-
// this is now blocked so remove from memory
- memory.getLeftTupleMemory().remove( leftTuple );
+ memory.getLeftTupleMemory().remove( leftTuple );
if ( leftTuple.getBetaChildren() != null ) {
this.sink.propagateRetractLeftTuple( leftTuple,
context,
workingMemory );
- }
+ }
}
-
+
leftTuple = temp;
}
@@ -206,28 +206,28 @@
* @throws AssertionException
*/
public void retractRightTuple(final RightTuple rightTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
// assign now, so we can remove from memory before doing any possible propagations
- final RightTuple rootBlocker = (RightTuple) rightTuple.getPrevious();
-
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+ final RightTuple rootBlocker = (RightTuple) rightTuple.getPrevious();
+
+ final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
memory.getRightTupleMemory().remove( rightTuple );
-
+
if ( rightTuple.getBlocked() == null ) {
return;
- }
+ }
for ( LeftTuple leftTuple = (LeftTuple) rightTuple.getBlocked(); leftTuple != null; ) {
- LeftTuple temp = leftTuple.getBlockedNext();
-
+ LeftTuple temp = leftTuple.getBlockedNext();
+
leftTuple.setBlocker( null );
leftTuple.setBlockedPrevious( null );
leftTuple.setBlockedNext( null );
-
+
this.constraints.updateFromTuple( memory.getContext(),
workingMemory,
- leftTuple );
+ leftTuple );
// we know that older tuples have been checked so continue previously
for ( RightTuple newBlocker = rootBlocker; newBlocker != null; newBlocker = (RightTuple) newBlocker.getPrevious() ) {
@@ -245,16 +245,16 @@
break;
}
}
-
+
if ( leftTuple.getBlocker() == null ) {
// was previous blocked and not in memory, so add
memory.getLeftTupleMemory().add( leftTuple );
this.sink.propagateAssertLeftTuple( leftTuple,
- context,
- workingMemory );
- }
-
+ context,
+ workingMemory );
+ }
+
leftTuple = temp;
}
this.constraints.resetTuple( memory.getContext() );
@@ -277,8 +277,8 @@
RightTuple blocker = leftTuple.getBlocker();
if ( blocker == null ) {
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
- memory.getLeftTupleMemory().remove( leftTuple );
-
+ memory.getLeftTupleMemory().remove( leftTuple );
+
this.sink.propagateRetractLeftTuple( leftTuple,
context,
workingMemory );
@@ -312,17 +312,17 @@
final Iterator tupleIter = memory.getLeftTupleMemory().iterator();
// @todo
-// for ( LeftTuple leftTuple = (LeftTuple) tupleIter.next(); leftTuple != null; leftTuple = (LeftTuple) tupleIter.next() ) {
-// if ( leftTuple.getMatch() == null ) {
-// sink.assertLeftTuple( new LeftTuple( leftTuple ),
-// context,
-// workingMemory );
-// }
-// }
+ // for ( LeftTuple leftTuple = (LeftTuple) tupleIter.next(); leftTuple != null; leftTuple = (LeftTuple) tupleIter.next() ) {
+ // if ( leftTuple.getMatch() == null ) {
+ // sink.assertLeftTuple( new LeftTuple( leftTuple ),
+ // context,
+ // workingMemory );
+ // }
+ // }
}
public String toString() {
- RightTupleSource source = this.rightInput;
+ ObjectSource source = this.rightInput;
while ( !(source instanceof ObjectTypeNode) ) {
source = source.source;
}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSink.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSink.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSink.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -0,0 +1,40 @@
+package org.drools.reteoo;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.spi.PropagationContext;
+
+/**
+ * Receiver of propagated <code>FactHandleImpl</code>s from a
+ * <code>ObjectSource</code>.
+ *
+ * @see ObectSource
+ *
+ * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
+ * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
+ *
+ */
+public interface ObjectSink
+ extends
+ Sink {
+
+ public void assertObject(InternalFactHandle factHandle,
+ PropagationContext propagationContext,
+ InternalWorkingMemory workingMemory);
+}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSinkNodeList.java (from rev 19178, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkNodeList.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSinkNodeList.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSinkNodeList.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -0,0 +1,245 @@
+package org.drools.reteoo;
+
+import java.io.Externalizable;
+import java.io.ObjectInput;
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * This is a simple linked linked implementation. Each node must implement </code>LinkedListNode<code> so that it references
+ * the node before and after it. This way a node can be removed without having to scan the list to find it. This class
+ * does not provide an Iterator implementation as its designed for efficiency and not genericity. There are a number of
+ * ways to iterate the list.
+ * <p>
+ * Simple iterator:
+ * <pre>
+ * for ( LinkedListNode node = list.getFirst(); node != null; node = node.getNext() ) {
+ * }
+ * </pre>
+ *
+ * Iterator that pops the first entry:
+ * <pre>
+ * for ( LinkedListNode node = list.removeFirst(); node != null; node = list.removeFirst() ) {
+ * }
+ * </pre>
+ *
+ *
+ * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
+ * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
+ *
+ */
+public class ObjectSinkNodeList
+ implements
+ Externalizable {
+ private static final long serialVersionUID = 400L;
+
+ private ObjectTupleSinkNode firstNode;
+ private ObjectTupleSinkNode lastNode;
+
+ private int size;
+
+ /**
+ * Construct an empty <code>LinkedList</code>
+ */
+ public ObjectSinkNodeList() {
+
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ firstNode = (ObjectTupleSinkNode) in.readObject();
+ lastNode = (ObjectTupleSinkNode) in.readObject();
+ size = in.readInt();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject( firstNode );
+ out.writeObject( lastNode );
+ out.writeInt( size );
+ }
+
+ /**
+ * Add a <code>ObjectSinkNode</code> to the list. If the <code>LinkedList</code> is empty then the first and
+ * last nodes are set to the added node.
+ *
+ * @param node
+ * The <code>ObjectSinkNode</code> to be added
+ */
+ public void add(final ObjectTupleSinkNode node) {
+ if ( this.firstNode == null ) {
+ this.firstNode = node;
+ this.lastNode = node;;
+ } else {
+ this.lastNode.setNextObjectSinkNode( node );
+ node.setPreviousObjectSinkNode( this.lastNode );
+ this.lastNode = node;
+ }
+ this.size++;
+ }
+
+ /**
+ * Removes a <code>ObjectSinkNode</code> from the list. This works by attach the previous reference to the child reference.
+ * When the node to be removed is the first node it calls <code>removeFirst()</code>. When the node to be removed is the last node
+ * it calls <code>removeLast()</code>.
+ *
+ * @param node
+ * The <code>ObjectSinkNode</code> to be removed.
+ */
+ public void remove(final ObjectTupleSinkNode node) {
+ if ( (this.firstNode != node) && (this.lastNode != node) ) {
+ node.getPreviousObjectSinkNode().setNextObjectSinkNode( node.getNextObjectSinkNode() );
+ node.getNextObjectSinkNode().setPreviousObjectSinkNode( node.getPreviousObjectSinkNode() );
+ this.size--;
+ node.setPreviousObjectSinkNode( null );
+ node.setNextObjectSinkNode( null );
+
+ } else {
+ if ( this.firstNode == node ) {
+ removeFirst();
+ } else if ( this.lastNode == node ) {
+ removeLast();
+ }
+ }
+ }
+
+ /**
+ * Return the first node in the list
+ * @return
+ * The first <code>ObjectSinkNode</code>.
+ */
+ public final ObjectTupleSinkNode getFirst() {
+ return this.firstNode;
+ }
+
+ /**
+ * Return the last node in the list
+ * @return
+ * The last <code>ObjectSinkNode</code>.
+ */
+ public final ObjectTupleSinkNode getLast() {
+ return this.lastNode;
+ }
+
+ /**
+ * Remove the first node from the list. The next node then becomes the first node. If this is the last
+ * node then both first and last node references are set to null.
+ *
+ * @return
+ * The first <code>ObjectSinkNode</code>.
+ */
+ public ObjectTupleSinkNode removeFirst() {
+ if ( this.firstNode == null ) {
+ return null;
+ }
+ final ObjectTupleSinkNode node = this.firstNode;
+ this.firstNode = node.getNextObjectSinkNode();
+ node.setNextObjectSinkNode( null );
+ if ( this.firstNode != null ) {
+ this.firstNode.setPreviousObjectSinkNode( null );
+ } else {
+ this.lastNode = null;
+ }
+ this.size--;
+ return node;
+ }
+
+ /**
+ * Remove the last node from the list. The previous node then becomes the last node. If this is the last
+ * node then both first and last node references are set to null.
+ *
+ * @return
+ * The first <code>ObjectSinkNode</code>.
+ */
+ public ObjectTupleSinkNode removeLast() {
+ if ( this.lastNode == null ) {
+ return null;
+ }
+ final ObjectTupleSinkNode node = this.lastNode;
+ this.lastNode = node.getPreviousObjectSinkNode();
+ node.setPreviousObjectSinkNode( null );
+ if ( this.lastNode != null ) {
+ this.lastNode.setNextObjectSinkNode( null );
+ } else {
+ this.firstNode = this.lastNode;
+ }
+ this.size--;
+ return node;
+ }
+
+ /**
+ * @return
+ * boolean value indicating the empty status of the list
+ */
+ public final boolean isEmpty() {
+ return (this.firstNode == null);
+ }
+
+ /**
+ * Iterates the list removing all the nodes until there are no more nodes to remove.
+ */
+ public void clear() {
+ while ( removeFirst() != null ) {
+ }
+ }
+
+ /**
+ * @return
+ * return size of the list as an int
+ */
+ public final int size() {
+ return this.size;
+ }
+
+ /**
+ * Returns a list iterator
+ * @return
+ */
+ public Iterator iterator() {
+ return new Iterator() {
+ private ObjectTupleSinkNode currentNode = null;
+ private ObjectTupleSinkNode nextNode = getFirst();
+
+ public boolean hasNext() {
+ return (this.nextNode != null);
+ }
+
+ public Object next() {
+ this.currentNode = this.nextNode;
+ if ( this.currentNode != null ) {
+ this.nextNode = this.currentNode.getNextObjectSinkNode();
+ } else {
+ throw new NoSuchElementException( "No more elements to return" );
+ }
+ return this.currentNode;
+ }
+
+ public void remove() {
+ if ( this.currentNode != null ) {
+ ObjectSinkNodeList.this.remove( this.currentNode );
+ this.currentNode = null;
+ } else {
+ throw new IllegalStateException( "No item to remove. Call next() before calling remove()." );
+ }
+ }
+ };
+ }
+
+}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSinkPropagator.java (from rev 19178, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkPropagator.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSinkPropagator.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSinkPropagator.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -0,0 +1,20 @@
+package org.drools.reteoo;
+
+import java.io.Serializable;
+import java.io.Externalizable;
+
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.spi.PropagationContext;
+
+public interface ObjectSinkPropagator
+ extends
+ Externalizable {
+ public void propagateAssertObject(InternalFactHandle factHandle,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory);
+
+ public ObjectSink[] getSinks();
+
+ public int size();
+}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.java (from rev 19178, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSource.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -0,0 +1,166 @@
+package org.drools.reteoo;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.Serializable;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.drools.common.BaseNode;
+import org.drools.common.DefaultFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.spi.PropagationContext;
+
+/**
+ * A source of <code>FactHandle</code>s for an <code>ObjectSink</code>.
+ *
+ * <p>
+ * Nodes that propagate <code>FactHandleImpl</code> extend this class.
+ * </p>
+ *
+ * @see ObjectSource
+ * @see DefaultFactHandle
+ *
+ * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
+ * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
+ */
+public abstract class ObjectSource extends BaseNode
+ implements
+ Externalizable {
+ // ------------------------------------------------------------
+ // Instance members
+ // ------------------------------------------------------------
+
+ /** The destination for <code>FactHandleImpl</code>. */
+ protected ObjectSinkPropagator sink;
+
+ protected ObjectSource source;
+
+ private int alphaNodeHashingThreshold;
+
+ // ------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------
+ public ObjectSource() {
+
+ }
+
+ /**
+ * Single parameter constructor that specifies the unique id of the node.
+ *
+ * @param id
+ */
+ ObjectSource(final int id) {
+ this( id,
+ null,
+ 3 );
+ }
+
+ /**
+ * Single parameter constructor that specifies the unique id of the node.
+ *
+ * @param id
+ */
+ ObjectSource(final int id,
+ final ObjectSource objectSource,
+ final int alphaNodeHashingThreshold) {
+ super( id );
+ this.source = objectSource;
+ this.alphaNodeHashingThreshold = alphaNodeHashingThreshold;
+ this.sink = EmptyObjectSinkAdapter.getInstance();
+ }
+
+ // ------------------------------------------------------------
+ // Instance methods
+ // ------------------------------------------------------------
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ sink = (ObjectSinkPropagator) in.readObject();
+ source = (ObjectSource) in.readObject();
+ alphaNodeHashingThreshold = in.readInt();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ super.writeExternal( out );
+ out.writeObject( sink );
+ out.writeObject( source );
+ out.writeInt( alphaNodeHashingThreshold );
+ }
+
+ /**
+ * Adds the <code>ObjectSink</code> so that it may receive
+ * <code>FactHandleImpl</code> propagated from this
+ * <code>ObjectSource</code>.
+ *
+ * @param objectSink
+ * The <code>ObjectSink</code> to receive propagated
+ * <code>FactHandleImpl</code>.
+ */
+ protected void addObjectSink(final ObjectSink objectSink) {
+ if ( this.sink instanceof EmptyObjectSinkAdapter ) {
+ this.sink = new SingleObjectSinkAdapter( objectSink );
+ } else if ( this.sink instanceof SingleObjectSinkAdapter ) {
+ final CompositeObjectSinkAdapter sinkAdapter = new CompositeObjectSinkAdapter( this.alphaNodeHashingThreshold );
+ sinkAdapter.addObjectSink( this.sink.getSinks()[0] );
+ sinkAdapter.addObjectSink( objectSink );
+ this.sink = sinkAdapter;
+ } else {
+ ((CompositeObjectSinkAdapter) this.sink).addObjectSink( objectSink );
+ }
+ }
+
+ /**
+ * Removes the <code>ObjectSink</code>
+ *
+ * @param objectSink
+ * The <code>ObjectSink</code> to remove
+ */
+ protected void removeObjectSink(final ObjectSink objectSink) {
+ if ( this.sink instanceof EmptyObjectSinkAdapter ) {
+ throw new IllegalArgumentException( "Cannot remove a sink, when the list of sinks is null" );
+ }
+
+ if ( this.sink instanceof SingleObjectSinkAdapter ) {
+ this.sink = EmptyObjectSinkAdapter.getInstance();
+ } else {
+ final CompositeObjectSinkAdapter sinkAdapter = (CompositeObjectSinkAdapter) this.sink;
+ sinkAdapter.removeObjectSink( objectSink );
+ if ( sinkAdapter.size() == 1 ) {
+ this.sink = new SingleObjectSinkAdapter( sinkAdapter.getSinks()[0] );
+ }
+ }
+ }
+
+ public abstract void updateSink(ObjectSink sink,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory);
+
+ public void networkUpdated() {
+ this.source.networkUpdated();
+ }
+
+ public ObjectSinkPropagator getSinkPropagator() {
+ return this.sink;
+ }
+
+ public boolean isInUse() {
+ return this.sink.size() > 0;
+ }
+}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTupleSinkNode.java (from rev 19178, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkNode.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTupleSinkNode.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTupleSinkNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -0,0 +1,60 @@
+package org.drools.reteoo;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Items placed in a <code>LinkedList<code> must implement this interface .
+ *
+ * @see LeftTupleSinkNodeList
+ *
+ * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
+ * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
+ */
+public interface ObjectTupleSinkNode
+ extends
+ ObjectSink {
+
+ /**
+ * Returns the next node
+ * @return
+ * The next LinkedListNode
+ */
+
+ public ObjectTupleSinkNode getNextObjectSinkNode();
+
+ /**
+ * Sets the next node
+ * @param next
+ * The next LinkedListNode
+ */
+ public void setNextObjectSinkNode(ObjectTupleSinkNode next);
+
+ /**
+ * Returns the previous node
+ * @return
+ * The previous LinkedListNode
+ */
+ public ObjectTupleSinkNode getPreviousObjectSinkNode();
+
+ /**
+ * Sets the previous node
+ * @param previous
+ * The previous LinkedListNode
+ */
+ public void setPreviousObjectSinkNode(ObjectTupleSinkNode previous);
+
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -31,8 +31,8 @@
public void resetCache();
public boolean isAssignableFrom(Object object);
-
+
public boolean isActive();
-
+
public boolean isEvent();
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -59,9 +59,9 @@
* @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
* @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
*/
-public class ObjectTypeNode extends RightTupleSource
+public class ObjectTypeNode extends ObjectSource
implements
- RightTupleSink,
+ ObjectSink,
Externalizable,
NodeMemory
@@ -173,9 +173,9 @@
false );
}
- this.sink.propagateAssertFact( factHandle,
- context,
- workingMemory );
+ this.sink.propagateAssertObject( factHandle,
+ context,
+ workingMemory );
}
public void retractRightTuple(final RightTuple rightTuple,
@@ -195,9 +195,9 @@
* @param workingMemory
* The working memory session.
*/
- public void retractRightTuple(final InternalFactHandle factHandle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ public void retractObject(final InternalFactHandle factHandle,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
if ( context.getType() == PropagationContext.MODIFICATION && this.skipOnModify && context.getDormantActivations() == 0 ) {
return;
@@ -223,7 +223,7 @@
factHandle.setLeftTuple( null );
}
- public void updateSink(final RightTupleSink sink,
+ public void updateSink(final ObjectSink sink,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
@@ -288,7 +288,7 @@
final BaseNode node,
final InternalWorkingMemory[] workingMemories) {
if ( !node.isInUse() ) {
- removeObjectSink( (RightTupleSink) node );
+ removeObjectSink( (ObjectSink) node );
}
}
@@ -337,14 +337,14 @@
/**
* @inheritDoc
*/
- protected void addObjectSink(final RightTupleSink objectSink) {
+ protected void addObjectSink(final ObjectSink objectSink) {
super.addObjectSink( objectSink );
}
/**
* @inheritDoc
*/
- protected void removeObjectSink(final RightTupleSink objectSink) {
+ protected void removeObjectSink(final ObjectSink objectSink) {
super.removeObjectSink( objectSink );
}
@@ -366,8 +366,8 @@
} else if ( sinks[i] instanceof EvalConditionNode ) {
hasConstraints = this.usesDeclaration( ((EvalConditionNode) sinks[i]).getCondition() );
}
- if ( !hasConstraints && sinks[i] instanceof RightTupleSource ) {
- hasConstraints = !this.canSkipOnModify( ((RightTupleSource) sinks[i]).getSinkPropagator().getSinks() );
+ if ( !hasConstraints && sinks[i] instanceof ObjectSource ) {
+ hasConstraints = !this.canSkipOnModify( ((ObjectSource) sinks[i]).getSinkPropagator().getSinks() );
} else if ( !hasConstraints && sinks[i] instanceof LeftTupleSource ) {
hasConstraints = !this.canSkipOnModify( ((LeftTupleSource) sinks[i]).getSinkPropagator().getSinks() );
}
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-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -40,19 +40,19 @@
* @author etirelli
*
*/
-public class PropagationQueuingNode extends RightTupleSource
+public class PropagationQueuingNode extends ObjectSource
implements
- RightTupleSinkNode,
+ ObjectTupleSinkNode,
NodeMemory {
- private static final long serialVersionUID = -615639068150958767L;
+ private static final long serialVersionUID = -615639068150958767L;
// should we make this one configurable?
- private static final int PROPAGATION_SLICE_LIMIT = 1000;
+ private static final int PROPAGATION_SLICE_LIMIT = 1000;
- private RightTupleSinkNode previousObjectSinkNode;
- private RightTupleSinkNode nextObjectSinkNode;
- private PropagateAction action;
+ private ObjectTupleSinkNode previousObjectSinkNode;
+ private ObjectTupleSinkNode nextObjectSinkNode;
+ private PropagateAction action;
public PropagationQueuingNode() {
}
@@ -68,7 +68,7 @@
* @param hasMemory true if node shall be configured with local memory. False otherwise.
*/
public PropagationQueuingNode(final int id,
- final RightTupleSource objectSource,
+ final ObjectSource objectSource,
final BuildContext context) {
super( id,
objectSource,
@@ -76,25 +76,26 @@
this.action = new PropagateAction( this );
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- previousObjectSinkNode = (RightTupleSinkNode)in.readObject();
- nextObjectSinkNode = (RightTupleSinkNode)in.readObject();
- action = (PropagateAction)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ previousObjectSinkNode = (ObjectTupleSinkNode) in.readObject();
+ nextObjectSinkNode = (ObjectTupleSinkNode) in.readObject();
+ action = (PropagateAction) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeObject(previousObjectSinkNode);
- out.writeObject(nextObjectSinkNode);
- out.writeObject(action);
+ super.writeExternal( out );
+ out.writeObject( previousObjectSinkNode );
+ out.writeObject( nextObjectSinkNode );
+ out.writeObject( action );
}
/**
- * @see org.drools.reteoo.RightTupleSource#updateSink(org.drools.reteoo.RightTupleSink, org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
+ * @see org.drools.reteoo.ObjectSource#updateSink(org.drools.reteoo.ObjectSink, org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
*/
@Override
- public void updateSink(RightTupleSink sink,
+ public void updateSink(ObjectSink sink,
PropagationContext context,
InternalWorkingMemory workingMemory) {
@@ -107,8 +108,8 @@
// as this node is simply a queue, ask object source to update the child sink directly
this.source.updateSink( sink,
- context,
- workingMemory );
+ context,
+ workingMemory );
}
/**
@@ -137,7 +138,7 @@
final BaseNode node,
final InternalWorkingMemory[] workingMemories) {
if ( !node.isInUse() ) {
- removeObjectSink( (RightTupleSink) node );
+ removeObjectSink( (ObjectSink) node );
}
if ( !this.isInUse() ) {
for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
@@ -145,41 +146,41 @@
}
}
this.source.remove( context,
- builder,
- this,
- workingMemories );
+ builder,
+ this,
+ workingMemories );
}
/**
- * @see org.drools.reteoo.RightTupleSinkNode#getNextRightTupleSinkNode()
+ * @see org.drools.reteoo.ObjectTupleSinkNode#getNextObjectSinkNode()
*/
- public RightTupleSinkNode getNextRightTupleSinkNode() {
+ public ObjectTupleSinkNode getNextObjectSinkNode() {
return this.nextObjectSinkNode;
}
/**
- * @see org.drools.reteoo.RightTupleSinkNode#getPreviousRightTupleSinkNode()
+ * @see org.drools.reteoo.ObjectTupleSinkNode#getPreviousObjectSinkNode()
*/
- public RightTupleSinkNode getPreviousRightTupleSinkNode() {
+ public ObjectTupleSinkNode getPreviousObjectSinkNode() {
return this.previousObjectSinkNode;
}
/**
- * @see org.drools.reteoo.RightTupleSinkNode#setNextRightTupleSinkNode(org.drools.reteoo.RightTupleSinkNode)
+ * @see org.drools.reteoo.ObjectTupleSinkNode#setNextObjectSinkNode(org.drools.reteoo.ObjectTupleSinkNode)
*/
- public void setNextRightTupleSinkNode(RightTupleSinkNode next) {
+ public void setNextObjectSinkNode(ObjectTupleSinkNode next) {
this.nextObjectSinkNode = next;
}
/**
- * @see org.drools.reteoo.RightTupleSinkNode#setPreviousRightTupleSinkNode(org.drools.reteoo.RightTupleSinkNode)
+ * @see org.drools.reteoo.ObjectTupleSinkNode#setPreviousObjectSinkNode(org.drools.reteoo.ObjectTupleSinkNode)
*/
- public void setPreviousRightTupleSinkNode(RightTupleSinkNode previous) {
+ public void setPreviousObjectSinkNode(ObjectTupleSinkNode previous) {
this.previousObjectSinkNode = previous;
}
/**
- * @see org.drools.reteoo.RightTupleSink#assertObject(InternalFactHandle, org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
+ * @see org.drools.reteoo.ObjectSink#assertObject(InternalFactHandle, org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
*/
public void assertObject(InternalFactHandle factHandle,
PropagationContext context,
@@ -196,14 +197,14 @@
}
/**
- * @see org.drools.reteoo.RightTupleSink#isObjectMemoryEnabled()
+ * @see org.drools.reteoo.ObjectSink#isObjectMemoryEnabled()
*/
public boolean isObjectMemoryEnabled() {
return true;
}
/**
- * @see org.drools.reteoo.RightTupleSink#retractObject(org.drools.common.InternalFactHandle, org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
+ * @see org.drools.reteoo.ObjectSink#retractObject(org.drools.common.InternalFactHandle, org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
*/
public void retractObject(InternalFactHandle handle,
PropagationContext context,
@@ -236,11 +237,12 @@
// we limit the propagation to avoid a hang when this queue is never empty
Action next = memory.getNext();
- for( int counter = 0; next != null && counter < PROPAGATION_SLICE_LIMIT; next = memory.getNext(), counter++ ) {
- next.execute( this.sink, workingMemory );
+ for ( int counter = 0; next != null && counter < PROPAGATION_SLICE_LIMIT; next = memory.getNext(), counter++ ) {
+ next.execute( this.sink,
+ workingMemory );
}
- if( memory.hasNext() ) {
+ if ( memory.hasNext() ) {
// add action to the queue again.
memory.isQueued().set( true );
workingMemory.queueWorkingMemoryAction( this.action );
@@ -248,7 +250,7 @@
}
/**
- * @see org.drools.reteoo.RightTupleSink#setObjectMemoryEnabled(boolean)
+ * @see org.drools.reteoo.ObjectSink#setObjectMemoryEnabled(boolean)
*/
public void setObjectMemoryEnabled(boolean objectMemoryOn) {
throw new UnsupportedOperationException( "PropagationQueueingNode must have its node memory enabled." );
@@ -280,14 +282,15 @@
this.isQueued = new AtomicBoolean( false );
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- queue = (ConcurrentLinkedQueue<Action>)in.readObject();
- isQueued = (AtomicBoolean)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ queue = (ConcurrentLinkedQueue<Action>) in.readObject();
+ isQueued = (AtomicBoolean) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(queue);
- out.writeObject(isQueued);
+ out.writeObject( queue );
+ out.writeObject( isQueued );
}
public boolean isEmpty() {
@@ -329,17 +332,18 @@
this.context = context;
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- handle = (InternalFactHandle)in.readObject();
- context = (PropagationContext)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ handle = (InternalFactHandle) in.readObject();
+ context = (PropagationContext) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(handle);
- out.writeObject(context);
+ out.writeObject( handle );
+ out.writeObject( context );
}
- public abstract void execute(final RightTupleSinkPropagator sink,
+ public abstract void execute(final ObjectSinkPropagator sink,
final InternalWorkingMemory workingMemory);
}
@@ -352,9 +356,9 @@
context );
}
- public void execute(final RightTupleSinkPropagator sink,
+ public void execute(final ObjectSinkPropagator sink,
final InternalWorkingMemory workingMemory) {
- sink.propagateAssertFact( this.handle,
+ sink.propagateAssertObject( this.handle,
this.context,
workingMemory );
}
@@ -366,13 +370,14 @@
public RetractAction() {
}
+
public RetractAction(final InternalFactHandle handle,
final PropagationContext context) {
super( handle,
context );
}
- public void execute(final RightTupleSinkPropagator sink,
+ public void execute(final ObjectSinkPropagator sink,
final InternalWorkingMemory workingMemory) {
sink.propagateRetractObject( this.handle,
this.context,
@@ -404,12 +409,13 @@
this.node = node;
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- node = (PropagationQueuingNode)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ node = (PropagationQueuingNode) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(node);
+ out.writeObject( node );
}
public void execute(InternalWorkingMemory workingMemory) {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/QueryTerminalNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/QueryTerminalNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/QueryTerminalNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -50,15 +50,15 @@
/**
*
*/
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
/** The rule to invoke upon match. */
- private Rule rule;
- private GroupElement subrule;
- private LeftTupleSource tupleSource;
- private boolean tupleMemoryEnabled;
+ private Rule rule;
+ private GroupElement subrule;
+ private LeftTupleSource tupleSource;
+ private boolean tupleMemoryEnabled;
- private LeftTupleSinkNode previousTupleSinkNode;
- private LeftTupleSinkNode nextTupleSinkNode;
+ private LeftTupleSinkNode previousTupleSinkNode;
+ private LeftTupleSinkNode nextTupleSinkNode;
// ------------------------------------------------------------
// Constructors
@@ -88,24 +88,25 @@
// ------------------------------------------------------------
// Instance methods
// ------------------------------------------------------------
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- rule = (Rule)in.readObject();
- subrule = (GroupElement)in.readObject();
- tupleSource = (LeftTupleSource)in.readObject();
- tupleMemoryEnabled = in.readBoolean();
- previousTupleSinkNode = (LeftTupleSinkNode)in.readObject();
- nextTupleSinkNode = (LeftTupleSinkNode)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ rule = (Rule) in.readObject();
+ subrule = (GroupElement) in.readObject();
+ tupleSource = (LeftTupleSource) in.readObject();
+ tupleMemoryEnabled = in.readBoolean();
+ previousTupleSinkNode = (LeftTupleSinkNode) in.readObject();
+ nextTupleSinkNode = (LeftTupleSinkNode) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeObject(rule);
- out.writeObject(subrule);
- out.writeObject(tupleSource);
- out.writeBoolean(tupleMemoryEnabled);
- out.writeObject(previousTupleSinkNode);
- out.writeObject(nextTupleSinkNode);
+ super.writeExternal( out );
+ out.writeObject( rule );
+ out.writeObject( subrule );
+ out.writeObject( tupleSource );
+ out.writeBoolean( tupleMemoryEnabled );
+ out.writeObject( previousTupleSinkNode );
+ out.writeObject( nextTupleSinkNode );
}
/**
@@ -132,8 +133,8 @@
* If an error occurs while asserting.
*/
public void assertLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final LinkedList list = (LinkedList) workingMemory.getNodeMemory( this );
if ( list.isEmpty() ) {
((ReteooWorkingMemory) workingMemory).setQueryResults( this.rule.getName(),
@@ -143,8 +144,8 @@
}
public void retractLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
}
public String toString() {
@@ -177,7 +178,7 @@
public void networkUpdated() {
this.tupleSource.networkUpdated();
}
-
+
protected void doRemove(final RuleRemovalContext context,
final ReteooBuilder builder,
final BaseNode node,
@@ -186,7 +187,7 @@
workingMemories[i].clearNodeMemory( this );
}
- if( ! context.alreadyVisited( this.tupleSource ) ) {
+ if ( !context.alreadyVisited( this.tupleSource ) ) {
this.tupleSource.remove( context,
builder,
this,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -53,10 +53,10 @@
* @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
* @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
*/
-public class Rete extends RightTupleSource
+public class Rete extends ObjectSource
implements
Externalizable,
- RightTupleSink {
+ ObjectSink {
// ------------------------------------------------------------
// Instance members
// ------------------------------------------------------------
@@ -64,14 +64,14 @@
/**
*
*/
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
private Map<EntryPoint, EntryPointNode> entryPoints;
- private transient InternalRuleBase ruleBase;
+ private transient InternalRuleBase ruleBase;
public Rete() {
- this(null);
+ this( null );
}
// ------------------------------------------------------------
@@ -105,7 +105,8 @@
final InternalWorkingMemory workingMemory) {
EntryPoint entryPoint = context.getEntryPoint();
EntryPointNode node = this.entryPoints.get( entryPoint );
- ObjectTypeConf typeConf = ((InternalWorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint( entryPoint.getEntryPointId() )).getObjectTypeConfigurationRegistry().getObjectTypeConf( entryPoint, factHandle.getObject() );
+ ObjectTypeConf typeConf = ((InternalWorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint( entryPoint.getEntryPointId() )).getObjectTypeConfigurationRegistry().getObjectTypeConf( entryPoint,
+ factHandle.getObject() );
node.assertObject( factHandle,
context,
typeConf,
@@ -126,7 +127,8 @@
final InternalWorkingMemory workingMemory) {
EntryPoint entryPoint = context.getEntryPoint();
EntryPointNode node = this.entryPoints.get( entryPoint );
- ObjectTypeConf typeConf = ((InternalWorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint( entryPoint.getEntryPointId() )).getObjectTypeConfigurationRegistry().getObjectTypeConf( entryPoint, handle.getObject() );
+ ObjectTypeConf typeConf = ((InternalWorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint( entryPoint.getEntryPointId() )).getObjectTypeConfigurationRegistry().getObjectTypeConf( entryPoint,
+ handle.getObject() );
node.retractObject( handle,
context,
typeConf,
@@ -142,13 +144,13 @@
* <code>Objects</code>. Rete only accepts <code>ObjectTypeNode</code>s
* as parameters to this method, though.
*/
- protected void addObjectSink(final RightTupleSink objectSink) {
+ protected void addObjectSink(final ObjectSink objectSink) {
final EntryPointNode node = (EntryPointNode) objectSink;
this.entryPoints.put( node.getEntryPoint(),
node );
}
- protected void removeObjectSink(final RightTupleSink objectSink) {
+ protected void removeObjectSink(final ObjectSink objectSink) {
final EntryPointNode node = (EntryPointNode) objectSink;
this.entryPoints.remove( node.getEntryPoint() );
}
@@ -173,14 +175,14 @@
removeObjectSink( entryPointNode );
}
- public EntryPointNode getEntryPointNode( final EntryPoint entryPoint ) {
+ public EntryPointNode getEntryPointNode(final EntryPoint entryPoint) {
return this.entryPoints.get( entryPoint );
}
public List<ObjectTypeNode> getObjectTypeNodes() {
List<ObjectTypeNode> allNodes = new LinkedList<ObjectTypeNode>();
- for( EntryPointNode node : this.entryPoints.values() ) {
- allNodes.addAll(node.getObjectTypeNodes().values());
+ for ( EntryPointNode node : this.entryPoints.values() ) {
+ allNodes.addAll( node.getObjectTypeNodes().values() );
}
return allNodes;
}
@@ -210,7 +212,7 @@
return this.entryPoints.equals( other.entryPoints );
}
- public void updateSink(final RightTupleSink sink,
+ public void updateSink(final ObjectSink sink,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
// nothing to do, since Rete object itself holds no facts to propagate.
@@ -225,14 +227,15 @@
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(entryPoints);
- out.writeObject(ruleBase);
- super.writeExternal(out);
+ out.writeObject( entryPoints );
+ out.writeObject( ruleBase );
+ super.writeExternal( out );
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
entryPoints = (Map<EntryPoint, EntryPointNode>) in.readObject();
- ruleBase = (InternalRuleBase)in.readObject();
- super.readExternal(in);
+ ruleBase = (InternalRuleBase) in.readObject();
+ super.readExternal( in );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteStatelessSessionResult.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteStatelessSessionResult.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteStatelessSessionResult.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -16,37 +16,44 @@
import org.drools.util.ObjectHashMap;
import org.drools.util.AbstractHashTable.HashTableIterator;
-public class ReteStatelessSessionResult implements StatelessSessionResult, Externalizable {
+public class ReteStatelessSessionResult
+ implements
+ StatelessSessionResult,
+ Externalizable {
private transient InternalWorkingMemory workingMemory;
// @TODO ObjectStore is currently too heavy for serialisation, but done to fix for now
- private ObjectStore objectStore;
- private GlobalResolver globalResolver;
+ private ObjectStore objectStore;
+ private GlobalResolver globalResolver;
public ReteStatelessSessionResult() {
}
- public ReteStatelessSessionResult(InternalWorkingMemory workingMemory, GlobalResolver globalResolver) {
+ public ReteStatelessSessionResult(InternalWorkingMemory workingMemory,
+ GlobalResolver globalResolver) {
this.workingMemory = workingMemory;
this.objectStore = workingMemory.getObjectStore();
this.globalResolver = globalResolver;
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- workingMemory = (InternalWorkingMemory)in.readObject();
- objectStore = (ObjectStore)in.readObject();
- globalResolver = (GlobalResolver)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ workingMemory = (InternalWorkingMemory) in.readObject();
+ objectStore = (ObjectStore) in.readObject();
+ globalResolver = (GlobalResolver) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(workingMemory);
- out.writeObject(objectStore);
- out.writeObject(globalResolver);
+ out.writeObject( workingMemory );
+ out.writeObject( objectStore );
+ out.writeObject( globalResolver );
}
+
public QueryResults getQueryResults(String query) {
return this.workingMemory.getQueryResults( query );
}
- public QueryResults getQueryResults(final String query, final Object[] arguments) {
+ public QueryResults getQueryResults(final String query,
+ final Object[] arguments) {
return this.workingMemory.getQueryResults( query,
arguments );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -91,6 +91,7 @@
public ReteooBuilder() {
}
+
/**
* Construct a <code>Builder</code> against an existing <code>Rete</code>
* network.
@@ -262,77 +263,79 @@
this.recycledIds = new LinkedList<Integer>();
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- recycledIds = (Queue<Integer>)in.readObject();
- nextId = in.readInt();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ recycledIds = (Queue<Integer>) in.readObject();
+ nextId = in.readInt();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(recycledIds);
- out.writeInt(nextId);
+ out.writeObject( recycledIds );
+ out.writeInt( nextId );
}
public int getNextId() {
Integer id = this.recycledIds.poll();
- if( id == null ) {
+ if ( id == null ) {
return this.nextId++;
}
return id.intValue();
}
- public void releaseId( int id ) {
- this.recycledIds.add( new Integer(id) );
+ public void releaseId(int id) {
+ this.recycledIds.add( new Integer( id ) );
}
public int getLastId() {
- return this.nextId-1;
+ return this.nextId - 1;
}
}
public void writeExternal(ObjectOutput out) throws IOException {
- boolean isDrools = out instanceof DroolsObjectOutputStream;
- DroolsObjectOutputStream droolsStream;
- ByteArrayOutputStream bytes;
+ boolean isDrools = out instanceof DroolsObjectOutputStream;
+ DroolsObjectOutputStream droolsStream;
+ ByteArrayOutputStream bytes;
- if (isDrools) {
- bytes = null;
- droolsStream = (DroolsObjectOutputStream)out;
+ if ( isDrools ) {
+ bytes = null;
+ droolsStream = (DroolsObjectOutputStream) out;
} else {
- bytes = new ByteArrayOutputStream();
- droolsStream = new DroolsObjectOutputStream(bytes);
+ bytes = new ByteArrayOutputStream();
+ droolsStream = new DroolsObjectOutputStream( bytes );
}
- droolsStream.writeObject(rules);
- droolsStream.writeObject(idGenerator);
- droolsStream.writeBoolean(ordered);
- droolsStream.writeObject(ruleBase);
- if (!isDrools) {
+ droolsStream.writeObject( rules );
+ droolsStream.writeObject( idGenerator );
+ droolsStream.writeBoolean( ordered );
+ droolsStream.writeObject( ruleBase );
+ if ( !isDrools ) {
bytes.close();
- out.writeObject(bytes.toByteArray());
+ out.writeObject( bytes.toByteArray() );
}
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- boolean isDrools = in instanceof DroolsObjectInputStream;
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ boolean isDrools = in instanceof DroolsObjectInputStream;
DroolsObjectInputStream droolsStream;
- ByteArrayInputStream bytes;
+ ByteArrayInputStream bytes;
- if (isDrools) {
- bytes = null;
- droolsStream = (DroolsObjectInputStream)in;
+ if ( isDrools ) {
+ bytes = null;
+ droolsStream = (DroolsObjectInputStream) in;
} else {
- bytes = new ByteArrayInputStream((byte[])in.readObject());
- droolsStream = new DroolsObjectInputStream(bytes);
+ bytes = new ByteArrayInputStream( (byte[]) in.readObject() );
+ droolsStream = new DroolsObjectInputStream( bytes );
}
- this.rules = (Map)in.readObject();
- this.idGenerator = (IdGenerator)in.readObject();
- this.ordered = in.readBoolean();
- this.ruleBase = (InternalRuleBase)droolsStream.readObject();
- if (!isDrools) {
+ this.rules = (Map) in.readObject();
+ this.idGenerator = (IdGenerator) in.readObject();
+ this.ordered = in.readBoolean();
+ this.ruleBase = (InternalRuleBase) droolsStream.readObject();
+ if ( !isDrools ) {
bytes.close();
}
- this.ruleBuilder = new ReteooRuleBuilder();
+ this.ruleBuilder = new ReteooRuleBuilder();
}
}
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-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -32,17 +32,18 @@
public class ReteooFactHandleFactory extends AbstractFactHandleFactory {
private static final long serialVersionUID = 400L;
-
+
public ReteooFactHandleFactory() {
super();
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
+ super.writeExternal( out );
}
/* (non-Javadoc)
@@ -52,14 +53,14 @@
final Object object,
final long recency,
final boolean isEvent,
- final WorkingMemory workingMemory ) {
+ final WorkingMemory workingMemory) {
if ( isEvent ) {
SessionClock clock = ((TemporalSession) workingMemory).getSessionClock();
return new EventFactHandle( id,
object,
recency,
clock.getCurrentTime(),
- 0 ); // primitive events have 0 duration
+ 0 ); // primitive events have 0 duration
} else {
return new DefaultFactHandle( id,
object,
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-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -152,8 +152,8 @@
*/
public void writeExternal(final ObjectOutput stream) throws IOException {
super.writeExternal( stream );
- stream.writeObject(this.reteooBuilder);
- stream.writeObject(this.rete);
+ stream.writeObject( this.reteooBuilder );
+ stream.writeObject( this.rete );
}
/**
@@ -312,7 +312,7 @@
public int getNodeCount() {
// may start in 0
- return this.reteooBuilder.getIdGenerator().getLastId()+1;
+ return this.reteooBuilder.getIdGenerator().getLastId() + 1;
}
public static class InitialFactHandleDummyObject
@@ -320,7 +320,8 @@
Externalizable {
private static final long serialVersionUID = 400L;
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
}
public void writeExternal(ObjectOutput out) throws IOException {
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-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -8,8 +8,7 @@
import org.drools.WorkingMemoryEntryPoint;
import org.drools.FactHandle;
import org.drools.StatefulSession;
-import org.drools.common.InternalRuleBase;
-//import org.drools.common.AbstractWorkingMemory.EntryPointInterfaceImpl;
+import org.drools.common.InternalRuleBase; //import org.drools.common.AbstractWorkingMemory.EntryPointInterfaceImpl;
import org.drools.concurrent.AssertObject;
import org.drools.concurrent.AssertObjects;
import org.drools.concurrent.ExecutorService;
@@ -27,10 +26,10 @@
implements
StatefulSession {
- private static final long serialVersionUID = -5360554247241558374L;
+ private static final long serialVersionUID = -5360554247241558374L;
private transient ExecutorService executor;
- private transient List ruleBaseListeners;
+ private transient List ruleBaseListeners;
public ReteooStatefulSession() {
@@ -55,7 +54,7 @@
}
public Future asyncUpdate(final FactHandle factHandle,
- final Object object) {
+ final Object object) {
return this.executor.submit( new UpdateObject( factHandle,
object ) );
}
@@ -89,7 +88,7 @@
this.workingMemoryEventSupport.reset();
this.agendaEventSupport.reset();
this.workflowEventSupport.reset();
- for( Iterator it = this.__ruleBaseEventListeners.iterator(); it.hasNext(); ) {
+ for ( Iterator it = this.__ruleBaseEventListeners.iterator(); it.hasNext(); ) {
this.ruleBase.removeEventListener( (RuleBaseEventListener) it.next() );
}
this.executor.shutDown();
@@ -108,13 +107,13 @@
}
return this.ruleBaseListeners;
}
-
-// public StatefulSession getEntryPoint(String id) {
-// EntryPoint ep = new EntryPoint( id );
-// return new EntryPointInterfaceImpl( ep,
-// this );
-// }
+ // public StatefulSession getEntryPoint(String id) {
+ // EntryPoint ep = new EntryPoint( id );
+ // return new EntryPointInterfaceImpl( ep,
+ // this );
+ // }
+
public ExecutorService getExecutorService() {
return executor;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -35,7 +35,8 @@
public class ReteooStatelessSession
implements
- StatelessSession, Externalizable {
+ StatelessSession,
+ Externalizable {
//private WorkingMemory workingMemory;
private InternalRuleBase ruleBase;
@@ -58,19 +59,21 @@
this.ruleBase = ruleBase;
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- ruleBase = (InternalRuleBase)in.readObject();
- agendaFilter = (AgendaFilter)in.readObject();
- globalResolver = (GlobalResolver)in.readObject();
- globalExporter = (GlobalExporter)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ ruleBase = (InternalRuleBase) in.readObject();
+ agendaFilter = (AgendaFilter) in.readObject();
+ globalResolver = (GlobalResolver) in.readObject();
+ globalExporter = (GlobalExporter) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(ruleBase);
- out.writeObject(agendaFilter);
- out.writeObject(globalResolver);
- out.writeObject(globalExporter);
+ out.writeObject( ruleBase );
+ out.writeObject( agendaFilter );
+ out.writeObject( globalResolver );
+ out.writeObject( globalExporter );
}
+
public InternalWorkingMemory newWorkingMemory() {
synchronized ( this.ruleBase.getPackagesMap() ) {
InternalWorkingMemory wm = new ReteooWorkingMemory( this.ruleBase.nextWorkingMemoryCounter(),
@@ -81,7 +84,9 @@
wm.setAgendaEventSupport( this.agendaEventSupport );
wm.setRuleFlowEventSupport( ruleFlowEventSupport );
- final InitialFactHandle handle = new InitialFactHandle( wm.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(), false, wm ) );
+ final InitialFactHandle handle = new InitialFactHandle( wm.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(),
+ false,
+ wm ) );
wm.queueWorkingMemoryAction( new WorkingMemoryReteAssertAction( handle,
false,
@@ -187,7 +192,7 @@
InternalWorkingMemory wm = newWorkingMemory();
final AssertObject assertObject = new AssertObject( object );
- ExecutorService executor = ExecutorServiceFactory.createExecutorService( this.ruleBase.getConfiguration().getExecutorService() );
+ ExecutorService executor = ExecutorServiceFactory.createExecutorService( this.ruleBase.getConfiguration().getExecutorService() );
executor.setCommandExecutor( new CommandExecutor( wm ) );
executor.submit( assertObject );
executor.submit( new FireAllRules( this.agendaFilter ) );
@@ -197,7 +202,7 @@
InternalWorkingMemory wm = newWorkingMemory();
final AssertObjects assertObjects = new AssertObjects( array );
- ExecutorService executor = ExecutorServiceFactory.createExecutorService( this.ruleBase.getConfiguration().getExecutorService() );
+ ExecutorService executor = ExecutorServiceFactory.createExecutorService( this.ruleBase.getConfiguration().getExecutorService() );
executor.setCommandExecutor( new CommandExecutor( wm ) );
executor.submit( assertObjects );
executor.submit( new FireAllRules( this.agendaFilter ) );
@@ -207,7 +212,7 @@
InternalWorkingMemory wm = newWorkingMemory();
final AssertObjects assertObjects = new AssertObjects( collection );
- ExecutorService executor = ExecutorServiceFactory.createExecutorService( this.ruleBase.getConfiguration().getExecutorService() );
+ ExecutorService executor = ExecutorServiceFactory.createExecutorService( this.ruleBase.getConfiguration().getExecutorService() );
executor.setCommandExecutor( new CommandExecutor( wm ) );
executor.submit( assertObjects );
executor.submit( new FireAllRules( this.agendaFilter ) );
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-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooTemporalSession.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -52,14 +52,15 @@
this.sessionClock = clock;
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- sessionClock = (T)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ sessionClock = (T) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeObject(sessionClock);
+ super.writeExternal( out );
+ out.writeObject( sessionClock );
}
public T getSessionClock() {
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-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -50,7 +50,9 @@
* @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
* @author <a href="mailto:simon at redhillconsulting.com.au">Simon Harris</a>
*/
-public class ReteooWorkingMemory extends AbstractWorkingMemory implements Externalizable {
+public class ReteooWorkingMemory extends AbstractWorkingMemory
+ implements
+ Externalizable {
/**
*
@@ -68,27 +70,33 @@
* The backing rule-base.
*/
public ReteooWorkingMemory(final int id,
- final InternalRuleBase ruleBase ) {
+ final InternalRuleBase ruleBase) {
super( id,
ruleBase,
ruleBase.newFactHandleFactory() );
this.agenda = new DefaultAgenda( this );
- }
-
+ }
+
public QueryResults getQueryResults(final String query) {
- return getQueryResults( query, null );
+ return getQueryResults( query,
+ null );
}
- public QueryResults getQueryResults(final String query, final Object[] arguments) {
+ public QueryResults getQueryResults(final String query,
+ final Object[] arguments) {
- Object object = new DroolsQuery( query, arguments );
- InternalFactHandle handle = this.handleFactory.newFactHandle( object, false, this );
+ Object object = new DroolsQuery( query,
+ arguments );
+ InternalFactHandle handle = this.handleFactory.newFactHandle( object,
+ false,
+ this );
insert( handle,
object,
null,
null,
- this.typeConfReg.getObjectTypeConf( this.entryPoint, object ));
+ this.typeConfReg.getObjectTypeConf( this.entryPoint,
+ object ) );
final QueryTerminalNode node = (QueryTerminalNode) this.queryResults.remove( query );
Query queryObj = null;
@@ -124,9 +132,6 @@
this.handleFactory.destroyFactHandle( handle );
}
-
-
-
return new QueryResults( list,
queryObj,
this );
@@ -171,20 +176,21 @@
this.activationOrigin = activationOrigin;
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- factHandle = (InternalFactHandle)in.readObject();
- removeLogical = in.readBoolean();
- updateEqualsMap = in.readBoolean();
- ruleOrigin = (Rule)in.readObject();
- activationOrigin = (Activation)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ factHandle = (InternalFactHandle) in.readObject();
+ removeLogical = in.readBoolean();
+ updateEqualsMap = in.readBoolean();
+ ruleOrigin = (Rule) in.readObject();
+ activationOrigin = (Activation) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(factHandle);
- out.writeBoolean(removeLogical);
- out.writeBoolean(updateEqualsMap);
- out.writeObject(ruleOrigin);
- out.writeObject(activationOrigin);
+ out.writeObject( factHandle );
+ out.writeBoolean( removeLogical );
+ out.writeBoolean( updateEqualsMap );
+ out.writeObject( ruleOrigin );
+ out.writeObject( activationOrigin );
}
public void execute(InternalWorkingMemory workingMemory) {
@@ -193,11 +199,11 @@
PropagationContext.ASSERTION,
this.ruleOrigin,
this.activationOrigin );
- ReteooRuleBase ruleBase = ( ReteooRuleBase ) workingMemory.getRuleBase();
+ ReteooRuleBase ruleBase = (ReteooRuleBase) workingMemory.getRuleBase();
ruleBase.assertObject( this.factHandle,
- this.factHandle.getObject(),
- context,
- workingMemory );
+ this.factHandle.getObject(),
+ context,
+ workingMemory );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -42,19 +42,19 @@
* @author <a href="mailto:etirelli at redhat.com">Edson Tirelli</a>
*
*/
-public class RightInputAdapterNode extends RightTupleSource
+public class RightInputAdapterNode extends ObjectSource
implements
LeftTupleSinkNode,
NodeMemory {
private static final long serialVersionUID = 400L;
- private LeftTupleSource tupleSource;
+ private LeftTupleSource tupleSource;
- protected boolean tupleMemoryEnabled;
+ protected boolean tupleMemoryEnabled;
- private LeftTupleSinkNode previousTupleSinkNode;
- private LeftTupleSinkNode nextTupleSinkNode;
+ private LeftTupleSinkNode previousTupleSinkNode;
+ private LeftTupleSinkNode nextTupleSinkNode;
public RightInputAdapterNode() {
}
@@ -76,22 +76,24 @@
this.tupleMemoryEnabled = context.isTupleMemoryEnabled();
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- tupleSource = (LeftTupleSource)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ tupleSource = (LeftTupleSource) in.readObject();
tupleMemoryEnabled = in.readBoolean();
- previousTupleSinkNode = (LeftTupleSinkNode)in.readObject();
- nextTupleSinkNode = (LeftTupleSinkNode)in.readObject();
+ previousTupleSinkNode = (LeftTupleSinkNode) in.readObject();
+ nextTupleSinkNode = (LeftTupleSinkNode) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeObject(tupleSource);
- out.writeBoolean(tupleMemoryEnabled);
- out.writeObject(previousTupleSinkNode);
- out.writeObject(nextTupleSinkNode);
+ super.writeExternal( out );
+ out.writeObject( tupleSource );
+ out.writeBoolean( tupleMemoryEnabled );
+ out.writeObject( previousTupleSinkNode );
+ out.writeObject( nextTupleSinkNode );
}
+
/**
* Creates and return the node memory
*/
@@ -111,11 +113,13 @@
* the <code>WorkingMemory</code> session.
*/
public void assertLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
// creating a dummy fact handle to wrap the tuple
- final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( tuple, false, workingMemory );
+ final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( tuple,
+ false,
+ workingMemory );
if ( this.tupleMemoryEnabled ) {
final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );
@@ -125,7 +129,7 @@
}
// propagate it
- this.sink.propagateAssertFact( handle,
+ this.sink.propagateAssertObject( handle,
context,
workingMemory );
}
@@ -135,8 +139,8 @@
* the fact created for it
*/
public void retractLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );
@@ -171,12 +175,12 @@
workingMemory );
}
}
-
+
public void networkUpdated() {
this.tupleSource.networkUpdated();
}
- public void updateSink(final RightTupleSink sink,
+ public void updateSink(final ObjectSink sink,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
@@ -197,9 +201,9 @@
final BaseNode node,
final InternalWorkingMemory[] workingMemories) {
if ( !node.isInUse() ) {
- removeObjectSink( (RightTupleSink) node );
+ removeObjectSink( (ObjectSink) node );
}
- if( ! context.alreadyVisited( this.tupleSource ) ) {
+ if ( !context.alreadyVisited( this.tupleSource ) ) {
this.tupleSource.remove( context,
builder,
this,
@@ -252,7 +256,7 @@
}
public int hashCode() {
- return this.tupleSource.hashCode() * 17 + ((this.tupleMemoryEnabled) ? 1234 : 4321 );
+ return this.tupleSource.hashCode() * 17 + ((this.tupleMemoryEnabled) ? 1234 : 4321);
}
/*
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -12,12 +12,12 @@
implements
Entry {
private final InternalFactHandle handle;
-
+
private RightTuple handlePrevious;
private RightTuple handleNext;
private FactHashTable memory;
-
+
private Entry previous;
private Entry next;
@@ -39,14 +39,14 @@
this.handle = handle;
this.hashCode = this.handle.hashCode();
this.sink = sink;
-
-// RightTuple currentFirst = handle.getRightTuple();
-// if ( currentFirst != null ) {
-// currentFirst.handlePrevious = this;
-// this.handleNext = currentFirst;
-// }
-//
-// handle.setRightTuple( this );
+
+ // RightTuple currentFirst = handle.getRightTuple();
+ // if ( currentFirst != null ) {
+ // currentFirst.handlePrevious = this;
+ // this.handleNext = currentFirst;
+ // }
+ //
+ // handle.setRightTuple( this );
}
public RightTuple(RightTuple parent) {
@@ -67,25 +67,25 @@
return this.sink;
}
-// public void unlinkFromRightParent() {
-// if ( this.parent != null ) {
-// if ( this.parentPrevious != null ) {
-// this.parentPrevious.parentNext = this.parentNext;
-// } else {
-// // first one in the chain, so treat differently
-// this.parent.setAlphaChildren( this.parentNext );
-// }
-//
-// if ( this.parentNext != null ) {
-// this.parentNext.parentPrevious = this.parentPrevious;
-// }
-// }
-//
-// this.parent = null;
-// this.parentPrevious = null;
-// this.parentNext = null;
-// this.blocked = null;
-// }
+ // public void unlinkFromRightParent() {
+ // if ( this.parent != null ) {
+ // if ( this.parentPrevious != null ) {
+ // this.parentPrevious.parentNext = this.parentNext;
+ // } else {
+ // // first one in the chain, so treat differently
+ // this.parent.setAlphaChildren( this.parentNext );
+ // }
+ //
+ // if ( this.parentNext != null ) {
+ // this.parentNext.parentPrevious = this.parentPrevious;
+ // }
+ // }
+ //
+ // this.parent = null;
+ // this.parentPrevious = null;
+ // this.parentNext = null;
+ // this.blocked = null;
+ // }
public InternalFactHandle getFactHandle() {
return this.handle;
@@ -97,7 +97,7 @@
public void setBlocked(LeftTuple blocked) {
this.blocked = blocked;
- }
+ }
public FactHashTable getMemory() {
return memory;
@@ -113,7 +113,7 @@
public void setPrevious(Entry previous) {
this.previous = previous;
- }
+ }
public RightTuple getHandlePrevious() {
return handlePrevious;
@@ -184,12 +184,12 @@
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
// TODO Auto-generated method stub
-
+
}
public void writeExternal(ObjectOutput out) throws IOException {
// TODO Auto-generated method stub
-
+
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleMemory.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleMemory.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -6,7 +6,7 @@
public interface RightTupleMemory {
public RightTuple getFirst(LeftTuple leftTuple);
-
+
public RightTuple getLast(LeftTuple leftTuple);
public void add(RightTuple rightTuple);
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -1,64 +0,0 @@
-package org.drools.reteoo;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.common.InternalFactHandle;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.spi.PropagationContext;
-
-/**
- * Receiver of propagated <code>FactHandleImpl</code>s from a
- * <code>ObjectSource</code>.
- *
- * @see ObectSource
- *
- * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
- * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
- *
- */
-public interface RightTupleSink
- extends
- Sink {
-
- /**
- * Assert a new <code>FactHandleImpl</code>.
- *
- * @param factHandle
- * The asserted <code>FactHandle/code>.
- * @param context
- * The <code>PropagationContext</code> of the <code>WorkingMemory<code> action.
- * @param workingMemory
- * the <code>WorkingMemory</code> session.
- */
- void assertObject(InternalFactHandle factHandle,
- PropagationContext context,
- InternalWorkingMemory workingMemory);
-
- /**
- * Retract an existing <code>FactHandleImpl</code>.
- *
- * @param factHandle
- * The <code>FactHandle/code> to retract.
- * @param context
- * The <code>PropagationContext</code> of the <code>WorkingMemory<code> action.
- * @param workingMemory
- * the <code>WorkingMemory</code> session.
- */
- void retractRightTuple(RightTuple rightTuple,
- PropagationContext context,
- InternalWorkingMemory workingMemory);
-}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -1,60 +0,0 @@
-package org.drools.reteoo;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Items placed in a <code>LinkedList<code> must implement this interface .
- *
- * @see LeftTupleSinkNodeList
- *
- * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
- * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
- */
-public interface RightTupleSinkNode
- extends
- RightTupleSink {
-
- /**
- * Returns the next node
- * @return
- * The next LinkedListNode
- */
-
- public RightTupleSinkNode getNextRightTupleSinkNode();
-
- /**
- * Sets the next node
- * @param next
- * The next LinkedListNode
- */
- public void setNextRightTupleSinkNode(RightTupleSinkNode next);
-
- /**
- * Returns the previous node
- * @return
- * The previous LinkedListNode
- */
- public RightTupleSinkNode getPreviousRightTupleSinkNode();
-
- /**
- * Sets the previous node
- * @param previous
- * The previous LinkedListNode
- */
- public void setPreviousRightTupleSinkNode(RightTupleSinkNode previous);
-
-}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkNodeList.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkNodeList.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkNodeList.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -1,243 +0,0 @@
-package org.drools.reteoo;
-
-import java.io.Externalizable;
-import java.io.ObjectInput;
-import java.io.IOException;
-import java.io.ObjectOutput;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * This is a simple linked linked implementation. Each node must implement </code>LinkedListNode<code> so that it references
- * the node before and after it. This way a node can be removed without having to scan the list to find it. This class
- * does not provide an Iterator implementation as its designed for efficiency and not genericity. There are a number of
- * ways to iterate the list.
- * <p>
- * Simple iterator:
- * <pre>
- * for ( LinkedListNode node = list.getFirst(); node != null; node = node.getNext() ) {
- * }
- * </pre>
- *
- * Iterator that pops the first entry:
- * <pre>
- * for ( LinkedListNode node = list.removeFirst(); node != null; node = list.removeFirst() ) {
- * }
- * </pre>
- *
- *
- * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
- * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
- *
- */
-public class RightTupleSinkNodeList
- implements
- Externalizable {
- private static final long serialVersionUID = 400L;
-
- private RightTupleSinkNode firstNode;
- private RightTupleSinkNode lastNode;
-
- private int size;
-
- /**
- * Construct an empty <code>LinkedList</code>
- */
- public RightTupleSinkNodeList() {
-
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- firstNode = (RightTupleSinkNode)in.readObject();
- lastNode = (RightTupleSinkNode)in.readObject();
- size = in.readInt();
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(firstNode);
- out.writeObject(lastNode);
- out.writeInt(size);
- }
- /**
- * Add a <code>ObjectSinkNode</code> to the list. If the <code>LinkedList</code> is empty then the first and
- * last nodes are set to the added node.
- *
- * @param node
- * The <code>ObjectSinkNode</code> to be added
- */
- public void add(final RightTupleSinkNode node) {
- if ( this.firstNode == null ) {
- this.firstNode = node;
- this.lastNode = node;;
- } else {
- this.lastNode.setNextRightTupleSinkNode( node );
- node.setPreviousRightTupleSinkNode( this.lastNode );
- this.lastNode = node;
- }
- this.size++;
- }
-
- /**
- * Removes a <code>ObjectSinkNode</code> from the list. This works by attach the previous reference to the child reference.
- * When the node to be removed is the first node it calls <code>removeFirst()</code>. When the node to be removed is the last node
- * it calls <code>removeLast()</code>.
- *
- * @param node
- * The <code>ObjectSinkNode</code> to be removed.
- */
- public void remove(final RightTupleSinkNode node) {
- if ( (this.firstNode != node) && (this.lastNode != node) ) {
- node.getPreviousRightTupleSinkNode().setNextRightTupleSinkNode( node.getNextRightTupleSinkNode() );
- node.getNextRightTupleSinkNode().setPreviousRightTupleSinkNode( node.getPreviousRightTupleSinkNode() );
- this.size--;
- node.setPreviousRightTupleSinkNode( null );
- node.setNextRightTupleSinkNode( null );
-
- } else {
- if ( this.firstNode == node ) {
- removeFirst();
- } else if ( this.lastNode == node ) {
- removeLast();
- }
- }
- }
-
- /**
- * Return the first node in the list
- * @return
- * The first <code>ObjectSinkNode</code>.
- */
- public final RightTupleSinkNode getFirst() {
- return this.firstNode;
- }
-
- /**
- * Return the last node in the list
- * @return
- * The last <code>ObjectSinkNode</code>.
- */
- public final RightTupleSinkNode getLast() {
- return this.lastNode;
- }
-
- /**
- * Remove the first node from the list. The next node then becomes the first node. If this is the last
- * node then both first and last node references are set to null.
- *
- * @return
- * The first <code>ObjectSinkNode</code>.
- */
- public RightTupleSinkNode removeFirst() {
- if ( this.firstNode == null ) {
- return null;
- }
- final RightTupleSinkNode node = this.firstNode;
- this.firstNode = node.getNextRightTupleSinkNode();
- node.setNextRightTupleSinkNode( null );
- if ( this.firstNode != null ) {
- this.firstNode.setPreviousRightTupleSinkNode( null );
- } else {
- this.lastNode = null;
- }
- this.size--;
- return node;
- }
-
- /**
- * Remove the last node from the list. The previous node then becomes the last node. If this is the last
- * node then both first and last node references are set to null.
- *
- * @return
- * The first <code>ObjectSinkNode</code>.
- */
- public RightTupleSinkNode removeLast() {
- if ( this.lastNode == null ) {
- return null;
- }
- final RightTupleSinkNode node = this.lastNode;
- this.lastNode = node.getPreviousRightTupleSinkNode();
- node.setPreviousRightTupleSinkNode( null );
- if ( this.lastNode != null ) {
- this.lastNode.setNextRightTupleSinkNode( null );
- } else {
- this.firstNode = this.lastNode;
- }
- this.size--;
- return node;
- }
-
- /**
- * @return
- * boolean value indicating the empty status of the list
- */
- public final boolean isEmpty() {
- return (this.firstNode == null);
- }
-
- /**
- * Iterates the list removing all the nodes until there are no more nodes to remove.
- */
- public void clear() {
- while ( removeFirst() != null ) {
- }
- }
-
- /**
- * @return
- * return size of the list as an int
- */
- public final int size() {
- return this.size;
- }
-
- /**
- * Returns a list iterator
- * @return
- */
- public Iterator iterator() {
- return new Iterator() {
- private RightTupleSinkNode currentNode = null;
- private RightTupleSinkNode nextNode = getFirst();
-
- public boolean hasNext() {
- return (this.nextNode != null);
- }
-
- public Object next() {
- this.currentNode = this.nextNode;
- if ( this.currentNode != null ) {
- this.nextNode = this.currentNode.getNextRightTupleSinkNode();
- } else {
- throw new NoSuchElementException( "No more elements to return" );
- }
- return this.currentNode;
- }
-
- public void remove() {
- if ( this.currentNode != null ) {
- RightTupleSinkNodeList.this.remove( this.currentNode );
- this.currentNode = null;
- } else {
- throw new IllegalStateException( "No item to remove. Call next() before calling remove()." );
- }
- }
- };
- }
-
-}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkPropagator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkPropagator.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSinkPropagator.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -1,20 +0,0 @@
-package org.drools.reteoo;
-
-import java.io.Serializable;
-import java.io.Externalizable;
-
-import org.drools.common.InternalFactHandle;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.spi.PropagationContext;
-
-public interface RightTupleSinkPropagator
- extends
- Externalizable {
- public void propagateAssertFact(InternalFactHandle factHandle,
- PropagationContext context,
- InternalWorkingMemory workingMemory);
-
- public RightTupleSink[] getSinks();
-
- public int size();
-}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSource.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSource.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -1,165 +0,0 @@
-package org.drools.reteoo;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.Serializable;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-
-import org.drools.common.BaseNode;
-import org.drools.common.DefaultFactHandle;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.spi.PropagationContext;
-
-/**
- * A source of <code>FactHandle</code>s for an <code>ObjectSink</code>.
- *
- * <p>
- * Nodes that propagate <code>FactHandleImpl</code> extend this class.
- * </p>
- *
- * @see RightTupleSource
- * @see DefaultFactHandle
- *
- * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
- * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
- */
-public abstract class RightTupleSource extends BaseNode
- implements
- Externalizable {
- // ------------------------------------------------------------
- // Instance members
- // ------------------------------------------------------------
-
- /** The destination for <code>FactHandleImpl</code>. */
- protected RightTupleSinkPropagator sink;
-
- protected RightTupleSource source;
-
- private int alphaNodeHashingThreshold;
-
- // ------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------
- public RightTupleSource() {
-
- }
-
- /**
- * Single parameter constructor that specifies the unique id of the node.
- *
- * @param id
- */
- RightTupleSource(final int id) {
- this( id,
- null,
- 3 );
- }
-
- /**
- * Single parameter constructor that specifies the unique id of the node.
- *
- * @param id
- */
- RightTupleSource(final int id,
- final RightTupleSource objectSource,
- final int alphaNodeHashingThreshold) {
- super( id );
- this.source = objectSource;
- this.alphaNodeHashingThreshold = alphaNodeHashingThreshold;
- this.sink = EmptyRightTupleSinkAdapter.getInstance();
- }
-
- // ------------------------------------------------------------
- // Instance methods
- // ------------------------------------------------------------
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- sink = (RightTupleSinkPropagator)in.readObject();
- source = (RightTupleSource)in.readObject();
- alphaNodeHashingThreshold = in.readInt();
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeObject(sink);
- out.writeObject(source);
- out.writeInt(alphaNodeHashingThreshold);
- }
-
- /**
- * Adds the <code>ObjectSink</code> so that it may receive
- * <code>FactHandleImpl</code> propagated from this
- * <code>ObjectSource</code>.
- *
- * @param objectSink
- * The <code>ObjectSink</code> to receive propagated
- * <code>FactHandleImpl</code>.
- */
- protected void addObjectSink(final RightTupleSink objectSink) {
- if ( this.sink instanceof EmptyRightTupleSinkAdapter ) {
- this.sink = new SingleRightTupleSinkAdapter( objectSink );
- } else if ( this.sink instanceof SingleRightTupleSinkAdapter ) {
- final CompositeRightTupleSinkAdapter sinkAdapter = new CompositeRightTupleSinkAdapter( this.alphaNodeHashingThreshold );
- sinkAdapter.addObjectSink( this.sink.getSinks()[0] );
- sinkAdapter.addObjectSink( objectSink );
- this.sink = sinkAdapter;
- } else {
- ((CompositeRightTupleSinkAdapter) this.sink).addObjectSink( objectSink );
- }
- }
-
- /**
- * Removes the <code>ObjectSink</code>
- *
- * @param objectSink
- * The <code>ObjectSink</code> to remove
- */
- protected void removeObjectSink(final RightTupleSink objectSink) {
- if ( this.sink instanceof EmptyRightTupleSinkAdapter ) {
- throw new IllegalArgumentException( "Cannot remove a sink, when the list of sinks is null" );
- }
-
- if ( this.sink instanceof SingleRightTupleSinkAdapter ) {
- this.sink = EmptyRightTupleSinkAdapter.getInstance();
- } else {
- final CompositeRightTupleSinkAdapter sinkAdapter = (CompositeRightTupleSinkAdapter) this.sink;
- sinkAdapter.removeObjectSink( objectSink );
- if ( sinkAdapter.size() == 1 ) {
- this.sink = new SingleRightTupleSinkAdapter( sinkAdapter.getSinks()[0] );
- }
- }
- }
-
- public abstract void updateSink(RightTupleSink sink,
- PropagationContext context,
- InternalWorkingMemory workingMemory);
-
- public void networkUpdated() {
- this.source.networkUpdated();
- }
-
- public RightTupleSinkPropagator getSinkPropagator() {
- return this.sink;
- }
-
- public boolean isInUse() {
- return this.sink.size() > 0;
- }
-}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleRemovalContext.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleRemovalContext.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleRemovalContext.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -45,12 +45,13 @@
this.visitedNodes = new HashMap();
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- visitedNodes = (Map)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ visitedNodes = (Map) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(visitedNodes);
+ out.writeObject( visitedNodes );
}
/**
@@ -59,8 +60,9 @@
*
* @param node
*/
- public void visitTupleSource( LeftTupleSource node ) {
- this.visitedNodes.put( new Integer(node.getId()), node );
+ public void visitTupleSource(LeftTupleSource node) {
+ this.visitedNodes.put( new Integer( node.getId() ),
+ node );
}
/**
@@ -70,7 +72,7 @@
* @param node
* @return
*/
- public boolean alreadyVisited( LeftTupleSource node ) {
+ public boolean alreadyVisited(LeftTupleSource node) {
return this.visitedNodes.containsKey( new Integer( node.getId() ) );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -60,30 +60,31 @@
implements
LeftTupleSinkNode,
NodeMemory,
- TerminalNode, Externalizable {
+ TerminalNode,
+ Externalizable {
// ------------------------------------------------------------
// Instance members
// ------------------------------------------------------------
- private int sequence;
+ private int sequence;
/**
*
*/
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
/** The rule to invoke upon match. */
- private Rule rule;
+ private Rule rule;
/**
* the subrule reference is needed to resolve declarations
* because declarations may have different offsets in each subrule
*/
- private GroupElement subrule;
- private LeftTupleSource tupleSource;
+ private GroupElement subrule;
+ private LeftTupleSource tupleSource;
- private LeftTupleSinkNode previousTupleSinkNode;
- private LeftTupleSinkNode nextTupleSinkNode;
+ private LeftTupleSinkNode previousTupleSinkNode;
+ private LeftTupleSinkNode nextTupleSinkNode;
- protected boolean tupleMemoryEnabled;
+ protected boolean tupleMemoryEnabled;
// ------------------------------------------------------------
// Constructors
@@ -115,24 +116,25 @@
// ------------------------------------------------------------
// Instance methods
// ------------------------------------------------------------
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- sequence = in.readInt();
- rule = (Rule)in.readObject();
- subrule = (GroupElement)in.readObject();
- tupleSource = (LeftTupleSource)in.readObject();
- previousTupleSinkNode = (LeftTupleSinkNode)in.readObject();
- nextTupleSinkNode = (LeftTupleSinkNode)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ super.readExternal( in );
+ sequence = in.readInt();
+ rule = (Rule) in.readObject();
+ subrule = (GroupElement) in.readObject();
+ tupleSource = (LeftTupleSource) in.readObject();
+ previousTupleSinkNode = (LeftTupleSinkNode) in.readObject();
+ nextTupleSinkNode = (LeftTupleSinkNode) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeInt(sequence);
- out.writeObject(rule);
- out.writeObject(subrule);
- out.writeObject(tupleSource);
- out.writeObject(previousTupleSinkNode);
- out.writeObject(nextTupleSinkNode);
+ super.writeExternal( out );
+ out.writeInt( sequence );
+ out.writeObject( rule );
+ out.writeObject( subrule );
+ out.writeObject( tupleSource );
+ out.writeObject( previousTupleSinkNode );
+ out.writeObject( nextTupleSinkNode );
}
/**
@@ -157,8 +159,8 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public void assertLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
assertTuple( tuple,
context,
workingMemory,
@@ -182,7 +184,7 @@
final boolean fireActivationCreated) {
//check if the rule is effective
- if ( !this.rule.isEffective(workingMemory.getTimeMachine()) ) {
+ if ( !this.rule.isEffective( workingMemory.getTimeMachine() ) ) {
return;
}
@@ -227,7 +229,7 @@
item.setActivated( true );
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
- workingMemory );
+ workingMemory );
} else {
// -----------------
// Lazy instantiation and addition to the Agenda of AgendGroup
@@ -257,7 +259,8 @@
final AgendaItem item = new AgendaItem( context.getPropagationNumber(),
cloned,
- rule.getSalience().getValue( tuple, workingMemory ),
+ rule.getSalience().getValue( tuple,
+ workingMemory ),
context,
this.rule,
this.subrule );
@@ -353,8 +356,8 @@
// We only want to fire an event on a truly new Activation and not on an Activation as a result of a modify
if ( fireActivationCreated ) {
- ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
- workingMemory );
+ ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
+ workingMemory );
}
}
@@ -380,8 +383,8 @@
}
public void retractLeftTuple(final LeftTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
final TerminalNodeMemory memory = (TerminalNodeMemory) workingMemory.getNodeMemory( this );
final LeftTuple tuple = memory.getTupleMemory().remove( leftTuple );
if ( tuple == null ) {
@@ -418,7 +421,7 @@
}
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCancelled( activation,
- workingMemory );
+ workingMemory );
((InternalAgenda) workingMemory.getAgenda()).decreaseActiveActivations();
} else {
((InternalAgenda) workingMemory.getAgenda()).decreaseDormantActivations();
@@ -460,7 +463,7 @@
public void networkUpdated() {
this.tupleSource.networkUpdated();
}
-
+
protected void doRemove(final RuleRemovalContext context,
final ReteooBuilder builder,
final BaseNode node,
@@ -476,7 +479,7 @@
if ( activation.isActivated() ) {
activation.remove();
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCancelled( activation,
- workingMemory );
+ workingMemory );
}
final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
@@ -492,7 +495,7 @@
workingMemory.clearNodeMemory( this );
}
- if( !context.alreadyVisited( this.tupleSource ) ) {
+ if ( !context.alreadyVisited( this.tupleSource ) ) {
this.tupleSource.remove( context,
builder,
this,
@@ -572,33 +575,35 @@
public static class TerminalNodeMemory
implements
Externalizable {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
- private InternalAgendaGroup agendaGroup;
+ private InternalAgendaGroup agendaGroup;
- private ActivationGroup activationGroup;
+ private ActivationGroup activationGroup;
- private RuleFlowGroup ruleFlowGroup;
+ private RuleFlowGroup ruleFlowGroup;
- private TupleHashTable tupleMemory;
+ private TupleHashTable tupleMemory;
public TerminalNodeMemory() {
this.tupleMemory = new TupleHashTable();
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- agendaGroup = (InternalAgendaGroup)in.readObject();
- activationGroup = (ActivationGroup)in.readObject();
- ruleFlowGroup = (RuleFlowGroup)in.readObject();
- tupleMemory = (TupleHashTable)in.readObject();
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ agendaGroup = (InternalAgendaGroup) in.readObject();
+ activationGroup = (ActivationGroup) in.readObject();
+ ruleFlowGroup = (RuleFlowGroup) in.readObject();
+ tupleMemory = (TupleHashTable) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(agendaGroup);
- out.writeObject(activationGroup);
- out.writeObject(ruleFlowGroup);
- out.writeObject(tupleMemory);
+ out.writeObject( agendaGroup );
+ out.writeObject( activationGroup );
+ out.writeObject( ruleFlowGroup );
+ out.writeObject( tupleMemory );
}
+
public InternalAgendaGroup getAgendaGroup() {
return this.agendaGroup;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -14,7 +14,7 @@
private LeftTupleSink sink;
public SingleLeftTupleSinkAdapter() {
-
+
}
public SingleLeftTupleSinkAdapter(final LeftTupleSink sink) {
@@ -22,83 +22,83 @@
}
public void propagateAssertLeftTuple(final LeftTuple leftTuple,
- final RightTuple rightTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final RightTuple rightTuple,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
this.sink.assertLeftTuple( new LeftTuple( leftTuple,
- rightTuple,
- this.sink ),
- context,
- workingMemory );
+ rightTuple,
+ this.sink ),
+ context,
+ workingMemory );
}
public void propagateAssertLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
this.sink.assertLeftTuple( new LeftTuple( tuple,
- this.sink ),
- context,
- workingMemory );
+ this.sink ),
+ context,
+ workingMemory );
}
-
-// public void propagateNotRetractLeftTuple(final LeftTuple leftTuple,
-// final PropagationContext context,
-// final InternalWorkingMemory workingMemory) {
-// LeftTuple child = leftTuple.getBetaChildren();
-// while ( child != null ) {
-// //LeftTuple temp = leftTuple.getRightParentNext();
-// //child.unlinkFromParents();
-// //child.unlinkFromLeftParent();
-// child.getSink().retractTuple( child,
-// context,
-// workingMemory );
-// child = child.getLeftParentNext();
-// //child = temp;
-// }
-// leftTuple.setBetaChildren( null );
-// }
+ // public void propagateNotRetractLeftTuple(final LeftTuple leftTuple,
+ // final PropagationContext context,
+ // final InternalWorkingMemory workingMemory) {
+ // LeftTuple child = leftTuple.getBetaChildren();
+ // while ( child != null ) {
+ // //LeftTuple temp = leftTuple.getRightParentNext();
+ // //child.unlinkFromParents();
+ // //child.unlinkFromLeftParent();
+ // child.getSink().retractTuple( child,
+ // context,
+ // workingMemory );
+ // child = child.getLeftParentNext();
+ // //child = temp;
+ // }
+ // leftTuple.setBetaChildren( null );
+ // }
+
public void propagateRetractLeftTuple(final LeftTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
LeftTuple child = leftTuple.getBetaChildren();
while ( child != null ) {
LeftTuple temp = child.getLeftParentNext();
//child.unlinkFromParents();
child.getSink().retractLeftTuple( child,
- context,
- workingMemory );
- child.unlinkFromRightParent();
+ context,
+ workingMemory );
+ child.unlinkFromRightParent();
//child = child.getLeftParentNext();
child = temp;
}
leftTuple.setBetaChildren( null );
}
-
+
public void propagateRetractRightTuple(final RightTuple rightTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
LeftTuple child = rightTuple.getBetaChildren();
while ( child != null ) {
LeftTuple temp = child.getRightParentNext();
//child.unlinkFromParents();
child.getSink().retractLeftTuple( child,
- context,
- workingMemory );
- child.unlinkFromLeftParent();
+ context,
+ workingMemory );
+ child.unlinkFromLeftParent();
//child = child.getRightParentNext();
child = temp;
}
rightTuple.setBetaChildren( null );
- }
+ }
public void createAndPropagateAssertLeftTuple(final InternalFactHandle factHandle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
this.sink.assertLeftTuple( new LeftTuple( factHandle,
- this.sink ),
- context,
- workingMemory );
+ this.sink ),
+ context,
+ workingMemory );
}
public LeftTupleSink[] getSinks() {
@@ -112,7 +112,7 @@
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
// @todo
-
+
}
public void writeExternal(ObjectOutput out) throws IOException {
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleObjectSinkAdapter.java (from rev 19178, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleRightTupleSinkAdapter.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleObjectSinkAdapter.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleObjectSinkAdapter.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -0,0 +1,55 @@
+package org.drools.reteoo;
+
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.spi.PropagationContext;
+
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+
+public class SingleObjectSinkAdapter
+ implements
+ ObjectSinkPropagator,
+ Externalizable {
+
+ private static final long serialVersionUID = 873985743021L;
+
+ private ObjectSink sink;
+
+ public SingleObjectSinkAdapter() {
+
+ }
+
+ public SingleObjectSinkAdapter(final ObjectSink sink) {
+ this.sink = sink;
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ sink = (ObjectSink) in.readObject();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject( sink );
+ }
+
+ public void propagateAssertObject(final InternalFactHandle factHandle,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+ this.sink.assertObject( factHandle,
+ context,
+ workingMemory );
+
+ }
+
+ public ObjectSink[] getSinks() {
+ return new ObjectSink[]{this.sink};
+ }
+
+ public int size() {
+ return 1;
+ }
+
+}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleRightTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleRightTupleSinkAdapter.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleRightTupleSinkAdapter.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -1,55 +0,0 @@
-package org.drools.reteoo;
-
-import org.drools.common.InternalFactHandle;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.spi.PropagationContext;
-
-import java.io.Externalizable;
-import java.io.ObjectOutput;
-import java.io.IOException;
-import java.io.ObjectInput;
-
-public class SingleRightTupleSinkAdapter
- implements
- RightTupleSinkPropagator,
- Externalizable {
-
- private static final long serialVersionUID = 873985743021L;
-
- private RightTupleSink sink;
-
- public SingleRightTupleSinkAdapter() {
-
- }
-
- public SingleRightTupleSinkAdapter(final RightTupleSink sink) {
- this.sink = sink;
- }
-
- public void readExternal(ObjectInput in) throws IOException,
- ClassNotFoundException {
- sink = (RightTupleSink) in.readObject();
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject( sink );
- }
-
- public void propagateAssertFact(final InternalFactHandle factHandle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- this.sink.assertObject( factHandle,
- context,
- workingMemory );
-
- }
-
- public RightTupleSink[] getSinks() {
- return new RightTupleSink[]{this.sink};
- }
-
- public int size() {
- return 1;
- }
-
-}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TerminalNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TerminalNode.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TerminalNode.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -23,6 +23,8 @@
*
* @author etirelli
*/
-public interface TerminalNode extends NetworkNode {
+public interface TerminalNode
+ extends
+ NetworkNode {
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -22,7 +22,7 @@
import org.drools.common.BetaConstraints;
import org.drools.common.TupleStartEqualsConstraint;
import org.drools.reteoo.AccumulateNode;
-import org.drools.reteoo.RightTupleSource;
+import org.drools.reteoo.ObjectSource;
import org.drools.reteoo.RightInputAdapterNode;
import org.drools.reteoo.LeftTupleSource;
import org.drools.rule.Accumulate;
@@ -67,7 +67,7 @@
if ( context.getObjectSource() == null ) {
// attach right input adapter node to convert tuple source into an object source
- context.setObjectSource( (RightTupleSource) utils.attachNode( context,
+ context.setObjectSource( (ObjectSource) utils.attachNode( context,
new RightInputAdapterNode( context.getNextId(),
context.getTupleSource(),
context ) ) );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -25,7 +25,7 @@
import org.drools.common.BetaConstraints;
import org.drools.common.InternalRuleBase;
import org.drools.common.InternalWorkingMemory;
-import org.drools.reteoo.RightTupleSource;
+import org.drools.reteoo.ObjectSource;
import org.drools.reteoo.ReteooBuilder;
import org.drools.reteoo.ReteooRuleBase;
import org.drools.reteoo.LeftTupleSource;
@@ -43,7 +43,7 @@
private LeftTupleSource tupleSource;
// object source to attach next node to
- private RightTupleSource objectSource;
+ private ObjectSource objectSource;
// object type cache to check for cross products
private LinkedList objectType;
@@ -131,14 +131,14 @@
/**
* @return the objectSource
*/
- public RightTupleSource getObjectSource() {
+ public ObjectSource getObjectSource() {
return this.objectSource;
}
/**
* @param objectSource the objectSource to set
*/
- public void setObjectSource(final RightTupleSource objectSource) {
+ public void setObjectSource(final ObjectSource objectSource) {
this.objectSource = objectSource;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -32,8 +32,8 @@
import org.drools.common.SingleBetaConstraints;
import org.drools.common.TripleBetaConstraints;
import org.drools.reteoo.EntryPointNode;
-import org.drools.reteoo.RightTupleSink;
-import org.drools.reteoo.RightTupleSource;
+import org.drools.reteoo.ObjectSink;
+import org.drools.reteoo.ObjectSource;
import org.drools.reteoo.ObjectTypeNode;
import org.drools.reteoo.LeftTupleSink;
import org.drools.reteoo.LeftTupleSource;
@@ -114,8 +114,8 @@
break;
}
}
- } else if ( (context.getObjectSource() != null) && (candidate instanceof RightTupleSink) ) {
- RightTupleSink[] sinks = context.getObjectSource().getSinkPropagator().getSinks();
+ } else if ( (context.getObjectSource() != null) && (candidate instanceof ObjectSink) ) {
+ ObjectSink[] sinks = context.getObjectSource().getSinkPropagator().getSinks();
for( int i = 0; i < sinks.length; i++ ) {
if( candidate.equals( sinks[i] ) ) {
node = (BaseNode) sinks[i];
@@ -157,7 +157,7 @@
final BaseNode node) {
if ( node instanceof LeftTupleSource ) {
return context.getRuleBase().getConfiguration().isShareBetaNodes();
- } else if ( node instanceof RightTupleSource ) {
+ } else if ( node instanceof ObjectSource ) {
return context.getRuleBase().getConfiguration().isShareAlphaNodes();
}
return false;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -22,7 +22,7 @@
import org.drools.common.BetaConstraints;
import org.drools.common.TupleStartEqualsConstraint;
import org.drools.reteoo.CollectNode;
-import org.drools.reteoo.RightTupleSource;
+import org.drools.reteoo.ObjectSource;
import org.drools.reteoo.RightInputAdapterNode;
import org.drools.reteoo.LeftTupleSource;
import org.drools.rule.Collect;
@@ -69,7 +69,7 @@
if ( context.getObjectSource() == null ) {
// attach right input adapter node to convert tuple source into an object source
- context.setObjectSource( (RightTupleSource) utils.attachNode( context,
+ context.setObjectSource( (ObjectSource) utils.attachNode( context,
new RightInputAdapterNode( context.getNextId(),
context.getTupleSource(),
context ) ) );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -29,7 +29,7 @@
import org.drools.reteoo.JoinNode;
import org.drools.reteoo.LeftInputAdapterNode;
import org.drools.reteoo.NotNode;
-import org.drools.reteoo.RightTupleSource;
+import org.drools.reteoo.ObjectSource;
import org.drools.reteoo.RightInputAdapterNode;
import org.drools.reteoo.LeftTupleSource;
import org.drools.rule.GroupElement;
@@ -215,7 +215,7 @@
if ( context.getObjectSource() == null && context.getTupleSource() != null ) {
// attach right input adapter node to convert tuple source into an object source
- context.setObjectSource( (RightTupleSource) utils.attachNode( context,
+ context.setObjectSource( (ObjectSource) utils.attachNode( context,
new RightInputAdapterNode( context.getNextId(),
context.getTupleSource(),
context ) ) );
@@ -292,7 +292,7 @@
if ( context.getObjectSource() == null && context.getTupleSource() != null ) {
// attach right input adapter node to convert tuple source into an object source
- context.setObjectSource( (RightTupleSource) utils.attachNode( context,
+ context.setObjectSource( (ObjectSource) utils.attachNode( context,
new RightInputAdapterNode( context.getNextId(),
context.getTupleSource(),
context ) ) );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -27,7 +27,7 @@
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.AlphaNode;
import org.drools.reteoo.EntryPointNode;
-import org.drools.reteoo.RightTupleSource;
+import org.drools.reteoo.ObjectSource;
import org.drools.reteoo.ObjectTypeNode;
import org.drools.reteoo.PropagationQueuingNode;
import org.drools.rule.Declaration;
@@ -108,7 +108,7 @@
alphaConstraints );
if ( context.getCurrentEntryPoint() != EntryPoint.DEFAULT ) {
- context.setObjectSource( (RightTupleSource) utils.attachNode( context,
+ context.setObjectSource( (ObjectSource) utils.attachNode( context,
new PropagationQueuingNode( context.getNextId(),
context.getObjectSource(),
context ) ) );
@@ -209,12 +209,12 @@
}
}
- context.setObjectSource( (RightTupleSource) utils.attachNode( context,
+ context.setObjectSource( (ObjectSource) utils.attachNode( context,
new EntryPointNode( context.getNextId(),
context.getRuleBase().getRete(),
context ) ) );
- context.setObjectSource( (RightTupleSource) utils.attachNode( context,
+ context.setObjectSource( (ObjectSource) utils.attachNode( context,
new ObjectTypeNode( context.getNextId(),
(EntryPointNode) context.getObjectSource(),
pattern.getObjectType(),
@@ -223,7 +223,7 @@
for ( final Iterator it = alphaConstraints.iterator(); it.hasNext(); ) {
final AlphaNodeFieldConstraint constraint = (AlphaNodeFieldConstraint) it.next();
- context.setObjectSource( (RightTupleSource) utils.attachNode( context,
+ context.setObjectSource( (ObjectSource) utils.attachNode( context,
new AlphaNode( context.getNextId(),
(AlphaNodeFieldConstraint) constraint,
context.getObjectSource(),
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/BetaNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/BetaNodeTest.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/BetaNodeTest.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -47,7 +47,7 @@
*/
public void testEqualsObject() {
final LeftTupleSource ts = new MockTupleSource( 1 );
- final RightTupleSource os = new MockObjectSource( 2 );
+ final ObjectSource os = new MockObjectSource( 2 );
ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -41,7 +41,7 @@
public String wah;
public void testBeta() {
- final CompositeRightTupleSinkAdapter ad = new CompositeRightTupleSinkAdapter();
+ final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
final MockBetaNode beta = new MockBetaNode( buildContext.getNextId(),
null,
null );
@@ -67,7 +67,7 @@
}
public void testAlphaWithPredicate() {
- final CompositeRightTupleSinkAdapter ad = new CompositeRightTupleSinkAdapter();
+ final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
final AlphaNode al = new AlphaNode( buildContext.getNextId(),
new PredicateConstraint( null,
null ),
@@ -91,7 +91,7 @@
public void testSingleAlpha() {
- final CompositeRightTupleSinkAdapter ad = new CompositeRightTupleSinkAdapter();
+ final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
final LiteralConstraint lit = new LiteralConstraint( new MockExtractor(),
equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
new ObjectFieldImpl( "stilton" ) );
@@ -117,7 +117,7 @@
public void testDoubleAlphaWithBeta() {
- final CompositeRightTupleSinkAdapter ad = new CompositeRightTupleSinkAdapter();
+ final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
final LiteralConstraint lit = new LiteralConstraint( new MockExtractor(),
equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
new ObjectFieldImpl( "stilton" ) );
@@ -175,7 +175,7 @@
}
public void testTripleAlpha() {
- final CompositeRightTupleSinkAdapter ad = new CompositeRightTupleSinkAdapter();
+ final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
FieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( Cheese.class,
"type",
this.getClass().getClassLoader() );
@@ -234,7 +234,7 @@
}
public void testTripleAlphaCharacterConstraint() {
- final CompositeRightTupleSinkAdapter ad = new CompositeRightTupleSinkAdapter();
+ final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
FieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( Cheese.class,
"charType",
this.getClass().getClassLoader() );
@@ -286,13 +286,13 @@
// test propagation
Cheese cheese = new Cheese();
cheese.setCharType( 'B' );
- CompositeRightTupleSinkAdapter.HashKey hashKey = new CompositeRightTupleSinkAdapter.HashKey();
+ CompositeObjectSinkAdapter.HashKey hashKey = new CompositeObjectSinkAdapter.HashKey();
// should find this
hashKey.setValue( extractor.getIndex(),
cheese,
extractor );
- RightTupleSink sink = (RightTupleSink) ad.hashedSinkMap.get( hashKey );
+ ObjectSink sink = (ObjectSink) ad.hashedSinkMap.get( hashKey );
assertSame( al2, sink );
// should not find this one
@@ -300,7 +300,7 @@
hashKey.setValue( extractor.getIndex(),
cheese,
extractor );
- sink = (RightTupleSink) ad.hashedSinkMap.get( hashKey );
+ sink = (ObjectSink) ad.hashedSinkMap.get( hashKey );
assertNull( sink );
//now remove one, check the hashing is undone
@@ -314,7 +314,7 @@
public void testPropagationWithNullValue() {
- final CompositeRightTupleSinkAdapter ad = new CompositeRightTupleSinkAdapter();
+ final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
FieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( Cheese.class,
"type",
this.getClass().getClassLoader() );
@@ -348,7 +348,7 @@
InternalFactHandle handle = new ReteooFactHandleFactory().newFactHandle( new Cheese(), false, null );
try {
- ad.propagateAssertFact( handle,
+ ad.propagateAssertObject( handle,
null,
null );
} catch ( RuntimeException e ) {
@@ -472,7 +472,7 @@
MockBetaNode(final int id,
final LeftTupleSource leftInput,
- final RightTupleSource rightInput) {
+ final ObjectSource rightInput) {
super( id,
leftInput,
rightInput,
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -89,9 +89,9 @@
}
public void testAttach() throws Exception {
- final Field objectFfield = RightTupleSource.class.getDeclaredField( "sink" );
+ final Field objectFfield = ObjectSource.class.getDeclaredField( "sink" );
objectFfield.setAccessible( true );
- RightTupleSinkPropagator objectSink = (RightTupleSinkPropagator) objectFfield.get( this.objectSource );
+ ObjectSinkPropagator objectSink = (ObjectSinkPropagator) objectFfield.get( this.objectSource );
final Field tupleField = LeftTupleSource.class.getDeclaredField( "sink" );
tupleField.setAccessible( true );
@@ -105,7 +105,7 @@
this.node.attach();
- objectSink = (RightTupleSinkPropagator) objectFfield.get( this.objectSource );
+ objectSink = (ObjectSinkPropagator) objectFfield.get( this.objectSource );
tupleSink = (LeftTupleSinkPropagator) tupleField.get( this.tupleSource );
assertEquals( 1,
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -65,9 +65,9 @@
final LeftInputAdapterNode liaNode = new LeftInputAdapterNode( 1,
source,
buildContext );
- final Field field = RightTupleSource.class.getDeclaredField( "sink" );
+ final Field field = ObjectSource.class.getDeclaredField( "sink" );
field.setAccessible( true );
- RightTupleSinkPropagator sink = (RightTupleSinkPropagator) field.get( source );
+ ObjectSinkPropagator sink = (ObjectSinkPropagator) field.get( source );
assertEquals( 1,
liaNode.getId() );
@@ -75,7 +75,7 @@
liaNode.attach();
- sink = (RightTupleSinkPropagator) field.get( source );
+ sink = (ObjectSinkPropagator) field.get( source );
assertEquals( 1,
sink.getSinks().length );
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSink.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSink.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSink.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -25,12 +25,12 @@
public class MockObjectSink
implements
- RightTupleSinkNode {
+ ObjectTupleSinkNode {
private final List asserted = new ArrayList();
private final List retracted = new ArrayList();
- private RightTupleSinkNode previousObjectSinkNode;
- private RightTupleSinkNode nextObjectSinkNode;
+ private ObjectTupleSinkNode previousObjectSinkNode;
+ private ObjectTupleSinkNode nextObjectSinkNode;
public void assertObject(final InternalFactHandle factHandle,
final PropagationContext context,
@@ -57,7 +57,7 @@
* @return
* The next ObjectSinkNode
*/
- public RightTupleSinkNode getNextRightTupleSinkNode() {
+ public ObjectTupleSinkNode getNextObjectSinkNode() {
return this.nextObjectSinkNode;
}
@@ -66,7 +66,7 @@
* @param next
* The next ObjectSinkNode
*/
- public void setNextRightTupleSinkNode(final RightTupleSinkNode next) {
+ public void setNextObjectSinkNode(final ObjectTupleSinkNode next) {
this.nextObjectSinkNode = next;
}
@@ -75,7 +75,7 @@
* @return
* The previous ObjectSinkNode
*/
- public RightTupleSinkNode getPreviousRightTupleSinkNode() {
+ public ObjectTupleSinkNode getPreviousObjectSinkNode() {
return this.previousObjectSinkNode;
}
@@ -84,7 +84,7 @@
* @param previous
* The previous ObjectSinkNode
*/
- public void setPreviousRightTupleSinkNode(final RightTupleSinkNode previous) {
+ public void setPreviousObjectSinkNode(final ObjectTupleSinkNode previous) {
this.previousObjectSinkNode = previous;
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSource.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSource.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -28,7 +28,7 @@
import java.util.Iterator;
import java.util.List;
-public class MockObjectSource extends RightTupleSource {
+public class MockObjectSource extends ObjectSource {
/**
*
*/
@@ -79,7 +79,7 @@
this.facts.add( handle );
}
- public void updateSink(final RightTupleSink sink,
+ public void updateSink(final ObjectSink sink,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
this.updated++;
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectSourceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectSourceTest.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectSourceTest.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -38,52 +38,52 @@
final MockObjectSource source = new MockObjectSource( 15 );
// We need to re-assign this var each time the sink changes references
- final Field field = RightTupleSource.class.getDeclaredField( "sink" );
+ final Field field = ObjectSource.class.getDeclaredField( "sink" );
field.setAccessible( true );
- RightTupleSinkPropagator sink = (RightTupleSinkPropagator) field.get( source );
+ ObjectSinkPropagator sink = (ObjectSinkPropagator) field.get( source );
- assertSame( EmptyRightTupleSinkAdapter.getInstance(),
+ assertSame( EmptyObjectSinkAdapter.getInstance(),
sink );
final MockObjectSink sink1 = new MockObjectSink();
source.addObjectSink( sink1 );
- sink = (RightTupleSinkPropagator) field.get( source );
- assertSame( SingleRightTupleSinkAdapter.class,
+ sink = (ObjectSinkPropagator) field.get( source );
+ assertSame( SingleObjectSinkAdapter.class,
sink.getClass() );
assertEquals( 1,
sink.getSinks().length );
final MockObjectSink sink2 = new MockObjectSink();
source.addObjectSink( sink2 );
- sink = (RightTupleSinkPropagator) field.get( source );
- assertSame( CompositeRightTupleSinkAdapter.class,
+ sink = (ObjectSinkPropagator) field.get( source );
+ assertSame( CompositeObjectSinkAdapter.class,
sink.getClass() );
assertEquals( 2,
sink.getSinks().length );
final MockObjectSink sink3 = new MockObjectSink();
source.addObjectSink( sink3 );
- assertSame( CompositeRightTupleSinkAdapter.class,
+ assertSame( CompositeObjectSinkAdapter.class,
sink.getClass() );
assertEquals( 3,
sink.getSinks().length );
source.removeObjectSink( sink2 );
- assertSame( CompositeRightTupleSinkAdapter.class,
+ assertSame( CompositeObjectSinkAdapter.class,
sink.getClass() );
assertEquals( 2,
sink.getSinks().length );
source.removeObjectSink( sink1 );
- sink = (RightTupleSinkPropagator) field.get( source );
- assertSame( SingleRightTupleSinkAdapter.class,
+ sink = (ObjectSinkPropagator) field.get( source );
+ assertSame( SingleObjectSinkAdapter.class,
sink.getClass() );
assertEquals( 1,
sink.getSinks().length );
source.removeObjectSink( sink3 );
- sink = (RightTupleSinkPropagator) field.get( source );
- assertSame( EmptyRightTupleSinkAdapter.getInstance(),
+ sink = (ObjectSinkPropagator) field.get( source );
+ assertSame( EmptyObjectSinkAdapter.getInstance(),
sink );
assertEquals( 0,
sink.getSinks().length );
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java 2008-03-21 16:51:37 UTC (rev 19180)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java 2008-03-21 18:10:36 UTC (rev 19181)
@@ -50,20 +50,20 @@
final MockTupleSink sink2 = new MockTupleSink();
source.addTupleSink( sink2 );
sink = (LeftTupleSinkPropagator) field.get( source );
- assertSame( CompositeTupleSinkAdapter.class,
+ assertSame( CompositeLeftTupleSinkAdapter.class,
sink.getClass() );
assertEquals( 2,
sink.getSinks().length );
final MockTupleSink sink3 = new MockTupleSink();
source.addTupleSink( sink3 );
- assertSame( CompositeTupleSinkAdapter.class,
+ assertSame( CompositeLeftTupleSinkAdapter.class,
sink.getClass() );
assertEquals( 3,
sink.getSinks().length );
source.removeTupleSink( sink2 );
- assertSame( CompositeTupleSinkAdapter.class,
+ assertSame( CompositeLeftTupleSinkAdapter.class,
sink.getClass() );
assertEquals( 2,
sink.getSinks().length );
More information about the jboss-svn-commits
mailing list