Search in sources :

Example 1 with ServerConnectionLifeCycleListener

use of org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener in project activemq-artemis by apache.

the class NettyAcceptorTest method testStartStop.

@Test
public void testStartStop() throws Exception {
    BufferHandler handler = new BufferHandler() {

        @Override
        public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
        }
    };
    Map<String, Object> params = new HashMap<>();
    ServerConnectionLifeCycleListener listener = new ServerConnectionLifeCycleListener() {

        @Override
        public void connectionException(final Object connectionID, final ActiveMQException me) {
        }

        @Override
        public void connectionDestroyed(final Object connectionID) {
        }

        @Override
        public void connectionCreated(final ActiveMQComponent component, final Connection connection, final ProtocolManager protocol) {
        }

        @Override
        public void connectionReadyForWrites(Object connectionID, boolean ready) {
        }
    };
    pool2 = Executors.newScheduledThreadPool(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), ActiveMQThreadFactory.defaultThreadFactory());
    NettyAcceptor acceptor = new NettyAcceptor("netty", null, params, handler, listener, pool2, new HashMap<String, ProtocolManager>());
    addActiveMQComponent(acceptor);
    acceptor.start();
    Assert.assertTrue(acceptor.isStarted());
    acceptor.stop();
    Assert.assertFalse(acceptor.isStarted());
    ActiveMQTestBase.checkFreePort(TransportConstants.DEFAULT_PORT);
    acceptor.start();
    Assert.assertTrue(acceptor.isStarted());
    acceptor.stop();
    Assert.assertFalse(acceptor.isStarted());
    ActiveMQTestBase.checkFreePort(TransportConstants.DEFAULT_PORT);
    pool2.shutdown();
    pool2.awaitTermination(1, TimeUnit.SECONDS);
}
Also used : ActiveMQComponent(org.apache.activemq.artemis.core.server.ActiveMQComponent) HashMap(java.util.HashMap) NettyAcceptor(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) ServerConnectionLifeCycleListener(org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener) BufferHandler(org.apache.activemq.artemis.spi.core.remoting.BufferHandler) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ProtocolManager(org.apache.activemq.artemis.spi.core.protocol.ProtocolManager) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 2 with ServerConnectionLifeCycleListener

use of org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener in project activemq-artemis by apache.

the class NettyAcceptorFactoryTest method testCreateAcceptor.

@Test
public void testCreateAcceptor() throws Exception {
    NettyAcceptorFactory factory = new NettyAcceptorFactory();
    Map<String, Object> params = new HashMap<>();
    BufferHandler handler = new BufferHandler() {

        @Override
        public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
        }
    };
    ServerConnectionLifeCycleListener listener = new ServerConnectionLifeCycleListener() {

        @Override
        public void connectionException(final Object connectionID, final ActiveMQException me) {
        }

        @Override
        public void connectionDestroyed(final Object connectionID) {
        }

        @Override
        public void connectionCreated(ActiveMQComponent component, final Connection connection, final ProtocolManager protocol) {
        }

        @Override
        public void connectionReadyForWrites(Object connectionID, boolean ready) {
        }
    };
    Acceptor acceptor = factory.createAcceptor("netty", null, params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), ActiveMQThreadFactory.defaultThreadFactory()), new HashMap<String, ProtocolManager>());
    Assert.assertTrue(acceptor instanceof NettyAcceptor);
}
Also used : ActiveMQComponent(org.apache.activemq.artemis.core.server.ActiveMQComponent) NettyAcceptor(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor) Acceptor(org.apache.activemq.artemis.spi.core.remoting.Acceptor) HashMap(java.util.HashMap) NettyAcceptor(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) NettyAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory) ServerConnectionLifeCycleListener(org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener) BufferHandler(org.apache.activemq.artemis.spi.core.remoting.BufferHandler) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ProtocolManager(org.apache.activemq.artemis.spi.core.protocol.ProtocolManager) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 NettyAcceptor (org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor)2 ActiveMQComponent (org.apache.activemq.artemis.core.server.ActiveMQComponent)2 ProtocolManager (org.apache.activemq.artemis.spi.core.protocol.ProtocolManager)2 BufferHandler (org.apache.activemq.artemis.spi.core.remoting.BufferHandler)2 Connection (org.apache.activemq.artemis.spi.core.remoting.Connection)2 ServerConnectionLifeCycleListener (org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener)2 Test (org.junit.Test)2 NettyAcceptorFactory (org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory)1 Acceptor (org.apache.activemq.artemis.spi.core.remoting.Acceptor)1