use of org.drools.core.reteoo.ObjectTypeConf in project drools by kiegroup.
the class NamedEntryPoint method insert.
public FactHandle insert(final Object object, final boolean dynamic, final RuleImpl rule, final TerminalNode terminalNode) {
if (object == null) {
// you cannot assert a null object
return null;
}
try {
this.wm.startOperation();
ObjectTypeConf typeConf = getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint, object);
final PropagationContext propagationContext = this.pctxFactory.createPropagationContext(this.wm.getNextPropagationIdCounter(), PropagationContext.Type.INSERTION, rule, terminalNode, null, entryPoint);
if (this.wm.isSequential()) {
InternalFactHandle handle = createHandle(object, typeConf);
propagationContext.setFactHandle(handle);
insert(handle, object, rule, typeConf, propagationContext);
return handle;
}
InternalFactHandle handle;
try {
this.lock.lock();
// check if the object already exists in the WM
handle = this.objectStore.getHandleForObject(object);
if (!typeConf.isTMSEnabled()) {
// TMS not enabled for this object type
if (handle != null) {
return handle;
}
handle = createHandle(object, typeConf);
} else {
TruthMaintenanceSystem tms = getTruthMaintenanceSystem();
EqualityKey key;
if (handle != null && handle.getEqualityKey().getStatus() == EqualityKey.STATED) {
// it's already stated, so just return the handle
return handle;
} else {
key = tms.get(object);
}
if (key != null && key.getStatus() == EqualityKey.JUSTIFIED) {
// The justified set needs to be staged, before we can continue with the stated insert
BeliefSet bs = handle.getEqualityKey().getBeliefSet();
// staging will set it's status to stated
bs.getBeliefSystem().stage(propagationContext, bs);
}
handle = createHandle(object, // we know the handle is null
typeConf);
if (key == null) {
key = new EqualityKey(handle, EqualityKey.STATED);
tms.put(key);
} else {
key.addFactHandle(handle);
}
handle.setEqualityKey(key);
}
propagationContext.setFactHandle(handle);
// @propertyChangeSupport
if (dynamic || typeConf.isDynamic()) {
addPropertyChangeListener(handle, dynamic);
}
insert(handle, object, rule, typeConf, propagationContext);
} finally {
this.lock.unlock();
}
return handle;
} finally {
this.wm.endOperation();
}
}
use of org.drools.core.reteoo.ObjectTypeConf in project drools by kiegroup.
the class NamedEntryPoint method deleteStated.
private void deleteStated(RuleImpl rule, TerminalNode terminalNode, InternalFactHandle handle, EqualityKey key) {
if (key != null && key.getStatus() == EqualityKey.JUSTIFIED) {
return;
}
if (handle.isTraitable()) {
traitHelper.deleteWMAssertedTraitProxies(handle, rule, terminalNode);
}
final Object object = handle.getObject();
final ObjectTypeConf typeConf = getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint, object);
if (typeConf.isDynamic()) {
removePropertyChangeListener(handle, true);
}
PropagationContext propagationContext = delete(handle, object, typeConf, rule, null, terminalNode);
deleteFromTMS(handle, key, typeConf, propagationContext);
this.handleFactory.destroyFactHandle(handle);
}
use of org.drools.core.reteoo.ObjectTypeConf in project drools by kiegroup.
the class NamedEntryPoint method removeFromObjectStore.
public void removeFromObjectStore(InternalFactHandle handle) {
this.objectStore.removeHandle(handle);
ObjectTypeConf typeConf = getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint, handle.getObject());
deleteFromTMS(handle, handle.getEqualityKey(), typeConf, null);
}
use of org.drools.core.reteoo.ObjectTypeConf in project drools by kiegroup.
the class NamedEntryPoint method insertAsync.
public FactHandle insertAsync(Object object) {
ObjectTypeConf typeConf = getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint, object);
PropagationContext pctx = this.pctxFactory.createPropagationContext(this.wm.getNextPropagationIdCounter(), PropagationContext.Type.INSERTION, null, null, null, entryPoint);
InternalFactHandle handle = createHandle(object, typeConf);
pctx.setFactHandle(handle);
this.entryPointNode.assertObject(handle, pctx, typeConf, this.wm);
this.wm.getRuleRuntimeEventSupport().fireObjectInserted(pctx, handle, object, this.wm);
return handle;
}
use of org.drools.core.reteoo.ObjectTypeConf in project drools by kiegroup.
the class TruthMaintenanceSystem method get.
public EqualityKey get(final Object object) {
EqualityKey key = (EqualityKey) this.equalityKeyMap.get(object);
if (key == null && assertBehaviour == AssertBehaviour.EQUALITY) {
// Edge case: another object X, equivalent (equals+hashcode) to "object" Y
// has been previously stated. However, if X is a subclass of Y, TMS
// may have not been enabled yet, and key would be null.
InternalFactHandle fh = ep.getObjectStore().getHandleForObject(object);
if (fh != null) {
key = fh.getEqualityKey();
if (key == null) {
// we use the FH's Object here, not the inserted object
ObjectTypeConf typeC = this.typeConfReg.getObjectTypeConf(ep.getEntryPoint(), fh.getObject());
enableTMS(fh.getObject(), typeC);
key = fh.getEqualityKey();
}
}
}
return key;
}
Aggregations