Search in sources :

Example 6 with BufferHandler

use of org.apache.activemq.artemis.spi.core.remoting.BufferHandler 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)

Example 7 with BufferHandler

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

the class NettyConnectorTest method testActiveMQSystemPropertyOverrides.

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

        @Override
        public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
        }
    };
    Map<String, Object> params = new HashMap<>();
    params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
    params.put(TransportConstants.KEYSTORE_PATH_PROP_NAME, "bad path");
    params.put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "bad password");
    params.put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, "bad path");
    params.put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "bad password");
    NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
    System.setProperty(NettyConnector.JAVAX_KEYSTORE_PATH_PROP_NAME, "bad path");
    System.setProperty(NettyConnector.JAVAX_KEYSTORE_PASSWORD_PROP_NAME, "bad password");
    System.setProperty(NettyConnector.JAVAX_TRUSTSTORE_PATH_PROP_NAME, "bad path");
    System.setProperty(NettyConnector.JAVAX_TRUSTSTORE_PASSWORD_PROP_NAME, "bad password");
    System.setProperty(NettyConnector.ACTIVEMQ_KEYSTORE_PATH_PROP_NAME, "client-side-keystore.jks");
    System.setProperty(NettyConnector.ACTIVEMQ_KEYSTORE_PASSWORD_PROP_NAME, "secureexample");
    System.setProperty(NettyConnector.ACTIVEMQ_TRUSTSTORE_PATH_PROP_NAME, "client-side-truststore.jks");
    System.setProperty(NettyConnector.ACTIVEMQ_TRUSTSTORE_PASSWORD_PROP_NAME, "secureexample");
    connector.start();
    Assert.assertTrue(connector.isStarted());
    connector.close();
    Assert.assertFalse(connector.isStarted());
}
Also used : HashMap(java.util.HashMap) NettyConnector(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector) BufferHandler(org.apache.activemq.artemis.spi.core.remoting.BufferHandler) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 8 with BufferHandler

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

the class NettyConnectorTest method testNullParams.

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

        @Override
        public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
        }
    };
    Map<String, Object> params = new HashMap<>();
    try {
        new NettyConnector(params, null, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
        Assert.fail("Should throw Exception");
    } catch (IllegalArgumentException e) {
    // Ok
    }
    try {
        new NettyConnector(params, handler, null, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
        Assert.fail("Should throw Exception");
    } catch (IllegalArgumentException e) {
    // Ok
    }
}
Also used : HashMap(java.util.HashMap) NettyConnector(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector) BufferHandler(org.apache.activemq.artemis.spi.core.remoting.BufferHandler) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)8 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)8 BufferHandler (org.apache.activemq.artemis.spi.core.remoting.BufferHandler)8 Test (org.junit.Test)8 NettyConnector (org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector)6 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 Connection (org.apache.activemq.artemis.spi.core.remoting.Connection)2 ServerConnectionLifeCycleListener (org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener)2 NettyAcceptorFactory (org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory)1 Acceptor (org.apache.activemq.artemis.spi.core.remoting.Acceptor)1