Example #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 ) {
    //
    //        }
  }
 public static ProtobufMessages.Trigger writeTrigger(
     Trigger trigger, MarshallerWriteContext outCtx) {
   if (trigger instanceof CronTrigger) {
     CronTrigger cronTrigger = (CronTrigger) trigger;
     ProtobufMessages.Trigger.CronTrigger.Builder _cron =
         ProtobufMessages.Trigger.CronTrigger.newBuilder()
             .setStartTime(cronTrigger.getStartTime().getTime())
             .setRepeatLimit(cronTrigger.getRepeatLimit())
             .setRepeatCount(cronTrigger.getRepeatCount())
             .setCronExpression(cronTrigger.getCronEx().getCronExpression());
     if (cronTrigger.getEndTime() != null) {
       _cron.setEndTime(cronTrigger.getEndTime().getTime());
     }
     if (cronTrigger.getNextFireTime() != null) {
       _cron.setNextFireTime(cronTrigger.getNextFireTime().getTime());
     }
     if (cronTrigger.getCalendarNames() != null) {
       for (String calendarName : cronTrigger.getCalendarNames()) {
         _cron.addCalendarName(calendarName);
       }
     }
     return ProtobufMessages.Trigger.newBuilder()
         .setType(ProtobufMessages.Trigger.TriggerType.CRON)
         .setCron(_cron.build())
         .build();
   } else if (trigger instanceof IntervalTrigger) {
     IntervalTrigger intTrigger = (IntervalTrigger) trigger;
     ProtobufMessages.Trigger.IntervalTrigger.Builder _interval =
         ProtobufMessages.Trigger.IntervalTrigger.newBuilder()
             .setStartTime(intTrigger.getStartTime().getTime())
             .setRepeatLimit(intTrigger.getRepeatLimit())
             .setRepeatCount(intTrigger.getRepeatCount())
             .setPeriod(intTrigger.getPeriod());
     if (intTrigger.getEndTime() != null) {
       _interval.setEndTime(intTrigger.getEndTime().getTime());
     }
     if (intTrigger.getNextFireTime() != null) {
       _interval.setNextFireTime(intTrigger.getNextFireTime().getTime());
     }
     if (intTrigger.getCalendarNames() != null) {
       for (String calendarName : intTrigger.getCalendarNames()) {
         _interval.addCalendarName(calendarName);
       }
     }
     return ProtobufMessages.Trigger.newBuilder()
         .setType(ProtobufMessages.Trigger.TriggerType.INTERVAL)
         .setInterval(_interval.build())
         .build();
   } else if (trigger instanceof PointInTimeTrigger) {
     PointInTimeTrigger pinTrigger = (PointInTimeTrigger) trigger;
     return ProtobufMessages.Trigger.newBuilder()
         .setType(ProtobufMessages.Trigger.TriggerType.POINT_IN_TIME)
         .setPit(
             ProtobufMessages.Trigger.PointInTimeTrigger.newBuilder()
                 .setNextFireTime(pinTrigger.hasNextFireTime().getTime())
                 .build())
         .build();
   }
   throw new RuntimeException("Unable to serialize Trigger for type: " + trigger.getClass());
 }
  public static Trigger readTrigger(MarshallerReaderContext inCtx)
      throws IOException, ClassNotFoundException {
    short triggerInt = inCtx.readShort();

    switch (triggerInt) {
      case PersisterEnums.CRON_TRIGGER:
        {
          long startTime = inCtx.readLong();

          CronTrigger trigger = new CronTrigger();
          trigger.setStartTime(new Date(startTime));
          if (inCtx.readBoolean()) {
            long endTime = inCtx.readLong();
            trigger.setEndTime(new Date(endTime));
          }

          int repeatLimit = inCtx.readInt();
          trigger.setRepeatLimit(repeatLimit);

          int repeatCount = inCtx.readInt();
          trigger.setRepeatCount(repeatCount);

          String expr = inCtx.readUTF();
          trigger.setCronExpression(expr);
          if (inCtx.readBoolean()) {
            long nextFireTime = inCtx.readLong();
            trigger.setNextFireTime(new Date(nextFireTime));
          }

          String[] calendarNames = (String[]) inCtx.readObject();
          trigger.setCalendarNames(calendarNames);
          return trigger;
        }
      case PersisterEnums.INT_TRIGGER:
        {
          IntervalTrigger trigger = new IntervalTrigger();
          long startTime = inCtx.readLong();
          trigger.setStartTime(new Date(startTime));
          if (inCtx.readBoolean()) {
            long endTime = inCtx.readLong();
            trigger.setEndTime(new Date(endTime));
          }
          int repeatLimit = inCtx.readInt();
          trigger.setRepeatLimit(repeatLimit);
          int repeatCount = inCtx.readInt();
          trigger.setRepeatCount(repeatCount);
          if (inCtx.readBoolean()) {
            long nextFireTime = inCtx.readLong();
            trigger.setNextFireTime(new Date(nextFireTime));
          }
          long period = inCtx.readLong();
          trigger.setPeriod(period);
          String[] calendarNames = (String[]) inCtx.readObject();
          trigger.setCalendarNames(calendarNames);
          return trigger;
        }
      case PersisterEnums.POINT_IN_TIME_TRIGGER:
        {
          long startTime = inCtx.readLong();

          PointInTimeTrigger trigger = new PointInTimeTrigger(startTime, null, null);
          return trigger;
        }
    }
    throw new RuntimeException("Unable to persist Trigger for type: " + triggerInt);
  }