Search in sources :

Example 1 with AcceptorControl

use of org.apache.activemq.artemis.api.core.management.AcceptorControl in project activemq-artemis by apache.

the class AcceptorControlTest method testStartStop.

@Test
public void testStartStop() throws Exception {
    TransportConfiguration acceptorConfig = new TransportConfiguration(InVMAcceptorFactory.class.getName(), new HashMap<String, Object>(), RandomUtil.randomString());
    Configuration config = createBasicConfig().addAcceptorConfiguration(acceptorConfig);
    ActiveMQServer service = createServer(false, config);
    service.setMBeanServer(mbeanServer);
    service.start();
    AcceptorControl acceptorControl = createManagementControl(acceptorConfig.getName());
    // started by the server
    Assert.assertTrue(acceptorControl.isStarted());
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    Assert.assertNotNull(session);
    session.close();
    acceptorControl.stop();
    Assert.assertFalse(acceptorControl.isStarted());
    try {
        sf.createSession(false, true, true);
        Assert.fail("acceptor must not accept connections when stopped accepting");
    } catch (ActiveMQException e) {
    }
    acceptorControl.start();
    Assert.assertTrue(acceptorControl.isStarted());
    locator = createInVMNonHALocator();
    sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    Assert.assertNotNull(session);
    session.close();
    acceptorControl.stop();
    Assert.assertFalse(acceptorControl.isStarted());
    try {
        sf.createSession(false, true, true);
        Assert.fail("acceptor must not accept connections when stopped accepting");
    } catch (ActiveMQException e) {
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) AcceptorControl(org.apache.activemq.artemis.api.core.management.AcceptorControl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) InVMAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 2 with AcceptorControl

use of org.apache.activemq.artemis.api.core.management.AcceptorControl in project activemq-artemis by apache.

the class ManagementServiceImpl method registerAcceptor.

@Override
public synchronized void registerAcceptor(final Acceptor acceptor, final TransportConfiguration configuration) throws Exception {
    ObjectName objectName = objectNameBuilder.getAcceptorObjectName(configuration.getName());
    AcceptorControl control = new AcceptorControlImpl(acceptor, storageManager, configuration);
    registerInJMX(objectName, control);
    registerInRegistry(ResourceNames.ACCEPTOR + configuration.getName(), control);
}
Also used : AcceptorControl(org.apache.activemq.artemis.api.core.management.AcceptorControl) AcceptorControlImpl(org.apache.activemq.artemis.core.management.impl.AcceptorControlImpl) ObjectName(javax.management.ObjectName)

Example 3 with AcceptorControl

use of org.apache.activemq.artemis.api.core.management.AcceptorControl in project activemq-artemis by apache.

the class AcceptorControlTest method testAttributes.

@Test
public void testAttributes() throws Exception {
    TransportConfiguration acceptorConfig = new TransportConfiguration(InVMAcceptorFactory.class.getName(), new HashMap<String, Object>(), RandomUtil.randomString());
    acceptorConfig.getParams().put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "password");
    Configuration config = createBasicConfig().addAcceptorConfiguration(acceptorConfig);
    ActiveMQServer service = createServer(false, config);
    service.setMBeanServer(mbeanServer);
    service.start();
    AcceptorControl acceptorControl = createManagementControl(acceptorConfig.getName());
    Assert.assertEquals(acceptorConfig.getName(), acceptorControl.getName());
    Assert.assertEquals(acceptorConfig.getFactoryClassName(), acceptorControl.getFactoryClassName());
    Assert.assertNotEquals(acceptorConfig.getParams().get(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME), acceptorControl.getParameters().get(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME));
    Assert.assertEquals("****", acceptorControl.getParameters().get(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME));
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) AcceptorControl(org.apache.activemq.artemis.api.core.management.AcceptorControl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InVMAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory) Test(org.junit.Test)

Example 4 with AcceptorControl

use of org.apache.activemq.artemis.api.core.management.AcceptorControl in project activemq-artemis by apache.

the class AcceptorControlTest method testNotifications.

@Test
public void testNotifications() throws Exception {
    TransportConfiguration acceptorConfig = new TransportConfiguration(InVMAcceptorFactory.class.getName(), new HashMap<String, Object>(), RandomUtil.randomString());
    TransportConfiguration acceptorConfig2 = new TransportConfiguration(NettyAcceptorFactory.class.getName(), new HashMap<String, Object>(), RandomUtil.randomString());
    Configuration config = createBasicConfig().addAcceptorConfiguration(acceptorConfig).addAcceptorConfiguration(acceptorConfig2);
    ActiveMQServer service = createServer(false, config);
    service.setMBeanServer(mbeanServer);
    service.start();
    AcceptorControl acceptorControl = createManagementControl(acceptorConfig2.getName());
    SimpleNotificationService.Listener notifListener = new SimpleNotificationService.Listener();
    service.getManagementService().addNotificationListener(notifListener);
    Assert.assertEquals(0, notifListener.getNotifications().size());
    acceptorControl.stop();
    Assert.assertEquals(usingCore() ? 5 : 1, notifListener.getNotifications().size());
    Notification notif = notifListener.getNotifications().get(usingCore() ? 2 : 0);
    Assert.assertEquals(CoreNotificationType.ACCEPTOR_STOPPED, notif.getType());
    Assert.assertEquals(NettyAcceptorFactory.class.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("factory")).toString());
    acceptorControl.start();
    Assert.assertEquals(usingCore() ? 10 : 2, notifListener.getNotifications().size());
    notif = notifListener.getNotifications().get(usingCore() ? 7 : 1);
    Assert.assertEquals(CoreNotificationType.ACCEPTOR_STARTED, notif.getType());
    Assert.assertEquals(NettyAcceptorFactory.class.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("factory")).toString());
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) AcceptorControl(org.apache.activemq.artemis.api.core.management.AcceptorControl) NettyAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Notification(org.apache.activemq.artemis.core.server.management.Notification) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SimpleNotificationService(org.apache.activemq.artemis.tests.integration.SimpleNotificationService) InVMAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory) Test(org.junit.Test)

Aggregations

AcceptorControl (org.apache.activemq.artemis.api.core.management.AcceptorControl)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)3 Configuration (org.apache.activemq.artemis.core.config.Configuration)3 InVMAcceptorFactory (org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory)3 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)3 Test (org.junit.Test)3 ObjectName (javax.management.ObjectName)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)1 AcceptorControlImpl (org.apache.activemq.artemis.core.management.impl.AcceptorControlImpl)1 NettyAcceptorFactory (org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory)1 Notification (org.apache.activemq.artemis.core.server.management.Notification)1 SimpleNotificationService (org.apache.activemq.artemis.tests.integration.SimpleNotificationService)1