Esempio n. 1
0
  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();
  }