예제 #1
0
  /** Cleans up all resources that are still in use. */
  public synchronized void close() {
    for (ClientConsumer consumer : dataConsumers) {
      try {
        consumer.close();
      } catch (HornetQException e) {
        // ignore exception
      }
    }

    dataConsumers.clear();

    try {
      if (session != null) {
        session.close();
      }
    } catch (Exception e) {
      // ignore exception
    } finally {
      if (sessionFactory != null) {
        sessionFactory.close();
      }
      if (locator != null) {
        locator.close();
      }
    }

    for (ConnectionListener cl : connectionListeners) {
      cl.disconnected();
    }
  }
예제 #2
0
  /**
   * Connects to the yamcs server. This method blocks until a connection is established or some
   * error has occurred, thus this should be called in a separate thread. Hornetq will try
   * indefinitely to establish the connection and also provides automatic re-connection afterwards.
   *
   * @throws Exception if the hornetq session could not be established due to some error
   */
  public void connect() throws Exception {
    for (ConnectionListener cl : connectionListeners) {
      cl.connecting(connParams.getUrl());
    }

    Map<String, Object> tcpConfig = new HashMap<String, Object>();
    tcpConfig.put(TransportConstants.HOST_PROP_NAME, connParams.host);
    tcpConfig.put(TransportConstants.PORT_PROP_NAME, connParams.port);

    locator =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(NettyConnectorFactory.class.getName(), tcpConfig));

    locator.setInitialConnectAttempts(initialConnectAttempts);
    locator.setReconnectAttempts(reconnectAttempts);
    locator.setRetryInterval(retryInterval);
    locator.setRetryIntervalMultiplier(retryIntervalMultiplier);
    locator.setMaxRetryInterval(maxRetryInterval);
    locator.setAckBatchSize(ackBatchSize);

    sessionFactory = locator.createSessionFactory();

    // TODO Use hornetq auth (like YamcsConnector), or keep anonymous connection?
    session = sessionFactory.createSession(false, true, true, preAcknowledge);
    session.addFailureListener(YamcsAckConnector.this);
    session.start();

    for (ConnectionListener cl : connectionListeners) {
      cl.connected(connParams.getUrl());
    }
  }
예제 #3
0
 public void connectionFailed(HornetQException e, boolean failedOver) {
   if (failedOver) {
     logger.info("reconnected to yamcs: {}", e.getMessage());
     for (ConnectionListener cl : connectionListeners) {
       cl.connected(connParams.getUrl());
     }
   } else {
     logger.warn("connection to yamcs failed: {}", e.getMessage());
     for (ConnectionListener cl : connectionListeners) {
       cl.connectionFailed(connParams.getUrl(), new YamcsException(e.getMessage(), e));
       cl.log(e.getMessage());
     }
   }
 }
예제 #4
0
  public void beforeReconnect(HornetQException e) {
    logger.warn("disconnected from yamcs: {}", e.getMessage());
    for (ConnectionListener cl : connectionListeners) {
      cl.disconnected();
      cl.log(e.getMessage());
    }

    // clear all pending messages in the data consumers, as they will be re-submitted
    // by yamcs upon re-connect
    for (ClientConsumer consumer : dataConsumers) {
      try {
        MessageHandler handler = consumer.getMessageHandler();
        if (handler instanceof ClientAckMessageHandler) {
          ((ClientAckMessageHandler) handler).clearPendingMessages();
        }
      } catch (HornetQException e1) {
        // ignore
      }
    }
  }