コード例 #1
0
  /** {@inheritDoc} */
  public void endMaintenance() {
    log.info("Resuming transport listeners, senders and tasks from maintenance mode...");

    // resume transport listeners and senders
    Axis2TransportHelper transportHelper = new Axis2TransportHelper(configurationContext);
    transportHelper.resumeListeners();
    transportHelper.resumeSenders();

    // resume tasks
    SynapseTaskManager synapseTaskManager = synapseEnvironment.getTaskManager();
    if (synapseTaskManager.isInitialized()) {
      synapseTaskManager.resumeAll();
    }

    log.info("Resumed normal operation from maintenance mode");
  }
コード例 #2
0
  /** {@inheritDoc} */
  public void startMaintenance() {
    log.info("Putting transport listeners, senders and tasks into maintenance mode..");

    // pause transport listeners and senders
    Axis2TransportHelper transportHelper = new Axis2TransportHelper(configurationContext);
    transportHelper.pauseListeners();
    transportHelper.pauseSenders();

    // put tasks on hold
    SynapseTaskManager synapseTaskManager = synapseEnvironment.getTaskManager();
    if (synapseTaskManager.isInitialized()) {
      synapseTaskManager.pauseAll();
    }

    log.info("Entered maintenance mode");
  }
コード例 #3
0
  /**
   * Waits until it is safe to stop or the the specified end time has been reached. A delay of
   * <code>waitIntervalMillis</code> milliseconds is used between each subsequent check. If the
   * state "safeToStop" is reached before the specified <code>endTime</code>, the return value is
   * true.
   *
   * @param waitIntervalMillis the pause time (delay) in milliseconds between subsequent checks
   * @param endTime the time until which the checks need to finish successfully
   * @return true, if a safe state is reached before the specified <code>endTime</code>, otherwise
   *     false (forceful stop required)
   */
  public boolean waitUntilSafeToStop(long waitIntervalMillis, long endTime) {

    boolean safeToStop = false;
    boolean forcefulStop = false;
    Axis2TransportHelper transportHelper = new Axis2TransportHelper(configurationContext);

    // wait until it is safe to shutdown (listeners and tasks are idle, no callbacks)
    while (!safeToStop && !forcefulStop) {

      int pendingListenerThreads = transportHelper.getPendingListenerThreadCount();
      if (pendingListenerThreads > 0) {
        log.info(
            new StringBuilder("Waiting for: ")
                .append(pendingListenerThreads)
                .append(" listener threads to complete")
                .toString());
      }
      int pendingSenderThreads = transportHelper.getPendingSenderThreadCount();
      if (pendingSenderThreads > 0) {
        log.info(
            new StringBuilder("Waiting for: ")
                .append(pendingSenderThreads)
                .append(" listener threads to complete")
                .toString());
      }
      int activeConnections = transportHelper.getActiveConnectionsCount();
      if (activeConnections > 0) {
        log.info("Waiting for: " + activeConnections + " active connections to be closed..");
      }
      int pendingTransportThreads = pendingListenerThreads + pendingSenderThreads;

      int pendingCallbacks = serverContextInformation.getCallbackCount();
      if (pendingCallbacks > 0) {
        log.info("Waiting for: " + pendingCallbacks + " callbacks/replies..");
      }

      int runningTasks = 0;
      SynapseTaskManager synapseTaskManager = synapseEnvironment.getTaskManager();
      if (synapseTaskManager.isInitialized()) {
        runningTasks = synapseTaskManager.getTaskScheduler().getRunningTaskCount();
        if (runningTasks > 0) {
          log.info("Waiting for : " + runningTasks + " tasks to complete..");
        }
      }

      // it is safe to stop if all used listener threads, callbacks and tasks are zero
      safeToStop = ((pendingTransportThreads + pendingCallbacks + runningTasks) == 0);

      if (safeToStop) {
        log.info("All transport threads and tasks are idle and no pending callbacks..");
      } else {
        if (System.currentTimeMillis() < endTime) {
          log.info(
              new StringBuilder("Waiting for a maximum of another ")
                  .append((endTime - System.currentTimeMillis()) / 1000)
                  .append(" seconds until transport threads and tasks become idle, ")
                  .append("active connections to get closed,")
                  .append(" and callbacks to be completed..")
                  .toString());
          try {
            Thread.sleep(waitIntervalMillis);
          } catch (InterruptedException ignore) {
            // nothing to do here
          }
        } else {
          // maximum time to wait is over, do a forceful stop
          forcefulStop = true;
        }
      }
    }

    return !forcefulStop;
  }
コード例 #4
0
  /** Cleanup the axis2 environment and stop the synapse environment. */
  public void stop() {
    try {
      // stop tasks
      SynapseTaskManager synapseTaskManager = synapseEnvironment.getTaskManager();
      if (synapseTaskManager.isInitialized()) {
        synapseTaskManager.cleanup();
      }

      EnterpriseBeanstalkManager manager =
          (EnterpriseBeanstalkManager)
              serverContextInformation.getProperty(
                  EnterpriseBeanstalkConstants.BEANSTALK_MANAGER_PROP_NAME);
      if (manager != null) {
        manager.destroy();
      }

      // stop the listener manager
      if (listenerManager != null) {
        listenerManager.stop();
      }

      // detach the synapse handlers
      if (configurationContext != null) {
        List<Phase> inflowPhases = configurationContext.getAxisConfiguration().getInFlowPhases();
        for (Phase inPhase : inflowPhases) {
          // we are interested about the Dispatch phase in the inflow
          if (PhaseMetadata.PHASE_DISPATCH.equals(inPhase.getPhaseName())) {
            List<HandlerDescription> synapseHandlers = new ArrayList<HandlerDescription>();
            for (Handler handler : inPhase.getHandlers()) {
              if (SynapseDispatcher.NAME.equals(handler.getName())
                  || SynapseMustUnderstandHandler.NAME.equals(handler.getName())) {
                synapseHandlers.add(handler.getHandlerDesc());
              }
            }

            for (HandlerDescription handlerMD : synapseHandlers) {
              inPhase.removeHandler(handlerMD);
            }
          }
        }
      } else {
        handleException(
            "Couldn't detach the Synapse handlers, " + "ConfigurationContext not found.");
      }

      // continue stopping the axis2 environment if we created it
      if (serverConfigurationInformation.isCreateNewInstance()
          && configurationContext != null
          && configurationContext.getAxisConfiguration() != null) {
        Map<String, AxisService> serviceMap =
            configurationContext.getAxisConfiguration().getServices();
        for (AxisService svc : serviceMap.values()) {
          svc.setActive(false);
        }

        // stop all modules
        Map<String, AxisModule> moduleMap =
            configurationContext.getAxisConfiguration().getModules();
        for (AxisModule mod : moduleMap.values()) {
          if (mod.getModule() != null && !"synapse".equals(mod.getName())) {
            mod.getModule().shutdown(configurationContext);
          }
        }
      }
    } catch (AxisFault e) {
      log.error("Error stopping the Axis2 Environment");
    }
  }