Search in sources :

Example 11 with TransportListener

use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.

the class WireformatNegociationTest method startClient.

/**
 * @throws Exception
 * @throws URISyntaxException
 */
private void startClient(String uri) throws Exception, URISyntaxException {
    clientTransport = TransportFactory.connect(new URI(uri));
    clientTransport.setTransportListener(new TransportListener() {

        @Override
        public void onCommand(Object command) {
            if (command instanceof WireFormatInfo) {
                clientWF.set((WireFormatInfo) command);
                negotiationCounter.countDown();
            }
        }

        @Override
        public void onException(IOException error) {
            if (!ignoreAsycError.get()) {
                LOG.info("Client transport error: ", error);
                asyncError.set(error);
                negotiationCounter.countDown();
            }
        }

        @Override
        public void transportInterupted() {
        }

        @Override
        public void transportResumed() {
        }
    });
    clientTransport.start();
}
Also used : TransportListener(org.apache.activemq.transport.TransportListener) WireFormatInfo(org.apache.activemq.command.WireFormatInfo) IOException(java.io.IOException) URI(java.net.URI)

Example 12 with TransportListener

use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.

the class InactivityMonitorTest method startClient.

/**
 * @throws Exception
 * @throws URISyntaxException
 */
private void startClient() throws Exception, URISyntaxException {
    clientTransport = TransportFactory.connect(new URI("tcp://localhost:" + serverPort + "?trace=true&wireFormat.maxInactivityDuration=1000"));
    clientTransport.setTransportListener(new TransportListener() {

        @Override
        public void onCommand(Object command) {
            clientReceiveCount.incrementAndGet();
            if (clientRunOnCommand != null) {
                clientRunOnCommand.run();
            }
        }

        @Override
        public void onException(IOException error) {
            if (!ignoreClientError.get()) {
                LOG.info("Client transport error:");
                error.printStackTrace();
                clientErrorCount.incrementAndGet();
            }
        }

        @Override
        public void transportInterupted() {
        }

        @Override
        public void transportResumed() {
        }
    });
    clientTransport.start();
}
Also used : TransportListener(org.apache.activemq.transport.TransportListener) IOException(java.io.IOException) URI(java.net.URI)

Example 13 with TransportListener

use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.

the class InactivityMonitorTest method onAccept.

@Override
public void onAccept(Transport transport) {
    try {
        LOG.info("[" + getName() + "] Server Accepted a Connection");
        serverTransport = transport;
        serverTransport.setTransportListener(new TransportListener() {

            @Override
            public void onCommand(Object command) {
                serverReceiveCount.incrementAndGet();
                if (serverRunOnCommand != null) {
                    serverRunOnCommand.run();
                }
            }

            @Override
            public void onException(IOException error) {
                if (!ignoreClientError.get()) {
                    LOG.info("Server transport error:", error);
                    serverErrorCount.incrementAndGet();
                }
            }

            @Override
            public void transportInterupted() {
            }

            @Override
            public void transportResumed() {
            }
        });
        serverTransport.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : TransportListener(org.apache.activemq.transport.TransportListener) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 14 with TransportListener

use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.

the class InactivityMonitorTest method testClientHang.

public void testClientHang() throws Exception {
    // Manually create a client transport so that it does not send KeepAlive
    // packets.  this should simulate a client hang.
    clientTransport = new TcpTransport(new OpenWireFormat(), SocketFactory.getDefault(), new URI("tcp://localhost:" + serverPort), null);
    clientTransport.setTransportListener(new TransportListener() {

        @Override
        public void onCommand(Object command) {
            clientReceiveCount.incrementAndGet();
            if (clientRunOnCommand != null) {
                clientRunOnCommand.run();
            }
        }

        @Override
        public void onException(IOException error) {
            if (!ignoreClientError.get()) {
                LOG.info("Client transport error:");
                error.printStackTrace();
                clientErrorCount.incrementAndGet();
            }
        }

        @Override
        public void transportInterupted() {
        }

        @Override
        public void transportResumed() {
        }
    });
    clientTransport.start();
    WireFormatInfo info = new WireFormatInfo();
    info.setVersion(OpenWireFormat.DEFAULT_LEGACY_VERSION);
    info.setMaxInactivityDuration(1000);
    clientTransport.oneway(info);
    assertEquals(0, serverErrorCount.get());
    assertEquals(0, clientErrorCount.get());
    // Server should consider the client timed out right away since the
    // client is not hart beating fast enough.
    Thread.sleep(6000);
    assertEquals(0, clientErrorCount.get());
    assertTrue(serverErrorCount.get() > 0);
}
Also used : OpenWireFormat(org.apache.activemq.openwire.OpenWireFormat) TransportListener(org.apache.activemq.transport.TransportListener) WireFormatInfo(org.apache.activemq.command.WireFormatInfo) IOException(java.io.IOException) URI(java.net.URI)

Example 15 with TransportListener

use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.

the class FailoverTransportBackupsTest method createTransport.

protected Transport createTransport(int backups) throws Exception {
    String connectionUri = "failover://(" + newURI(0) + "," + newURI(1) + "," + newURI(2) + ")";
    if (backups > 0) {
        connectionUri += "?randomize=false&backup=true&backupPoolSize=" + backups;
    }
    Transport transport = TransportFactory.connect(new URI(connectionUri));
    transport.setTransportListener(new TransportListener() {

        @Override
        public void onCommand(Object command) {
            LOG.debug("Test Transport Listener received Command: " + command);
        }

        @Override
        public void onException(IOException error) {
            LOG.debug("Test Transport Listener received Exception: " + error);
        }

        @Override
        public void transportInterupted() {
            transportInterruptions++;
            LOG.debug("Test Transport Listener records transport Interrupted: " + transportInterruptions);
        }

        @Override
        public void transportResumed() {
            transportResumptions++;
            LOG.debug("Test Transport Listener records transport Resumed: " + transportResumptions);
        }
    });
    transport.start();
    this.failoverTransport = transport.narrow(FailoverTransport.class);
    return transport;
}
Also used : TransportListener(org.apache.activemq.transport.TransportListener) IOException(java.io.IOException) Transport(org.apache.activemq.transport.Transport) URI(java.net.URI)

Aggregations

TransportListener (org.apache.activemq.transport.TransportListener)16 IOException (java.io.IOException)15 URI (java.net.URI)8 Transport (org.apache.activemq.transport.Transport)6 Test (org.junit.Test)5 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)4 WireFormatInfo (org.apache.activemq.command.WireFormatInfo)3 URISyntaxException (java.net.URISyntaxException)2 Connection (javax.jms.Connection)2 JMSException (javax.jms.JMSException)2 Message (javax.jms.Message)2 Queue (javax.jms.Queue)2 Session (javax.jms.Session)2 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)2 OpenwireArtemisBaseTest (org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest)2 BrokerInfo (org.apache.activemq.command.BrokerInfo)2 TransportAcceptListener (org.apache.activemq.transport.TransportAcceptListener)2 ArrayDeque (java.util.ArrayDeque)1 NoSuchElementException (java.util.NoSuchElementException)1 Properties (java.util.Properties)1