예제 #1
0
  /**
   * Inform the <code>JobStore</code> that the scheduler is now firing the given <code>Trigger
   * </code> (executing its associated <code>Job</code>), that it had previously acquired
   * (reserved).
   *
   * @return null if the trigger or its job or calendar no longer exist, or if the trigger was not
   *     successfully put into the 'executing' state.
   */
  public TriggerFiredBundle triggerFired(SchedulingContext ctxt, Trigger trigger)
      throws JobPersistenceException {
    synchronized (m_triggerLock) {
      if (!isEligibleGroupName(trigger.getGroup())) {
        return null;
      }
      WrappedTrigger wt = m_triggersByGroupAndName.get(getTriggerKey(trigger));
      if ((wt != null) && (wt.getState() == TRIGGER_STATE_CLAIMED)) {
        wt.setState(TRIGGER_STATE_EXECUTING);
        Calendar cal = null;
        if (trigger.getCalendarName() != null) {
          cal = retrieveCalendar(ctxt, trigger.getCalendarName());
        }
        Date prevFiredTime = trigger.getPreviousFireTime();
        trigger.triggered(cal);
        TriggerFiredBundle tfb =
            new TriggerFiredBundle(
                retrieveJob(ctxt, trigger.getJobName(), trigger.getJobGroup()),
                trigger,
                cal,
                false,
                new Date(),
                trigger.getPreviousFireTime(),
                prevFiredTime,
                trigger.getNextFireTime());

        return tfb;
      }
      return null;
    }
  }
  public static Trigger convertTriggerFromNativeObject(org.quartz.Trigger quartzTrigger) {
    Trigger spagobiTrigger;

    spagobiTrigger = new Trigger();
    spagobiTrigger.setName(quartzTrigger.getName());
    spagobiTrigger.setGroupName(quartzTrigger.getGroup());
    spagobiTrigger.setDescription(quartzTrigger.getDescription());

    // spagobiTrigger.setCalendarName( quartzTrigger.getCalendarName() );
    Assert.assertTrue(
        quartzTrigger.getCalendarName() == null,
        "quartz trigger calendar name is not null: " + quartzTrigger.getCalendarName());

    spagobiTrigger.setStartTime(quartzTrigger.getStartTime());
    spagobiTrigger.setEndTime(quartzTrigger.getEndTime());

    // triggers that run immediately have a generated name that starts with schedule_uuid_ (see
    // TriggerXMLDeserializer)
    // It would be better anyway to relay on a specific property to recognize if a trigger is
    // thinked to run immediately
    spagobiTrigger.setRunImmediately(spagobiTrigger.getName().startsWith("schedule_uuid_"));

    if (quartzTrigger instanceof org.quartz.CronTrigger) {
      org.quartz.CronTrigger quartzCronTrigger = (org.quartz.CronTrigger) quartzTrigger;
      // dirty trick
      String expression = (String) quartzCronTrigger.getJobDataMap().get(SPAGOBI_CRON_EXPRESSION);
      if (expression != null) {
        quartzCronTrigger.getJobDataMap().remove(SPAGOBI_CRON_EXPRESSION);
      } else {
        // for back compatibility
        expression =
            (String) quartzCronTrigger.getJobDataMap().get(SPAGOBI_CRON_EXPRESSION_DEPRECATED);
        quartzCronTrigger.getJobDataMap().remove(SPAGOBI_CRON_EXPRESSION_DEPRECATED);
      }
      spagobiTrigger.setCronExpression(new CronExpression(expression));
    }

    Job job = new Job();
    job.setName(quartzTrigger.getJobName());
    job.setGroupName(quartzTrigger.getJobGroup());
    job.setVolatile(quartzTrigger.isVolatile());
    Map<String, String> parameters =
        convertParametersFromNativeObject(quartzTrigger.getJobDataMap());
    job.addParameters(parameters);

    spagobiTrigger.setJob(job);

    return spagobiTrigger;
  }