Java Code Examples for org.apache.activemq.ActiveMQConnection#addTransportListener()

The following examples show how to use org.apache.activemq.ActiveMQConnection#addTransportListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsProxyImpl.java    From c2mon with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Runs until (re)connected. Should only be called by one thread. Use
 * startReconnectThread to run in another thread (only one thread will be
 * started however many calls are made).
 * <p>
 * Listeners are notified of connection once the connection is reestablished
 * and all topic subscriptions are back.
 */
private synchronized void connect() {
  while (!connected && !shutdownRequested) {
    try {
      connection = (ActiveMQConnection) jmsConnectionFactory.createConnection();
      connection.start();
      connection.addTransportListener((ActiveMQTransportListener) this::startReconnectThread);
      refreshSubscriptions();
      connected = true;
    } catch (Exception e) {
      log.error("Exception caught while trying to refresh the JMS connection; sleeping 5s before retrying.", e);
      try {
        wait(SLEEP_BETWEEN_CONNECTION_ATTEMPTS);
      } catch (InterruptedException interEx) {
        log.error("InterruptedException caught while waiting to reconnect.", interEx);
      }
    }
  }
  if (connected) {
    notifyConnectionListenerOnConnection();
  }
}
 
Example 2
Source File: ReconnectTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public Worker(final String name) throws URISyntaxException, JMSException {
   this.name = name;
   URI uri = new URI("failover://(mock://(" + tcpUri + "))?updateURIsSupported=false");
   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(uri);
   connection = (ActiveMQConnection) factory.createConnection();
   connection.addTransportListener(new TransportListener() {
      @Override
      public void onCommand(Object command) {
      }

      @Override
      public void onException(IOException error) {
         setError(error);
      }

      @Override
      public void transportInterupted() {
         LOG.info("Worker " + name + " was interrupted...");
         interruptedCount.incrementAndGet();
      }

      @Override
      public void transportResumed() {
         LOG.info("Worker " + name + " was resummed...");
         resumedCount.incrementAndGet();
      }
   });
   connection.start();
}
 
Example 3
Source File: ActiveMQConn.java    From zipkin-reporter-java with Apache License 2.0 4 votes vote down vote up
ActiveMQConn(ActiveMQConnection connection, QueueSession session, QueueSender sender) {
  this.connection = connection;
  this.session = session;
  this.sender = sender;
  connection.addTransportListener(this);
}