use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class ProtobufInputMarshaller method readTruthMaintenanceSystem.
public static void readTruthMaintenanceSystem(MarshallerReaderContext context, EntryPoint wmep, ProtobufMessages.EntryPoint _ep, List<PropagationContext> pctxs) throws IOException, ClassNotFoundException {
TruthMaintenanceSystem tms = ((NamedEntryPoint) wmep).getTruthMaintenanceSystem();
// if 0, then the OTC was not serialized (older versions of drools)
boolean wasOTCSerialized = _ep.getOtcCount() > 0;
Set<String> tmsEnabled = new HashSet<String>();
for (ObjectTypeConfiguration _otc : _ep.getOtcList()) {
if (_otc.getTmsEnabled()) {
tmsEnabled.add(_otc.getType());
}
}
ProtobufMessages.TruthMaintenanceSystem _tms = _ep.getTms();
for (ProtobufMessages.EqualityKey _key : _tms.getKeyList()) {
InternalFactHandle handle = (InternalFactHandle) context.handles.get(_key.getHandleId());
// ObjectTypeConf state is not marshalled, so it needs to be re-determined
ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf(((NamedEntryPoint) handle.getEntryPoint()).getEntryPoint(), handle.getObject());
if (!typeConf.isTMSEnabled() && (!wasOTCSerialized || tmsEnabled.contains(typeConf.getTypeName()))) {
typeConf.enableTMS();
}
EqualityKey key = new EqualityKey(handle, _key.getStatus());
handle.setEqualityKey(key);
if (key.getStatus() == EqualityKey.JUSTIFIED) {
// not yet added to the object stores
((NamedEntryPoint) handle.getEntryPoint()).getObjectStore().addHandle(handle, handle.getObject());
// add handle to object type node
assertHandleIntoOTN(context, context.wm, handle, pctxs);
}
for (Integer factHandleId : _key.getOtherHandleList()) {
handle = (InternalFactHandle) context.handles.get(factHandleId.intValue());
key.addFactHandle(handle);
handle.setEqualityKey(key);
}
tms.put(key);
context.filter.fireRNEAs(context.wm);
readBeliefSet(context, tms, key, _key);
}
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class ProtobufInputMarshaller method readFactHandles.
public static void readFactHandles(MarshallerReaderContext context, org.drools.core.marshalling.impl.ProtobufMessages.EntryPoint _ep, ObjectStore objectStore, List<PropagationContext> pctxs) throws IOException, ClassNotFoundException {
InternalWorkingMemory wm = context.wm;
EntryPoint entryPoint = ((StatefulKnowledgeSessionImpl) context.wm).getEntryPointMap().get(_ep.getEntryPointId());
// load the handles
for (ProtobufMessages.FactHandle _handle : _ep.getHandleList()) {
InternalFactHandle handle = readFactHandle(context, entryPoint, _handle);
context.handles.put(handle.getId(), handle);
if (!_handle.getIsJustified()) {
// BeliefSystem handles the Object type
if (handle.getObject() != null) {
objectStore.addHandle(handle, handle.getObject());
}
// add handle to object type node
assertHandleIntoOTN(context, wm, handle, pctxs);
}
}
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class ProtobufInputMarshaller method readBeliefSet.
private static void readBeliefSet(MarshallerReaderContext context, TruthMaintenanceSystem tms, EqualityKey key, ProtobufMessages.EqualityKey _key) throws IOException, ClassNotFoundException {
if (_key.hasBeliefSet()) {
ProtobufMessages.BeliefSet _beliefSet = _key.getBeliefSet();
InternalFactHandle handle = (InternalFactHandle) context.handles.get(_key.getHandleId());
// phreak might serialize empty belief sets, so he have to handle it during deserialization
if (_beliefSet.getLogicalDependencyCount() > 0) {
for (ProtobufMessages.LogicalDependency _logicalDependency : _beliefSet.getLogicalDependencyList()) {
ProtobufMessages.Activation _activation = _logicalDependency.getActivation();
Activation activation = (Activation) context.filter.getTuplesCache().get(PersisterHelper.createActivationKey(_activation.getPackageName(), _activation.getRuleName(), _activation.getTuple())).getContextObject();
Object object = null;
ObjectMarshallingStrategy strategy = null;
if (_logicalDependency.hasObjectStrategyIndex()) {
strategy = context.usedStrategies.get(_logicalDependency.getObjectStrategyIndex());
object = strategy.unmarshal(context.strategyContexts.get(strategy), context, _logicalDependency.getObject().toByteArray(), (context.kBase == null) ? null : context.kBase.getRootClassLoader());
}
Object value = null;
if (_logicalDependency.hasValueStrategyIndex()) {
strategy = context.usedStrategies.get(_logicalDependency.getValueStrategyIndex());
value = strategy.unmarshal(context.strategyContexts.get(strategy), context, _logicalDependency.getValue().toByteArray(), (context.kBase == null) ? null : context.kBase.getRootClassLoader());
}
ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf(((NamedEntryPoint) handle.getEntryPoint()).getEntryPoint(), handle.getObject());
tms.readLogicalDependency(handle, object, value, activation, activation.getPropagationContext(), activation.getRule(), typeConf);
}
} else {
handle.getEqualityKey().setBeliefSet(tms.getBeliefSystem().newBeliefSet(handle));
}
}
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class CursoredDataSource method bind.
@Override
public void bind(RuleUnit unit, WorkingMemoryEntryPoint ep) {
setWorkingMemory(ep.getInternalWorkingMemory());
PropagationList propagationList = propagationsMap.get(unit.getUnitIdentity());
if (propagationList != null) {
flush(ep, propagationList.takeAll());
} else {
Iterator<InternalFactHandle> fhs = objectStore.iterateFactHandles();
while (fhs.hasNext()) {
new Insert((DataSourceFactHandle) fhs.next()).execute(ep);
}
propagationsMap.put(unit.getUnitIdentity(), new SynchronizedPropagationList(((WorkingMemoryEntryPoint) ep).getInternalWorkingMemory()));
}
currentUnit = unit.getUnitIdentity();
currentEntryPoint = ep;
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class StatelessKnowledgeSessionImpl method executeWithResults.
public List executeWithResults(Iterable objects, ObjectFilter filter) {
List list = new ArrayList();
StatefulKnowledgeSession ksession = newWorkingMemory();
try {
for (Object object : objects) {
ksession.insert(object);
}
ksession.fireAllRules();
for (FactHandle fh : ksession.getFactHandles(filter)) {
list.add(((InternalFactHandle) fh).getObject());
}
} finally {
dispose(ksession);
}
return list;
}
Aggregations