/** QTZ-205 */
  @Test
  public void testTriggerFinalized() throws Exception {
    Qtz205TriggerListener triggerListener = new Qtz205TriggerListener();
    Qtz205ScheListener schedulerListener = new Qtz205ScheListener();
    Properties props = new Properties();
    props.setProperty("org.quartz.scheduler.idleWaitTime", "1500");
    props.setProperty("org.quartz.threadPool.threadCount", "2");
    Scheduler scheduler = new StdSchedulerFactory(props).getScheduler();
    scheduler.getListenerManager().addSchedulerListener(schedulerListener);
    scheduler.getListenerManager().addTriggerListener(triggerListener);
    scheduler.start();
    scheduler.standby();

    JobDetail job = newJob(Qtz205Job.class).withIdentity("test").build();
    Trigger trigger =
        newTrigger()
            .withIdentity("test")
            .withSchedule(simpleSchedule().withIntervalInMilliseconds(250).withRepeatCount(2))
            .build();
    scheduler.scheduleJob(job, trigger);
    scheduler.start();
    Thread.sleep(5000);

    scheduler.shutdown(true);

    Assert.assertEquals(2, Qtz205Job.jobExecutionCount);
    Assert.assertEquals(3, triggerListener.getFireCount());
    Assert.assertEquals(1, schedulerListener.getTriggerFinalizedCount());
  }
Пример #2
0
  public boolean stop() {
    try {
      if (scheduler != null && scheduler.isStarted()) {

        // This is to immediately stop the scheduler to avoid firing new services
        scheduler.standby();

        if (logger.isDebugEnabled()) {
          logger.debug("ShuttingDown Message Processor Scheduler : " + scheduler.getMetaData());
        }

        try {
          scheduler.interrupt(
              new JobKey(
                  name + "-job", MessageProcessorConstants.SCHEDULED_MESSAGE_PROCESSOR_GROUP));
        } catch (UnableToInterruptJobException e) {
          logger.info("Unable to interrupt job [" + name + "-job]");
        }

        // gracefully shutdown
        scheduler.shutdown(true);
      }

    } catch (SchedulerException e) {
      throw new SynapseException("Error ShuttingDown Message processor scheduler ", e);
    }

    if (logger.isDebugEnabled()) {
      logger.debug("Stopped message processor [" + getName() + "].");
    }

    return true;
  }
Пример #3
0
  public boolean deactivate() {
    try {
      if (scheduler != null && scheduler.isStarted()) {
        if (logger.isDebugEnabled()) {
          logger.debug("Deactivating message processor [" + getName() + "]");
        }

        // This is to immediately stop the scheduler to avoid firing new services
        scheduler.standby();

        try {
          scheduler.interrupt(
              new JobKey(
                  name + "-job", MessageProcessorConstants.SCHEDULED_MESSAGE_PROCESSOR_GROUP));
        } catch (UnableToInterruptJobException e) {
          logger.info("Unable to interrupt job [" + name + "-job]");
        }

        // This is to remove the consumer from the queue.
        messageConsumer.cleanup();

        if (logger.isDebugEnabled()) {
          logger.debug("Successfully deactivated the message processor [" + getName() + "]");
        }

        setActivated(isActive());

        // This means the deactivation has happened automatically. So we have to persist the
        // deactivation manually.
        if (isPaused()) {
          try {
            // TODO: Need to make sure if this is the best way.
            String directory = configuration.getPathToConfigFile() + "/message-processors";
            DeploymentEngine deploymentEngine =
                (DeploymentEngine) configuration.getAxisConfiguration().getConfigurator();
            MessageProcessorDeployer dep =
                (MessageProcessorDeployer) deploymentEngine.getDeployer(directory, "xml");
            dep.restoreSynapseArtifact(name);
          } catch (Exception e) {
            logger.warn("Couldn't persist the state of the message processor [" + name + "]");
          }
        }

        return true;
      } else {
        return false;
      }
    } catch (SchedulerException e) {
      throw new SynapseException("Error Standing-by Message processor scheduler ", e);
    }
  }