[jboss-svn-commits] JBL Code SVN: r25791 - labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Mar 23 16:42:15 EDT 2009
Author: salaboy21
Date: 2009-03-23 16:42:15 -0400 (Mon, 23 Mar 2009)
New Revision: 25791
Modified:
labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java
Log:
fixes in default knowledge helper.. analyze how turn off and on this caching in identityMap
Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java 2009-03-23 14:03:41 UTC (rev 25790)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java 2009-03-23 20:42:15 UTC (rev 25791)
@@ -36,6 +36,9 @@
import org.drools.runtime.rule.WorkingMemoryEntryPoint;
import org.drools.FactHandle;
import org.drools.WorkingMemory;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.common.InternalWorkingMemoryEntryPoint;
import org.drools.spi.Activation;
import org.drools.spi.KnowledgeHelper;
import org.drools.spi.Tuple;
@@ -57,7 +60,7 @@
public DefaultKnowledgeHelper() {
- this.identityMap = new IdentityHashMap<Object,FactHandle>();
+ //this.identityMap = new IdentityHashMap<Object,FactHandle>();
}
@@ -75,6 +78,7 @@
activation = (Activation) in.readObject();
tuple = (Tuple) in.readObject();
workingMemory = (InternalWorkingMemoryActions) in.readObject();
+ identityMap = (IdentityHashMap<Object,FactHandle> ) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
@@ -83,6 +87,7 @@
out.writeObject( activation );
out.writeObject( tuple );
out.writeObject( workingMemory );
+ out.writeObject( identityMap );
}
public void setActivation(final Activation agendaItem) {
@@ -97,6 +102,7 @@
this.subrule = null;
this.activation = null;
this.tuple = null;
+ this.identityMap.clear();
}
public void insert(final Object object) throws FactException {
@@ -133,30 +139,37 @@
public void update(final FactHandle handle,
final Object newObject) throws FactException {
// only update if this fact exists in the wm
- this.workingMemory.update( handle,
+
+ ((InternalWorkingMemoryEntryPoint)((InternalFactHandle)handle).getEntryPoint())
+ .update( handle,
newObject,
this.rule,
this.activation );
+ this.getIdentityMap().put(newObject, handle);
}
public void update(final Object object) throws FactException {
- FactHandle handle = this.workingMemory.getFactHandleByIdentity( object );
+ FactHandle handle = identityMap.get(object);
if ( handle == null ) {
throw new FactException( "Update error: handle not found for object: " + object + ". Is it in the working memory?" );
}
// only update if this fact exists in the wm
- this.workingMemory.update( handle,
+ ((InternalWorkingMemoryEntryPoint)((InternalFactHandle)handle).getEntryPoint())
+ .update( handle,
object,
this.rule,
this.activation );
+ this.getIdentityMap().put(object, handle);
}
public void retract(final FactHandle handle) throws FactException {
- this.workingMemory.retract( handle,
+ ((InternalWorkingMemoryEntryPoint)((InternalFactHandle)handle).getEntryPoint())
+ .retract( handle,
true,
true,
this.rule,
this.activation );
+ this.getIdentityMap().remove(((InternalFactHandle)handle).getObject());
}
public void retract(final Object object) throws FactException {
@@ -164,7 +177,8 @@
if ( handle == null ) {
throw new FactException( "Retract error: handle not found for object: " + object + ". Is it in the working memory?" );
}
- this.workingMemory.retract( handle,
+ ((InternalWorkingMemoryEntryPoint)((InternalFactHandle)handle).getEntryPoint())
+ .retract( handle,
true,
true,
this.rule,
@@ -175,13 +189,15 @@
public void modifyRetract(final Object object) {
FactHandle handle = getIdentityMap().get( object );
- this.workingMemory.modifyRetract( handle,
+ ((InternalWorkingMemoryEntryPoint)((InternalFactHandle)handle).getEntryPoint())
+ .modifyRetract( handle,
rule,
activation );
}
public void modifyRetract(final FactHandle factHandle) {
- this.workingMemory.modifyRetract( factHandle,
+ ((InternalWorkingMemoryEntryPoint)((InternalFactHandle)factHandle).getEntryPoint())
+ .modifyRetract( factHandle,
rule,
activation );
}
@@ -189,7 +205,8 @@
public void modifyInsert(final Object object) {
FactHandle handle = getIdentityMap().get( object );
- this.workingMemory.modifyInsert( handle,
+ ((InternalWorkingMemoryEntryPoint)((InternalFactHandle)handle).getEntryPoint())
+ .modifyInsert( handle,
object,
rule,
activation );
@@ -198,7 +215,8 @@
public void modifyInsert(final FactHandle factHandle,
final Object object) {
- this.workingMemory.modifyInsert( factHandle,
+ ((InternalWorkingMemoryEntryPoint)((InternalFactHandle)factHandle).getEntryPoint())
+ .modifyInsert( factHandle,
object,
rule,
activation );
@@ -259,13 +277,31 @@
// }
public Object get(final Declaration declaration) {
- return declaration.getValue( workingMemory,
+ //((InternalWorkingMemoryActions)((InternalFactHandle)this.tuple.get( declaration )).getEntryPoint())
+// getIdentityMap().put(declaration.getValue(
+// ((InternalWorkingMemoryActions)(this.tuple.get(declaration)).getEntryPoint()),
+// this.tuple.get( declaration ).getObject() ),
+// tuple.get(declaration));
+ InternalWorkingMemoryActions wmTmp = ((InternalWorkingMemoryActions)(this.tuple.get(declaration)).getEntryPoint());
+
+
+ Object object = declaration.getValue( wmTmp ,
this.tuple.get( declaration ).getObject() );
+ if(wmTmp != null){
+ getIdentityMap().put(object, wmTmp.getFactHandleByIdentity(object));
+ }
+ return object;
}
public Declaration getDeclaration(final String identifier) {
Declaration declaration = (Declaration) this.subrule.getOuterDeclarations().get( identifier );
- getIdentityMap().put(tuple.get(declaration).getObject(), tuple.get(declaration));
+ Object object = get(declaration);
+ InternalWorkingMemoryActions wmTmp = ((InternalWorkingMemoryActions)(this.tuple.get(declaration)).getEntryPoint());
+
+ if(wmTmp != null){
+ getIdentityMap().put(object, wmTmp.getFactHandleByIdentity(object));
+ }
+ //((InternalWorkingMemoryActions)(this.tuple.get(declaration)).getEntryPoint()).getFactHandleByIdentity(declaration.getValue( ((InternalWorkingMemoryActions)(this.tuple.get(declaration)).getEntryPoint()),this.tuple.get( declaration ).getObject() ))
return declaration;
}
More information about the jboss-svn-commits
mailing list