Search in sources :

Example 1 with TransportAcceptListener

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

the class TcpTransportServerTest method testDefaultPropertiesSetOnTransport.

public void testDefaultPropertiesSetOnTransport() throws Exception {
    TcpTransportServer server = (TcpTransportServer) TransportFactory.bind(new URI("tcp://localhost:61616?trace=true"));
    server.setTransportOption(new HashMap<String, Object>());
    server.setAcceptListener(new TransportAcceptListener() {

        @Override
        public void onAccept(Transport transport) {
            assertTrue("This transport does not have a TransportLogger!!", hasTransportLogger(transport));
        }

        @Override
        public void onAcceptError(Exception error) {
            fail("Should not have received an error!");
        }
    });
    server.start();
    Socket socket = new Socket("localhost", 61616);
    server.handleSocket(socket);
    server.stop();
}
Also used : Transport(org.apache.activemq.transport.Transport) URI(java.net.URI) TransportAcceptListener(org.apache.activemq.transport.TransportAcceptListener) Socket(java.net.Socket)

Example 2 with TransportAcceptListener

use of org.apache.activemq.transport.TransportAcceptListener 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 3 with TransportAcceptListener

use of org.apache.activemq.transport.TransportAcceptListener 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

Transport (org.apache.activemq.transport.Transport)3 TransportAcceptListener (org.apache.activemq.transport.TransportAcceptListener)3 IOException (java.io.IOException)2 URI (java.net.URI)2 TransportListener (org.apache.activemq.transport.TransportListener)2 Socket (java.net.Socket)1 URISyntaxException (java.net.URISyntaxException)1 MessageNotWriteableException (javax.jms.MessageNotWriteableException)1 WireFormatInfo (org.apache.activemq.command.WireFormatInfo)1