示例#1
0
  public static void writeTrigger(Trigger trigger, MarshallerWriteContext outCtx)
      throws IOException {
    if (trigger instanceof CronTrigger) {
      outCtx.writeShort(PersisterEnums.CRON_TRIGGER);

      CronTrigger cronTrigger = (CronTrigger) trigger;
      outCtx.writeLong(cronTrigger.getStartTime().getTime());
      if (cronTrigger.getEndTime() != null) {
        outCtx.writeBoolean(true);
        outCtx.writeLong(cronTrigger.getEndTime().getTime());
      } else {
        outCtx.writeBoolean(false);
      }
      outCtx.writeInt(cronTrigger.getRepeatLimit());
      outCtx.writeInt(cronTrigger.getRepeatCount());
      outCtx.writeUTF(cronTrigger.getCronEx().getCronExpression());
      if (cronTrigger.getNextFireTime() != null) {
        outCtx.writeBoolean(true);
        outCtx.writeLong(cronTrigger.getNextFireTime().getTime());
      } else {
        outCtx.writeBoolean(false);
      }
      outCtx.writeObject(cronTrigger.getCalendarNames());
    } else if (trigger instanceof IntervalTrigger) {
      outCtx.writeShort(PersisterEnums.INT_TRIGGER);

      IntervalTrigger intTrigger = (IntervalTrigger) trigger;
      outCtx.writeLong(intTrigger.getStartTime().getTime());
      if (intTrigger.getEndTime() != null) {
        outCtx.writeBoolean(true);
        outCtx.writeLong(intTrigger.getEndTime().getTime());
      } else {
        outCtx.writeBoolean(false);
      }
      outCtx.writeInt(intTrigger.getRepeatLimit());
      outCtx.writeInt(intTrigger.getRepeatCount());
      if (intTrigger.getNextFireTime() != null) {
        outCtx.writeBoolean(true);
        outCtx.writeLong(intTrigger.getNextFireTime().getTime());
      } else {
        outCtx.writeBoolean(false);
      }
      outCtx.writeLong(intTrigger.getPeriod());
      outCtx.writeObject(intTrigger.getCalendarNames());
    } else if (trigger instanceof PointInTimeTrigger) {
      outCtx.writeShort(PersisterEnums.POINT_IN_TIME_TRIGGER);

      PointInTimeTrigger pinTrigger = (PointInTimeTrigger) trigger;

      outCtx.writeLong(pinTrigger.hasNextFireTime().getTime());
    }

    //        else if ( trigger instanceof DelayedTrigger ) {
    //
    //        } else if ( trigger instanceof PointInTimeTrigger ) {
    //
    //        } else if ( trigger instanceof CompositeMaxDurationTimer ) {
    //
    //        }
  }
示例#2
0
  public static void writeAgenda(MarshallerWriteContext context) throws IOException {
    InternalWorkingMemory wm = context.wm;
    DefaultAgenda agenda = (DefaultAgenda) wm.getAgenda();

    context.writeInt(agenda.getDormantActivations());
    context.writeInt(agenda.getActiveActivations());

    Map<String, ActivationGroup> activationGroups = agenda.getActivationGroupsMap();

    AgendaGroup[] agendaGroups =
        (AgendaGroup[])
            agenda
                .getAgendaGroupsMap()
                .values()
                .toArray(new AgendaGroup[agenda.getAgendaGroupsMap().size()]);
    Arrays.sort(agendaGroups, AgendaGroupSorter.instance);

    for (AgendaGroup group : agendaGroups) {
      context.writeShort(PersisterEnums.AGENDA_GROUP);
      context.writeUTF(group.getName());
      context.writeBoolean(group.isActive());
    }
    context.writeShort(PersisterEnums.END);

    LinkedList<AgendaGroup> focusStack = agenda.getStackList();
    for (Iterator<AgendaGroup> it = focusStack.iterator(); it.hasNext(); ) {
      AgendaGroup group = it.next();
      context.writeShort(PersisterEnums.AGENDA_GROUP);
      context.writeUTF(group.getName());
    }
    context.writeShort(PersisterEnums.END);

    RuleFlowGroupImpl[] ruleFlowGroups =
        (RuleFlowGroupImpl[])
            agenda
                .getRuleFlowGroupsMap()
                .values()
                .toArray(new RuleFlowGroupImpl[agenda.getRuleFlowGroupsMap().size()]);
    Arrays.sort(ruleFlowGroups, RuleFlowGroupSorter.instance);

    for (RuleFlowGroupImpl group : ruleFlowGroups) {
      context.writeShort(PersisterEnums.RULE_FLOW_GROUP);
      // group.write( context );
      context.writeUTF(group.getName());
      context.writeBoolean(group.isActive());
      context.writeBoolean(group.isAutoDeactivate());
      Map<Long, String> nodeInstances = group.getNodeInstances();
      context.writeInt(nodeInstances.size());
      for (Map.Entry<Long, String> entry : nodeInstances.entrySet()) {
        context.writeLong(entry.getKey());
        context.writeUTF(entry.getValue());
      }
    }
    context.writeShort(PersisterEnums.END);
  }
示例#3
0
  public static void writeSession(MarshallerWriteContext context) throws IOException {
    // context.out.println( "... write session");
    ReteooWorkingMemory wm = (ReteooWorkingMemory) context.wm;
    wm.getAgenda().unstageActivations();

    final boolean multithread = wm.isPartitionManagersActive();
    // is multi-thread active?
    if (multithread) {
      context.writeBoolean(true);
      wm.stopPartitionManagers();
    } else {
      context.writeBoolean(false);
    }

    long time = 0;
    if (context.wm.getTimerService() instanceof PseudoClockScheduler) {
      time = context.clockTime;
    }
    context.writeLong(time);

    context.writeInt(wm.getFactHandleFactory().getId());
    context.writeLong(wm.getFactHandleFactory().getRecency());
    //// context.out.println( "FactHandleFactory int:" + wm.getFactHandleFactory().getId() + "
    // long:" + wm.getFactHandleFactory().getRecency() );

    context.writeLong(wm.getPropagationIdCounter());
    // context.out.println( "PropagationCounter long:" + wm.getPropagationIdCounter() );

    InternalFactHandle handle = context.wm.getInitialFactHandle();
    context.writeInt(handle.getId());
    context.writeLong(handle.getRecency());
    // context.out.println( "InitialFact int:" + handle.getId() + " long:" + handle.getRecency() );

    writeAgenda(context);

    writeInitialFactHandleRightTuples(context);
    for (WorkingMemoryEntryPoint wmep : wm.getEntryPoints().values()) {
      context.stream.writeShort(PersisterEnums.ENTRY_POINT);
      context.stream.writeUTF(wmep.getEntryPointId());
      writeFactHandles(context, ((NamedEntryPoint) wmep).getObjectStore());
    }
    context.stream.writeShort(PersisterEnums.END);
    writeInitialFactHandleLeftTuples(context);

    writePropagationContexts(context);

    writeActivations(context);

    writeActionQueue(context);

    writeTruthMaintenanceSystem(context);

    if (context.marshalProcessInstances && processMarshaller != null) {
      processMarshaller.writeProcessInstances(context);
    } else {
      context.stream.writeShort(PersisterEnums.END);
    }

    if (context.marshalWorkItems && processMarshaller != null) {
      processMarshaller.writeWorkItems(context);
    } else {
      context.stream.writeShort(PersisterEnums.END);
    }

    if (processMarshaller != null) {
      // this now just assigns the writer, it will not write out any timer information
      processMarshaller.writeProcessTimers(context);
    } else {
      context.stream.writeShort(PersisterEnums.END);
    }

    // Only works for JpaJDKTimerService
    writeTimers(context.wm.getTimerService().getTimerJobInstances(), context);

    if (multithread) {
      wm.startPartitionManagers();
    }

    // context.out.println( "--- write session --- END");
  }