Пример #1
0
  private boolean checkJMSConnection(ServiceTaskManager stm) {

    Connection connection = null;
    Hashtable<String, String> jmsProperties = stm.getJmsProperties();
    try {
      ConnectionFactory jmsConFactory = null;
      try {
        jmsConFactory =
            JMSUtils.lookup(
                new InitialContext(stm.getJmsProperties()),
                ConnectionFactory.class,
                stm.getConnFactoryJNDIName());
      } catch (NamingException e) {
        log.error(
            "Error looking up connection factory : "
                + stm.getConnFactoryJNDIName()
                + "using JNDI properties : "
                + jmsProperties,
            e);
      }
      connection =
          JMSUtils.createConnection(
              jmsConFactory,
              jmsProperties.get(JMSConstants.PARAM_JMS_USERNAME),
              jmsProperties.get(JMSConstants.PARAM_JMS_PASSWORD),
              stm.isJmsSpec11(),
              null,
              false,
              "");
    } catch (JMSException ignore) {
    } // we silently ignore this as a JMSException can be expected when connection is not available

    return (connection != null);
  }
Пример #2
0
  /**
   * Stops listening for messages for the service thats undeployed or stopped
   *
   * @param endpoint the jms endpoint which is connected with the service
   */
  @Override
  protected void stopEndpoint(JMSEndpoint endpoint) {
    ServiceTaskManager stm = endpoint.getServiceTaskManager();
    if (log.isDebugEnabled()) {
      log.debug(
          "Stopping listening on destination : "
              + stm.getDestinationJNDIName()
              + " for service : "
              + stm.getServiceName());
    }

    stm.stop();

    log.info("Stopped listening for JMS messages to service : " + endpoint.getServiceName());
  }
  /**
   * Create a ServiceTaskManager for the service passed in and its corresponding
   * JMSConnectionFactory
   *
   * @param jcf
   * @param service
   * @param workerPool
   * @return
   */
  public static ServiceTaskManager createTaskManagerForService(
      JMSConnectionFactory jcf, AxisService service, WorkerPool workerPool) {

    String name = service.getName();
    Map<String, String> svc = getServiceStringParameters(service.getParameters());
    Map<String, String> cf = jcf.getParameters();

    ServiceTaskManager stm = new ServiceTaskManager();

    stm.setServiceName(name);
    stm.addJmsProperties(cf);
    stm.addJmsProperties(svc);

    stm.setConnFactoryJNDIName(getRqdStringProperty(JMSConstants.PARAM_CONFAC_JNDI_NAME, svc, cf));
    String destName = getOptionalStringProperty(JMSConstants.PARAM_DESTINATION, svc, cf);
    if (destName == null) {
      destName = service.getName();
    }
    stm.setDestinationJNDIName(destName);
    stm.setDestinationType(getDestinationType(svc, cf));
    if (getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf) != null
        && getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf)) {
      stm.setDurableSubscriberClientId(
          getRqdStringProperty(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID, svc, cf));
    }

    stm.setJmsSpec11(getJMSSpecVersion(svc, cf));
    stm.setTransactionality(getTransactionality(svc, cf));
    stm.setCacheUserTransaction(
        getOptionalBooleanProperty(BaseConstants.PARAM_CACHE_USER_TXN, svc, cf));
    stm.setUserTransactionJNDIName(
        getOptionalStringProperty(BaseConstants.PARAM_USER_TXN_JNDI_NAME, svc, cf));
    stm.setSessionTransacted(
        getOptionalBooleanProperty(JMSConstants.PARAM_SESSION_TRANSACTED, svc, cf));
    stm.setSessionAckMode(getSessionAck(svc, cf));
    stm.setMessageSelector(getOptionalStringProperty(JMSConstants.PARAM_MSG_SELECTOR, svc, cf));
    stm.setSubscriptionDurable(getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf));
    stm.setDurableSubscriberName(
        getOptionalStringProperty(JMSConstants.PARAM_DURABLE_SUB_NAME, svc, cf));

    stm.setCacheLevel(getCacheLevel(svc, cf));
    stm.setPubSubNoLocal(getOptionalBooleanProperty(JMSConstants.PARAM_PUBSUB_NO_LOCAL, svc, cf));

    Integer value = getOptionalIntProperty(JMSConstants.PARAM_RCV_TIMEOUT, svc, cf);
    if (value != null) {
      stm.setReceiveTimeout(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_CONCURRENT_CONSUMERS, svc, cf);
    if (value != null) {
      stm.setConcurrentConsumers(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_MAX_CONSUMERS, svc, cf);
    if (value != null) {
      stm.setMaxConcurrentConsumers(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_IDLE_TASK_LIMIT, svc, cf);
    if (value != null) {
      stm.setIdleTaskExecutionLimit(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_MAX_MSGS_PER_TASK, svc, cf);
    if (value != null) {
      stm.setMaxMessagesPerTask(value);
    }

    value = getOptionalIntProperty(JMSConstants.PARAM_RECON_INIT_DURATION, svc, cf);
    if (value != null) {
      stm.setInitialReconnectDuration(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_RECON_MAX_DURATION, svc, cf);
    if (value != null) {
      stm.setMaxReconnectDuration(value);
    }
    Double dValue = getOptionalDoubleProperty(JMSConstants.PARAM_RECON_FACTOR, svc, cf);
    if (dValue != null) {
      stm.setReconnectionProgressionFactor(dValue);
    }

    stm.setWorkerPool(workerPool);

    // remove processed properties from property bag
    stm.removeJmsProperties(JMSConstants.PARAM_CONFAC_JNDI_NAME);
    stm.removeJmsProperties(JMSConstants.PARAM_DESTINATION);
    stm.removeJmsProperties(JMSConstants.PARAM_JMS_SPEC_VER);
    stm.removeJmsProperties(BaseConstants.PARAM_TRANSACTIONALITY);
    stm.removeJmsProperties(BaseConstants.PARAM_CACHE_USER_TXN);
    stm.removeJmsProperties(BaseConstants.PARAM_USER_TXN_JNDI_NAME);
    stm.removeJmsProperties(JMSConstants.PARAM_SESSION_TRANSACTED);
    stm.removeJmsProperties(JMSConstants.PARAM_MSG_SELECTOR);
    stm.removeJmsProperties(JMSConstants.PARAM_SUB_DURABLE);
    stm.removeJmsProperties(JMSConstants.PARAM_DURABLE_SUB_NAME);
    stm.removeJmsProperties(JMSConstants.PARAM_CACHE_LEVEL);
    stm.removeJmsProperties(JMSConstants.PARAM_PUBSUB_NO_LOCAL);
    stm.removeJmsProperties(JMSConstants.PARAM_RCV_TIMEOUT);
    stm.removeJmsProperties(JMSConstants.PARAM_CONCURRENT_CONSUMERS);
    stm.removeJmsProperties(JMSConstants.PARAM_MAX_CONSUMERS);
    stm.removeJmsProperties(JMSConstants.PARAM_IDLE_TASK_LIMIT);
    stm.removeJmsProperties(JMSConstants.PARAM_MAX_MSGS_PER_TASK);
    stm.removeJmsProperties(JMSConstants.PARAM_RECON_INIT_DURATION);
    stm.removeJmsProperties(JMSConstants.PARAM_RECON_MAX_DURATION);
    stm.removeJmsProperties(JMSConstants.PARAM_RECON_FACTOR);
    stm.removeJmsProperties(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID);

    return stm;
  }
Пример #4
0
  /**
   * Listen for JMS messages on behalf of the given service
   *
   * @param endpoint the jms endpoint which is connected with the service
   */
  @Override
  protected void startEndpoint(JMSEndpoint endpoint) throws AxisFault {
    ServiceTaskManager stm = endpoint.getServiceTaskManager();
    boolean connected = false;

    /* The following parameters are used when trying to connect with the JMS provider at the start up*/
    int r = 1;
    long retryDuration = 10000;
    double reconnectionProgressionFactor = 2.0;
    long maxReconnectDuration = 1000 * 60 * 60; // 1 hour

    // First we will check whether jms provider is started or not, as if not it will throw a
    // continuous error log
    // If jms provider not started we will wait for exponentially increasing time intervals, till
    // the provider is started
    while (!connected) {
      boolean jmsProviderStarted = checkJMSConnection(stm);
      if (jmsProviderStarted) {
        log.info(
            "Connection attempt: "
                + r
                + " for JMS Provider for service: "
                + stm.getServiceName()
                + " was successful!");
        connected = true;
        stm.start();

        for (int i = 0; i < 3; i++) {
          // Check the consumer count rather than the active task count. Reason: if the
          // destination is of type topic, then the transport is only ready to receive
          // messages if at least one consumer exists. This is of not much importance,
          // except for automated tests.
          if (stm.getConsumerCount() > 0) {
            log.info(
                "Started to listen on destination : "
                    + stm.getDestinationJNDIName()
                    + " of type "
                    + JMSUtils.getDestinationTypeAsString(stm.getDestinationType())
                    + " for service "
                    + stm.getServiceName());
            return;
          }
          try {
            Thread.sleep(1000);
          } catch (InterruptedException ignore) {
          }
        }

        log.warn(
            "Polling tasks on destination : "
                + stm.getDestinationJNDIName()
                + " of type "
                + JMSUtils.getDestinationTypeAsString(stm.getDestinationType())
                + " for service "
                + stm.getServiceName()
                + " have not yet started after 3 seconds ..");
      } else {
        log.error(
            "Unable to continue server startup as it seems the JMS Provider is not yet started. Please start the JMS provider now.");
        retryDuration = (long) (retryDuration * reconnectionProgressionFactor);
        log.error(
            "Connection attempt : "
                + (r++)
                + " for JMS Provider failed. Next retry in "
                + (retryDuration / 1000)
                + " seconds");
        if (retryDuration > maxReconnectDuration) {
          retryDuration = maxReconnectDuration;
        }
        try {
          Thread.sleep(retryDuration);
        } catch (InterruptedException ignore) {
        }
      }
    }
  }