use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class StatefulKnowledgeSessionImpl method initInitialFact.
public InternalFactHandle initInitialFact(InternalKnowledgeBase kBase, InternalWorkingMemoryEntryPoint entryPoint, EntryPointId epId, MarshallerReaderContext context) {
InitialFact initialFact = InitialFactImpl.getInstance();
InternalFactHandle handle = new DefaultFactHandle(0, initialFact, 0, entryPoint);
ClassObjectTypeConf otc = (ClassObjectTypeConf) entryPoint.getObjectTypeConfigurationRegistry().getObjectTypeConf(epId, initialFact);
ObjectTypeNode otn = otc.getConcreteObjectTypeNode();
if (otn != null) {
PropagationContextFactory ctxFact = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
PropagationContext pctx = ctxFact.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, handle, epId, context);
otn.assertInitialFact(handle, pctx, this);
}
return handle;
}
use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class StatefulKnowledgeSessionImpl method internalGetQueryResult.
protected QueryResultsImpl internalGetQueryResult(boolean calledFromRHS, String queryName, Object... arguments) {
try {
startOperation();
this.lock.lock();
this.kBase.executeQueuedActions();
// eventually enqueued by events that have been inserted when already expired
if (calledFromRHS) {
flushPropagations();
flushPropagations();
} else {
agenda.executeFlush();
agenda.executeFlush();
}
DroolsQuery queryObject = new DroolsQuery(queryName, arguments, getQueryListenerInstance(), false, null, null, null, null, null);
InternalFactHandle handle = this.handleFactory.newFactHandle(queryObject, null, this, this);
final PropagationContext pCtx = pctxFactory.createPropagationContext(getNextPropagationIdCounter(), PropagationContext.Type.INSERTION, null, null, handle, getEntryPoint());
BaseNode[] tnodes = evalQuery(queryName, queryObject, handle, pCtx, calledFromRHS);
List<Map<String, Declaration>> decls = new ArrayList<Map<String, Declaration>>();
if (tnodes != null) {
for (BaseNode node : tnodes) {
decls.add(((QueryTerminalNode) node).getSubRule().getOuterDeclarations());
}
}
this.handleFactory.destroyFactHandle(handle);
return new QueryResultsImpl((List<QueryRowWithSubruleIndex>) queryObject.getQueryResultCollector().getResults(), decls.toArray(new Map[decls.size()]), this, (queryObject.getQuery() != null) ? queryObject.getQuery().getParameters() : new Declaration[0]);
} finally {
this.lock.unlock();
endOperation();
}
}
use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class DynamicEntryPoint method propagateInsert.
private void propagateInsert(InternalFactHandle handle) {
ObjectTypeConf typeConf = getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPointNode.getEntryPoint(), handle.getObject());
PropagationContext pctx = pctxFactory.createPropagationContext(this.wm.getNextPropagationIdCounter(), PropagationContext.Type.INSERTION, null, null, handle, this.entryPoint);
entryPointNode.assertObject(handle, pctx, typeConf, wm);
}
use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class NamedEntryPoint method insert.
public void insert(InternalFactHandle handle, Object object, RuleImpl rule, TerminalNode terminalNode, ObjectTypeConf typeConf) {
PropagationContext pctx = pctxFactory.createPropagationContext(this.wm.getNextPropagationIdCounter(), PropagationContext.Type.INSERTION, rule, terminalNode, handle, entryPoint);
insert(handle, object, rule, typeConf, pctx);
}
use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class NamedEntryPoint method update.
public InternalFactHandle update(InternalFactHandle handle, final Object object, final BitMask mask, final Class<?> modifiedClass, final Activation activation) {
try {
this.lock.lock();
this.wm.startOperation();
this.kBase.executeQueuedActions();
// the handle might have been disconnected, so reconnect if it has
if (handle.isDisconnected()) {
handle = this.objectStore.reconnect(handle);
}
final Object originalObject = handle.getObject();
if (handle.getEntryPoint() != this) {
throw new IllegalArgumentException("Invalid Entry Point. You updated the FactHandle on entry point '" + handle.getEntryPoint().getEntryPointId() + "' instead of '" + getEntryPointId() + "'");
}
final ObjectTypeConf typeConf = getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint, object);
if (handle.getId() == -1 || object == null || handle.isExpired()) {
// the handle is invalid, most likely already retracted, so return and we cannot assert a null object
return handle;
}
if (originalObject != object || !AssertBehaviour.IDENTITY.equals(this.kBase.getConfiguration().getAssertBehaviour())) {
this.objectStore.updateHandle(handle, object);
}
this.handleFactory.increaseFactHandleRecency(handle);
final PropagationContext propagationContext = pctxFactory.createPropagationContext(this.wm.getNextPropagationIdCounter(), PropagationContext.Type.MODIFICATION, activation == null ? null : activation.getRule(), activation == null ? null : activation.getTuple().getTupleSink(), handle, entryPoint, mask, modifiedClass, null);
if (typeConf.isTMSEnabled()) {
EqualityKey newKey = tms.get(object);
EqualityKey oldKey = handle.getEqualityKey();
if ((oldKey.getStatus() == EqualityKey.JUSTIFIED || oldKey.getBeliefSet() != null) && newKey != oldKey) {
// Mixed stated and justified, we cannot have updates untill we figure out how to use this.
throw new IllegalStateException("Currently we cannot modify something that has mixed stated and justified equal objects. " + "Rule " + activation.getRule().getName() + " attempted an illegal operation");
}
if (newKey == null) {
oldKey.removeFactHandle(handle);
newKey = new EqualityKey(handle, // updates are always stated
EqualityKey.STATED);
handle.setEqualityKey(newKey);
getTruthMaintenanceSystem().put(newKey);
} else if (newKey != oldKey) {
oldKey.removeFactHandle(handle);
handle.setEqualityKey(newKey);
newKey.addFactHandle(handle);
}
// If the old equality key is now empty, and no justified entries, remove it
if (oldKey.isEmpty() && oldKey.getLogicalFactHandle() == null) {
getTruthMaintenanceSystem().remove(oldKey);
}
}
if (handle.isTraitable() && object != originalObject && object instanceof TraitableBean && originalObject instanceof TraitableBean) {
this.traitHelper.replaceCore(handle, object, originalObject, propagationContext.getModificationMask(), object.getClass(), activation);
}
update(handle, object, originalObject, typeConf, propagationContext);
} finally {
this.wm.endOperation();
this.lock.unlock();
}
return handle;
}
Aggregations