示例#1
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;
  }
 /**
  * Check if the scheduler is started.
  *
  * @throws JobSchedulerException thrown if the scheduler status cannot be checked
  */
 public boolean isStarted() throws JobSchedulerException {
   try {
     return scheduler.isStarted();
   } catch (SchedulerException e) {
     throw new JobSchedulerException(
         "An exception occurred during checking if the scheduler is started", e);
   }
 }
示例#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);
    }
  }