Search in sources :

Example 6 with TransportListener

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

the class FailoverTransportTest method createTransport.

protected Transport createTransport() throws Exception {
    Transport transport = TransportFactory.connect(new URI("failover://(tcp://localhost:1234?transport.connectTimeout=10000)"));
    transport.setTransportListener(new TransportListener() {

        @Override
        public void onCommand(Object command) {
        }

        @Override
        public void onException(IOException error) {
        }

        @Override
        public void transportInterupted() {
        }

        @Override
        public void transportResumed() {
        }
    });
    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)

Example 7 with TransportListener

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

the class InitalReconnectDelayTest method testNoSuspendedCallbackOnNoReconnect.

@Test
public void testNoSuspendedCallbackOnNoReconnect() throws Exception {
    String uriString = "failover://(" + newURI(1) + "," + newURI(2) + ")?randomize=false&maxReconnectAttempts=0";
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(uriString);
    final AtomicInteger calls = new AtomicInteger(0);
    connectionFactory.setTransportListener(new TransportListener() {

        @Override
        public void onCommand(Object command) {
        }

        @Override
        public void onException(IOException error) {
            LOG.info("on exception: " + error);
            calls.set(0x01 | calls.intValue());
        }

        @Override
        public void transportInterupted() {
            LOG.info("on transportInterupted");
            calls.set(0x02 | calls.intValue());
        }

        @Override
        public void transportResumed() {
            LOG.info("on transportResumed");
            calls.set(0x04 | calls.intValue());
        }
    });
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue destination = session.createQueue("foo");
    MessageProducer producer = session.createProducer(destination);
    final Message message = session.createTextMessage("TEST");
    producer.send(message);
    // clear listener state
    calls.set(0);
    LOG.info("Stopping the Broker1...");
    server1.stop();
    LOG.info("Attempting to send... failover should throw on disconnect");
    try {
        producer.send(destination, message);
        fail("Expect IOException to bubble up on send");
    } catch (javax.jms.IllegalStateException producerClosed) {
    }
    assertEquals("Only an exception is reported to the listener", 0x1, calls.get());
}
Also used : Message(javax.jms.Message) Connection(javax.jms.Connection) IOException(java.io.IOException) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) TransportListener(org.apache.activemq.transport.TransportListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test) OpenwireArtemisBaseTest(org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest)

Example 8 with TransportListener

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

the class NetworkRouteTest method before.

@Before
public void before() throws Exception {
    control = EasyMock.createControl();
    localBroker = control.createMock(Transport.class);
    remoteBroker = control.createMock(Transport.class);
    NetworkBridgeConfiguration configuration = new NetworkBridgeConfiguration();
    brokerService = new BrokerService();
    BrokerInfo remoteBrokerInfo = new BrokerInfo();
    configuration.setDuplex(true);
    configuration.setNetworkTTL(5);
    brokerService.setBrokerId("broker-1");
    brokerService.setPersistent(false);
    brokerService.setUseJmx(false);
    brokerService.start();
    brokerService.waitUntilStarted();
    remoteBrokerInfo.setBrokerId(new BrokerId("remote-broker-id"));
    remoteBrokerInfo.setBrokerName("remote-broker-name");
    localBroker.setTransportListener(EasyMock.isA(TransportListener.class));
    ArgHolder localListenerRef = ArgHolder.holdArgsForLastVoidCall();
    remoteBroker.setTransportListener(EasyMock.isA(TransportListener.class));
    ArgHolder remoteListenerRef = ArgHolder.holdArgsForLastVoidCall();
    localBroker.start();
    remoteBroker.start();
    remoteBroker.oneway(EasyMock.isA(Object.class));
    EasyMock.expectLastCall().times(4);
    remoteBroker.oneway(EasyMock.isA(Object.class));
    ExpectationWaiter remoteInitWaiter = ExpectationWaiter.waiterForLastVoidCall();
    localBroker.oneway(remoteBrokerInfo);
    EasyMock.expect(localBroker.request(EasyMock.isA(Object.class))).andReturn(null);
    localBroker.oneway(EasyMock.isA(Object.class));
    ExpectationWaiter localInitWaiter = ExpectationWaiter.waiterForLastVoidCall();
    control.replay();
    DurableConduitBridge bridge = new DurableConduitBridge(configuration, localBroker, remoteBroker);
    bridge.setBrokerService(brokerService);
    bridge.start();
    localListener = (TransportListener) localListenerRef.getArguments()[0];
    Assert.assertNotNull(localListener);
    remoteListener = (TransportListener) remoteListenerRef.getArguments()[0];
    Assert.assertNotNull(remoteListener);
    remoteListener.onCommand(remoteBrokerInfo);
    remoteInitWaiter.assertHappens(5, TimeUnit.SECONDS);
    localInitWaiter.assertHappens(5, TimeUnit.SECONDS);
    control.verify();
    control.reset();
    ActiveMQMessage msg = new ActiveMQMessage();
    msg.setDestination(new ActiveMQTopic("test"));
    msgDispatch = new MessageDispatch();
    msgDispatch.setMessage(msg);
    ConsumerInfo path1 = new ConsumerInfo();
    path1.setDestination(msg.getDestination());
    path1.setConsumerId(new ConsumerId(new SessionId(new ConnectionId("conn-id-1"), 1), 3));
    path1.setBrokerPath(new BrokerId[] { new BrokerId("remote-broker-id"), new BrokerId("server(1)-broker-id") });
    path1Msg = new ActiveMQMessage();
    path1Msg.setDestination(AdvisorySupport.getConsumerAdvisoryTopic(path1.getDestination()));
    path1Msg.setDataStructure(path1);
    ConsumerInfo path2 = new ConsumerInfo();
    path2.setDestination(path1.getDestination());
    path2.setConsumerId(new ConsumerId(new SessionId(new ConnectionId("conn-id-2"), 2), 4));
    path2.setBrokerPath(new BrokerId[] { new BrokerId("remote-broker-id"), new BrokerId("server(2)-broker-id"), new BrokerId("server(1)-broker-id") });
    path2Msg = new ActiveMQMessage();
    path2Msg.setDestination(path1Msg.getDestination());
    path2Msg.setDataStructure(path2);
    RemoveInfo removePath1 = new RemoveInfo(path1.getConsumerId());
    RemoveInfo removePath2 = new RemoveInfo(path2.getConsumerId());
    removePath1Msg = new ActiveMQMessage();
    removePath1Msg.setDestination(path1Msg.getDestination());
    removePath1Msg.setDataStructure(removePath1);
    removePath2Msg = new ActiveMQMessage();
    removePath2Msg.setDestination(path1Msg.getDestination());
    removePath2Msg.setDataStructure(removePath2);
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) BrokerId(org.apache.activemq.command.BrokerId) BrokerInfo(org.apache.activemq.command.BrokerInfo) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) TransportListener(org.apache.activemq.transport.TransportListener) MessageDispatch(org.apache.activemq.command.MessageDispatch) ConnectionId(org.apache.activemq.command.ConnectionId) RemoveInfo(org.apache.activemq.command.RemoveInfo) ConsumerId(org.apache.activemq.command.ConsumerId) Transport(org.apache.activemq.transport.Transport) BrokerService(org.apache.activemq.broker.BrokerService) SessionId(org.apache.activemq.command.SessionId) Before(org.junit.Before)

Example 9 with TransportListener

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

the class UdpTestSupport method setUp.

@Override
protected void setUp() throws Exception {
    server = createServer();
    if (server != null) {
        server.setAcceptListener(new TransportAcceptListener() {

            @Override
            public void onAccept(Transport transport) {
                consumer = transport;
                consumer.setTransportListener(UdpTestSupport.this);
                try {
                    consumer.start();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public void onAcceptError(Exception error) {
            }
        });
        server.start();
    }
    consumer = createConsumer();
    if (consumer != null) {
        consumer.setTransportListener(this);
        consumer.start();
    }
    producer = createProducer();
    producer.setTransportListener(new TransportListener() {

        @Override
        public void onCommand(Object command) {
            LOG.info("Producer received: " + command);
        }

        @Override
        public void onException(IOException error) {
            LOG.info("Producer exception: " + error);
            error.printStackTrace();
        }

        @Override
        public void transportInterupted() {
        }

        @Override
        public void transportResumed() {
        }
    });
    producer.start();
}
Also used : TransportListener(org.apache.activemq.transport.TransportListener) IOException(java.io.IOException) Transport(org.apache.activemq.transport.Transport) TransportAcceptListener(org.apache.activemq.transport.TransportAcceptListener) IOException(java.io.IOException) MessageNotWriteableException(javax.jms.MessageNotWriteableException)

Example 10 with TransportListener

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

the class WireformatNegociationTest method startServer.

/**
 * @throws IOException
 * @throws URISyntaxException
 * @throws Exception
 */
private void startServer(String uri) throws IOException, URISyntaxException, Exception {
    server = TransportFactory.bind(new URI(uri));
    server.setAcceptListener(new TransportAcceptListener() {

        @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) {
                        if (command instanceof WireFormatInfo) {
                            serverWF.set((WireFormatInfo) command);
                            negotiationCounter.countDown();
                        }
                    }

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

                    @Override
                    public void transportInterupted() {
                    }

                    @Override
                    public void transportResumed() {
                    }
                });
                serverTransport.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onAcceptError(Exception error) {
            error.printStackTrace();
        }
    });
    server.start();
}
Also used : TransportListener(org.apache.activemq.transport.TransportListener) WireFormatInfo(org.apache.activemq.command.WireFormatInfo) IOException(java.io.IOException) Transport(org.apache.activemq.transport.Transport) URI(java.net.URI) TransportAcceptListener(org.apache.activemq.transport.TransportAcceptListener) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

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