Exemple #1
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());
    }
  }
Exemple #2
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());
     }
   }
 }