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) {
}
}
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);
}
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));
}
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());
}
Aggregations