public static void readTruthMaintenanceSystem( MarshallerReaderContext context, SessionEntryPoint wmep, ProtobufMessages.EntryPoint _ep, List<PropagationContextImpl> pctxs) throws IOException, ClassNotFoundException { TruthMaintenanceSystem tms = ((NamedEntryPoint) wmep).getTruthMaintenanceSystem(); 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()) { 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); readBeliefSet(context, tms, key, _key.getBeliefSet()); } }
public static void writeTruthMaintenanceSystem( MarshallerWriteContext context, EntryPoint wmep, ProtobufMessages.EntryPoint.Builder _epb) throws IOException { TruthMaintenanceSystem tms = ((NamedEntryPoint) wmep).getTruthMaintenanceSystem(); ObjectHashMap justifiedMap = tms.getEqualityKeyMap(); if (!justifiedMap.isEmpty()) { EqualityKey[] keys = new EqualityKey[justifiedMap.size()]; org.drools.core.util.Iterator it = justifiedMap.iterator(); int i = 0; for (org.drools.core.util.ObjectHashMap.ObjectEntry entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next()) { EqualityKey key = (EqualityKey) entry.getKey(); keys[i++] = key; } Arrays.sort(keys, EqualityKeySorter.instance); ProtobufMessages.TruthMaintenanceSystem.Builder _tms = ProtobufMessages.TruthMaintenanceSystem.newBuilder(); // write the assert map of Equality keys for (EqualityKey key : keys) { ProtobufMessages.EqualityKey.Builder _key = ProtobufMessages.EqualityKey.newBuilder(); _key.setStatus(key.getStatus()); _key.setHandleId(key.getFactHandle().getId()); if (key.size() > 1) { // add all the other key's if they exist FastIterator keyIter = key.fastIterator(); for (DefaultFactHandle handle = key.getFirst().getNext(); handle != null; handle = (DefaultFactHandle) keyIter.next(handle)) { _key.addOtherHandle(handle.getId()); } } if (key.getBeliefSet() != null) { writeBeliefSet(context, key.getBeliefSet(), _key); } _tms.addKey(_key.build()); } _epb.setTms(_tms.build()); } }
public static void writeTruthMaintenanceSystem( MarshallerWriteContext context, ProtobufMessages.RuleData.Builder _session) throws IOException { ObjectHashMap assertMap = context.wm.getTruthMaintenanceSystem().getAssertMap(); ObjectHashMap justifiedMap = context.wm.getTruthMaintenanceSystem().getJustifiedMap(); if (!assertMap.isEmpty() || !justifiedMap.isEmpty()) { EqualityKey[] keys = new EqualityKey[assertMap.size()]; org.drools.core.util.Iterator it = assertMap.iterator(); int i = 0; for (org.drools.core.util.ObjectHashMap.ObjectEntry entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next()) { EqualityKey key = (EqualityKey) entry.getKey(); keys[i++] = key; } Arrays.sort(keys, EqualityKeySorter.instance); ProtobufMessages.TruthMaintenanceSystem.Builder _tms = ProtobufMessages.TruthMaintenanceSystem.newBuilder(); // write the assert map of Equality keys for (EqualityKey key : keys) { ProtobufMessages.EqualityKey.Builder _key = ProtobufMessages.EqualityKey.newBuilder(); _key.setStatus(key.getStatus()); _key.setHandleId(key.getFactHandle().getId()); if (key.getOtherFactHandle() != null && !key.getOtherFactHandle().isEmpty()) { for (InternalFactHandle handle : key.getOtherFactHandle()) { _key.addOtherHandle(handle.getId()); } } _tms.addKey(_key.build()); } it = justifiedMap.iterator(); i = 0; for (org.drools.core.util.ObjectHashMap.ObjectEntry entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next()) { ProtobufMessages.Justification.Builder _justification = ProtobufMessages.Justification.newBuilder(); _justification.setHandleId(((Integer) entry.getKey()).intValue()); org.drools.core.util.LinkedList list = (org.drools.core.util.LinkedList) entry.getValue(); for (LinkedListEntry node = (LinkedListEntry) list.getFirst(); node != null; node = (LinkedListEntry) node.getNext()) { LogicalDependency dependency = (LogicalDependency) node.getObject(); org.drools.spi.Activation activation = dependency.getJustifier(); ProtobufMessages.Activation _activation = ProtobufMessages.Activation.newBuilder() .setPackageName(activation.getRule().getPackage()) .setRuleName(activation.getRule().getName()) .setTuple(PersisterHelper.createTuple(activation.getTuple())) .build(); _justification.addActivation(_activation); } _tms.addJustification(_justification.build()); } _session.setTms(_tms.build()); } }