use of org.drools.core.reteoo.ObjectTypeConf in project drools by kiegroup.
the class InputMarshaller method readFactHandle.
public static InternalFactHandle readFactHandle(MarshallerReaderContext context) throws IOException, ClassNotFoundException {
int type = context.stream.readInt();
int id = context.stream.readInt();
long recency = context.stream.readLong();
long startTimeStamp = 0;
long duration = 0;
boolean expired = false;
long activationsCount = 0;
if (type == 2) {
startTimeStamp = context.stream.readLong();
duration = context.stream.readLong();
expired = context.stream.readBoolean();
activationsCount = context.stream.readLong();
}
int strategyIndex = context.stream.readInt();
Object object = null;
ObjectMarshallingStrategy strategy = null;
// This is the old way of de/serializing strategy objects
if (strategyIndex >= 0) {
strategy = context.resolverStrategyFactory.getStrategy(strategyIndex);
} else // This is the new way
if (strategyIndex == -2) {
String strategyClassName = context.stream.readUTF();
if (!StringUtils.isEmpty(strategyClassName)) {
strategy = context.resolverStrategyFactory.getStrategyObject(strategyClassName);
if (strategy == null) {
throw new IllegalStateException("No strategy of type " + strategyClassName + " available.");
}
}
}
// If either way retrieves a strategy, use it
if (strategy != null) {
object = strategy.read(context.stream);
}
EntryPoint entryPoint = null;
if (context.readBoolean()) {
String entryPointId = context.readUTF();
if (entryPointId != null && !entryPointId.equals("")) {
entryPoint = ((RuleRuntime) context.wm).getEntryPoint(entryPointId);
}
}
EntryPointId confEP;
if (entryPoint != null) {
confEP = ((NamedEntryPoint) entryPoint).getEntryPoint();
} else {
confEP = context.wm.getEntryPoint();
}
ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf(confEP, object);
InternalFactHandle handle = null;
switch(type) {
case 0:
{
handle = new DefaultFactHandle(id, object, recency, (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
break;
}
case 1:
{
handle = new QueryElementFactHandle(object, id, recency);
break;
}
case 2:
{
handle = new EventFactHandle(id, object, recency, startTimeStamp, duration, (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
((EventFactHandle) handle).setExpired(expired);
((EventFactHandle) handle).setActivationsCount(activationsCount);
break;
}
default:
{
throw new IllegalStateException("Unable to marshal FactHandle, as type does not exist:" + type);
}
}
return handle;
}
use of org.drools.core.reteoo.ObjectTypeConf in project drools by kiegroup.
the class ProtobufInputMarshaller method readFactHandle.
public static InternalFactHandle readFactHandle(MarshallerReaderContext context, EntryPoint entryPoint, FactHandle _handle) throws IOException, ClassNotFoundException {
Object object = null;
ObjectMarshallingStrategy strategy = null;
if (_handle.hasStrategyIndex()) {
strategy = context.usedStrategies.get(_handle.getStrategyIndex());
object = strategy.unmarshal(context.strategyContexts.get(strategy), context, _handle.getObject().toByteArray(), (context.kBase == null) ? null : context.kBase.getRootClassLoader());
}
EntryPointId confEP;
if (entryPoint != null) {
confEP = ((NamedEntryPoint) entryPoint).getEntryPoint();
} else {
confEP = context.wm.getEntryPoint();
}
ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf(confEP, object);
InternalFactHandle handle = null;
switch(_handle.getType()) {
case FACT:
{
handle = new DefaultFactHandle(_handle.getId(), object, _handle.getRecency(), (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
break;
}
case QUERY:
{
handle = new QueryElementFactHandle(object, _handle.getId(), _handle.getRecency());
break;
}
case EVENT:
{
handle = new EventFactHandle(_handle.getId(), object, _handle.getRecency(), _handle.getTimestamp(), _handle.getDuration(), (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
((EventFactHandle) handle).setExpired(_handle.getIsExpired());
((EventFactHandle) handle).setOtnCount(_handle.getOtnCount());
// ((EventFactHandle) handle).setActivationsCount( _handle.getActivationsCount() );
break;
}
default:
{
throw new IllegalStateException("Unable to marshal FactHandle, as type does not exist:" + _handle.getType());
}
}
return handle;
}
use of org.drools.core.reteoo.ObjectTypeConf 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.reteoo.ObjectTypeConf 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.reteoo.ObjectTypeConf in project drools by kiegroup.
the class ProtobufInputMarshaller method assertHandleIntoOTN.
private static void assertHandleIntoOTN(MarshallerReaderContext context, InternalWorkingMemory wm, InternalFactHandle handle, List<PropagationContext> pctxs) {
Object object = handle.getObject();
WorkingMemoryEntryPoint ep = handle.getEntryPoint();
ObjectTypeConf typeConf = ep.getObjectTypeConfigurationRegistry().getObjectTypeConf(ep.getEntryPoint(), object);
PropagationContextFactory pctxFactory = wm.getKnowledgeBase().getConfiguration().getComponentFactory().getPropagationContextFactory();
PropagationContext propagationContext = pctxFactory.createPropagationContext(wm.getNextPropagationIdCounter(), PropagationContext.Type.INSERTION, null, null, handle, ep.getEntryPoint(), context);
// keeping this list for a later cleanup is necessary because of the lazy propagations that might occur
pctxs.add(propagationContext);
ep.getEntryPointNode().assertObject(handle, propagationContext, typeConf, wm);
wm.flushPropagations();
}
Aggregations