public static ProtobufMessages.Activation writeActivation( MarshallerWriteContext context, AgendaItem agendaItem) { ProtobufMessages.Activation.Builder _activation = ProtobufMessages.Activation.newBuilder(); RuleImpl rule = agendaItem.getRule(); _activation.setPackageName(rule.getPackage()); _activation.setRuleName(rule.getName()); _activation.setTuple(writeTuple(agendaItem.getTuple())); _activation.setSalience(agendaItem.getSalience()); _activation.setIsActivated(agendaItem.isQueued()); _activation.setEvaluated(agendaItem.isRuleAgendaItem()); if (agendaItem.getActivationGroupNode() != null) { _activation.setActivationGroup( agendaItem.getActivationGroupNode().getActivationGroup().getName()); } if (agendaItem.getFactHandle() != null) { _activation.setHandleId(agendaItem.getFactHandle().getId()); } org.drools.core.util.LinkedList<LogicalDependency> list = agendaItem.getLogicalDependencies(); if (list != null && !list.isEmpty()) { for (LogicalDependency node = list.getFirst(); node != null; node = node.getNext()) { _activation.addLogicalDependency(((BeliefSet) node.getJustified()).getFactHandle().getId()); } } return _activation.build(); }
public static void writeActivation( MarshallerWriteContext context, LeftTuple leftTuple, AgendaItem agendaItem, RuleTerminalNode ruleTerminalNode) throws IOException { ObjectOutputStream stream = context.stream; stream.writeLong(agendaItem.getActivationNumber()); stream.writeInt(context.terminalTupleMap.get(leftTuple)); stream.writeInt(agendaItem.getSalience()); Rule rule = agendaItem.getRule(); stream.writeUTF(rule.getPackage()); stream.writeUTF(rule.getName()); // context.out.println( "Rule " + rule.getPackage() + "." + rule.getName() ); // context.out.println( "AgendaItem long:" + // agendaItem.getPropagationContext().getPropagationNumber() ); stream.writeLong(agendaItem.getPropagationContext().getPropagationNumber()); if (agendaItem.getActivationGroupNode() != null) { stream.writeBoolean(true); // context.out.println( "ActivationGroup bool:" + true ); stream.writeUTF(agendaItem.getActivationGroupNode().getActivationGroup().getName()); // context.out.println( "ActivationGroup string:" + // agendaItem.getActivationGroupNode().getActivationGroup().getName() ); } else { stream.writeBoolean(false); // context.out.println( "ActivationGroup bool:" + false ); } stream.writeBoolean(agendaItem.isActivated()); // context.out.println( "AgendaItem bool:" + agendaItem.isActivated() ); if (agendaItem.getFactHandle() != null) { stream.writeBoolean(true); stream.writeInt(agendaItem.getFactHandle().getId()); } else { stream.writeBoolean(false); } org.drools.core.util.LinkedList list = agendaItem.getLogicalDependencies(); if (list != null && !list.isEmpty()) { for (LogicalDependency node = (LogicalDependency) list.getFirst(); node != null; node = (LogicalDependency) node.getNext()) { stream.writeShort(PersisterEnums.LOGICAL_DEPENDENCY); stream.writeInt(((InternalFactHandle) node.getJustified()).getId()); // context.out.println( "Logical Depenency : int " + ((InternalFactHandle) // node.getFactHandle()).getId() ); } } stream.writeShort(PersisterEnums.END); }
public static ProtobufMessages.Activation writeActivation( MarshallerWriteContext context, AgendaItem agendaItem) { ProtobufMessages.Activation.Builder _activation = ProtobufMessages.Activation.newBuilder(); Rule rule = agendaItem.getRule(); _activation.setPackageName(rule.getPackage()); _activation.setRuleName(rule.getName()); ProtobufMessages.Tuple.Builder _tb = ProtobufMessages.Tuple.newBuilder(); for (LeftTuple entry = agendaItem.getTuple(); entry != null; entry = entry.getParent()) { InternalFactHandle handle = entry.getLastHandle(); _tb.addHandleId(handle.getId()); } _activation.setTuple(_tb.build()); _activation.setSalience(agendaItem.getSalience()); _activation.setIsActivated(agendaItem.isActivated()); if (agendaItem.getActivationGroupNode() != null) { _activation.setActivationGroup( agendaItem.getActivationGroupNode().getActivationGroup().getName()); } if (agendaItem.getFactHandle() != null) { _activation.setHandleId(agendaItem.getFactHandle().getId()); } org.drools.core.util.LinkedList list = agendaItem.getLogicalDependencies(); if (list != null && !list.isEmpty()) { for (LogicalDependency node = (LogicalDependency) list.getFirst(); node != null; node = (LogicalDependency) node.getNext()) { _activation.addLogicalDependency(((InternalFactHandle) node.getJustified()).getId()); } } return _activation.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()); } }