Skip to content

Commit

Permalink
Remove unnecessary identityMaps
Browse files Browse the repository at this point in the history
  • Loading branch information
sotty committed Feb 28, 2015
1 parent a1d955d commit 09e99d4
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.kie.api.runtime.process.ProcessInstance;
import org.kie.api.runtime.process.WorkflowProcessInstance;
import org.kie.api.runtime.rule.EntryPoint;
import org.kie.api.runtime.rule.FactHandle;
import org.kie.api.runtime.rule.Match;
import org.kie.internal.runtime.KnowledgeRuntime;
import org.kie.internal.runtime.beliefs.Mode;
Expand All @@ -68,7 +67,6 @@
import java.io.ObjectOutput;
import java.util.Collection;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Map;

import static org.drools.core.reteoo.PropertySpecificUtil.allSetButTraitBitMask;
Expand All @@ -85,9 +83,6 @@ public class DefaultKnowledgeHelper<T extends ModedAssertion<T>>
private Tuple tuple;
private InternalWorkingMemoryActions workingMemory;

private IdentityHashMap<Object, InternalFactHandle>
identityMap;

private LinkedList<LogicalDependency<T>> previousJustified;

private LinkedList<LogicalDependency<SimpleMode>> previousBlocked;
Expand All @@ -98,31 +93,24 @@ public DefaultKnowledgeHelper() {

public DefaultKnowledgeHelper(final WorkingMemory workingMemory) {
this.workingMemory = (InternalWorkingMemoryActions) workingMemory;

this.identityMap = null;

}

public DefaultKnowledgeHelper(Activation activation, final WorkingMemory workingMemory) {
this.workingMemory = (InternalWorkingMemoryActions) workingMemory;
this.activation = activation;
this.identityMap = null;

}

public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
activation = (Activation) in.readObject();
tuple = (Tuple) in.readObject();
workingMemory = (InternalWorkingMemoryActions) in.readObject();
identityMap = (IdentityHashMap<Object, InternalFactHandle>) in.readObject();
}

public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject( activation );
out.writeObject( tuple );
out.writeObject( workingMemory );
out.writeObject( identityMap );
}

public void setActivation(final Activation agendaItem) {
Expand All @@ -139,7 +127,6 @@ public void setActivation(final Activation agendaItem) {
public void reset() {
this.activation = null;
this.tuple = null;
this.identityMap = null;
this.previousJustified = null;
this.previousBlocked = null;
}
Expand Down Expand Up @@ -218,11 +205,6 @@ public InternalFactHandle insert(final Object object,
false,
this.activation.getRule(),
this.activation );
if ( this.identityMap != null ) {
this.getIdentityMap().put( object,
handle );
}

return handle;
}

Expand Down Expand Up @@ -298,10 +280,6 @@ public InternalFactHandle insertLogical(final Object object,
// this.activation.getRule(),
// this.activation );

if ( this.identityMap != null ) {
this.getIdentityMap().put( object,
handle );
}
return handle;
}
}
Expand Down Expand Up @@ -387,10 +365,7 @@ public void cancelMatch(Match act) {

public InternalFactHandle getFactHandle(Object object) {
InternalFactHandle handle = null;
if ( identityMap != null ) {
handle = identityMap.get( object );
}


if ( handle != null ) {
return handle;
}
Expand Down Expand Up @@ -425,10 +400,6 @@ public void update(final FactHandle handle,
onlyTraitBitSetMask(),
newObject.getClass(),
this.activation );
if ( getIdentityMap() != null ) {
this.getIdentityMap().put( newObject,
h );
}
}

public void update(final FactHandle handle) {
Expand Down Expand Up @@ -483,9 +454,6 @@ public void delete(FactHandle handle) {
((InternalWorkingMemoryEntryPoint) ifh.getEntryPoint()).getTruthMaintenanceSystem().delete( ifh );
}

if ( this.identityMap != null ) {
this.getIdentityMap().remove( o );
}
}

public RuleImpl getRule() {
Expand Down Expand Up @@ -519,10 +487,6 @@ public Object get(final Declaration declaration) {
Object object = declaration.getValue( wmTmp.getInternalWorkingMemory(),
this.tuple.get( declaration ).getObject() );

if ( identityMap != null ) {
getIdentityMap().put( object,
(InternalFactHandle) wmTmp.getFactHandleByIdentity( object ) );
}
return object;
}
return null;
Expand All @@ -548,30 +512,12 @@ public Map<String, Channel> getChannels() {
return Collections.unmodifiableMap( this.workingMemory.getChannels() );
}

/**
* @return the identityMap
*/
public IdentityHashMap<Object, InternalFactHandle> getIdentityMap() {
return identityMap;
}

/**
* @param identityMap the identityMap to set
*/
public void setIdentityMap(IdentityHashMap<Object, InternalFactHandle> identityMap) {
this.identityMap = identityMap;
}

private InternalFactHandle getFactHandleFromWM(final Object object) {
InternalFactHandle handle = null;
// entry point null means it is a generated fact, not a regular inserted fact
// NOTE: it would probably be a good idea to create a specific attribute for that
for ( EntryPoint ep : workingMemory.getEntryPoints() ) {
handle = (InternalFactHandle) ep.getFactHandle( object );
if ( identityMap != null ) {
identityMap.put( object,
handle );
}
if( handle != null ) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public class SequentialKnowledgeHelper
private Activation activation;
private Tuple tuple;
private final InternalWorkingMemoryActions workingMemory;
private IdentityHashMap<Object,InternalFactHandle>
identityMap;

public SequentialKnowledgeHelper(final WorkingMemory workingMemory) {
this.workingMemory = (InternalWorkingMemoryActions) workingMemory;
Expand All @@ -65,7 +63,6 @@ public void setActivation(final Activation agendaItem) {
this.subrule = agendaItem.getSubRule();
this.activation = agendaItem;
this.tuple = agendaItem.getTuple();
this.identityMap = new IdentityHashMap<Object,InternalFactHandle>();
}

public void reset() {
Expand Down Expand Up @@ -158,14 +155,6 @@ public Map<String, Channel> getChannels() {
return Collections.unmodifiableMap( this.workingMemory.getChannels() );
}

public IdentityHashMap<Object, InternalFactHandle> getIdentityMap() {
return this.identityMap;
}

public void setIdentityMap(IdentityHashMap<Object, InternalFactHandle> identityMap) {
this.identityMap = identityMap;
}

public <T> T getContext(Class<T> contextClass) {
return null;
}
Expand Down
46 changes: 0 additions & 46 deletions drools-core/src/main/java/org/drools/core/base/TraitHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class TraitHelper implements Externalizable {

private InternalWorkingMemoryActions workingMemory;
private NamedEntryPoint entryPoint;
private IdentityHashMap<Object, FactHandle> identityMap;


public TraitHelper( InternalWorkingMemoryActions workingMemory, NamedEntryPoint nep ) {
Expand Down Expand Up @@ -257,10 +256,6 @@ private void checkStaticTypeCode( TraitableBean inner ) {
}

protected <T, K> T applyTrait( Activation activation, K core, Class<T> trait, Object value, boolean logical, Mode... modes ) throws LogicalTypeInconsistencyException {
if ( identityMap == null ) {
// traits and proxies can benefit from a cached lookup
identityMap = new IdentityHashMap<Object, FactHandle>( );
}
TraitFactory builder = TraitFactory.getTraitBuilderForKnowledgeBase( entryPoint.getKnowledgeBase() );

TraitableBean inner = makeTraitable( core, builder, logical, activation );
Expand Down Expand Up @@ -320,10 +315,6 @@ private <T> void updateCore( TraitableBean inner, Object core, Class<T> trait, b
logical,
activation.getRule(),
activation );
if ( this.identityMap != null ) {
this.identityMap.put( inner,
handle );
}
}

}
Expand Down Expand Up @@ -421,10 +412,6 @@ private <T, K> T asTrait( K core, TraitableBean inner, Class<T> trait, boolean n
logical,
activation.getRule(),
activation );
if ( this.identityMap != null ) {
this.identityMap.put( core,
h );
}
}
if ( ! h.isTraitOrTraitable() ) {
throw new IllegalStateException( "A traited working memory element is being used with a default fact handle. " +
Expand Down Expand Up @@ -466,10 +453,6 @@ private <K> TraitableBean makeTraitable( K core, TraitFactory builder, boolean l
logical,
activation.getRule(),
activation );
if ( this.identityMap != null ) {
this.identityMap.put( inner,
handle );
}
}
if ( ftms.needsInit() ) {
ftms.init( workingMemory );
Expand Down Expand Up @@ -506,9 +489,6 @@ private <K> InternalFactHandle lookupHandleForWrapper( K core ) {

public FactHandle lookupFactHandle(Object object) {
FactHandle handle = null;
if ( identityMap != null ) {
handle = identityMap.get( object );
}

if ( handle != null ) {
return handle;
Expand All @@ -532,19 +512,12 @@ private FactHandle getFactHandleFromWM(final Object object) {
// NOTE: it would probably be a good idea to create a specific attribute for that
handle = (FactHandle) entryPoint.getFactHandle( object );
if ( handle != null ) {
if ( identityMap != null ) {
identityMap.put( object,
handle );
}
}
return handle;
}

public FactHandle getFactHandle(Object object) {
FactHandle handle = null;
if ( identityMap != null ) {
handle = identityMap.get( object );
}

if ( handle != null ) {
return handle;
Expand All @@ -566,12 +539,10 @@ public FactHandle getFactHandle(Object object) {

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
workingMemory = (InternalWorkingMemoryActions) in.readObject();
identityMap = (IdentityHashMap<Object, FactHandle>) in.readObject();
}

public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject( workingMemory );
out.writeObject( identityMap );
}


Expand All @@ -584,10 +555,6 @@ public void update(final FactHandle handle,
onlyTraitBitSetMask(),
newObject.getClass(),
activation );
if ( identityMap != null ) {
identityMap.put( newObject,
handle );
}
}

public void update( final FactHandle handle,
Expand All @@ -610,9 +577,6 @@ public void delete( final FactHandle handle, Activation activation ) {
((InternalWorkingMemoryEntryPoint) ((InternalFactHandle) handle).getEntryPoint()).delete( handle,
activation.getRule(),
activation );
if ( this.identityMap != null ) {
this.identityMap.remove( o );
}
}

public FactHandle insert(final Object object,
Expand All @@ -623,11 +587,6 @@ public FactHandle insert(final Object object,
false,
activation.getRule(),
activation );
if ( this.identityMap != null ) {
this.identityMap.put( object,
handle );
}

return handle;
}

Expand All @@ -645,11 +604,6 @@ public void insertLogical(final Activation activation,
activation.getRule(),
activation );

if ( this.identityMap != null ) {
this.identityMap.put( object,
handle );
}

}

public void deleteWMAssertedTraitProxies( InternalFactHandle handle, RuleImpl rule, Activation activation ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ public void updateFactory(Object knowledgeHelper,

if ( knowledgeHelper instanceof KnowledgeHelper ) {
KnowledgeHelper kh = ( KnowledgeHelper ) knowledgeHelper;
kh.setIdentityMap( identityMap );
df.setKnowledgeHelper( kh );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ public InternalFactHandle insertLogical(Object object,

void halt();

IdentityHashMap<Object, InternalFactHandle> getIdentityMap();

void setIdentityMap(IdentityHashMap<Object, InternalFactHandle> identityMap);

<T> T getContext(Class<T> contextClass);

<T, K> T don( K core, Class<T> trait, boolean logical );
Expand Down

0 comments on commit 09e99d4

Please sign in to comment.