Search in sources :

Example 6 with ActiveMQServerPlugin

use of org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin in project activemq-artemis by apache.

the class SessionMetadataAddExceptionTest method createDefaultConfig.

@Override
protected Configuration createDefaultConfig(boolean netty) throws Exception {
    Configuration config = super.createDefaultConfig(netty);
    config.registerBrokerPlugin(new ActiveMQServerPlugin() {

        @Override
        public void beforeSessionMetadataAdded(ServerSession session, String key, String data) throws ActiveMQException {
            if (ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY.equals(key)) {
                if ("invalid".equals(data)) {
                    throw new ActiveMQException("Invalid clientId");
                }
            }
        }
    });
    return config;
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQServerPlugin(org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin)

Example 7 with ActiveMQServerPlugin

use of org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin in project activemq-artemis by apache.

the class CriticalSimpleTest method testSimpleShutdown.

@Test
public void testSimpleShutdown() throws Exception {
    Configuration configuration = createDefaultConfig(false);
    configuration.setCriticalAnalyzerCheckPeriod(10).setCriticalAnalyzerPolicy(CriticalAnalyzerPolicy.SHUTDOWN);
    ActiveMQServer server = createServer(false, configuration, AddressSettings.DEFAULT_PAGE_SIZE, AddressSettings.DEFAULT_MAX_SIZE_BYTES);
    server.start();
    try {
        CountDownLatch latch = new CountDownLatch(1);
        server.getConfiguration().registerBrokerPlugin(new ActiveMQServerPlugin() {

            @Override
            public void criticalFailure(CriticalComponent components) throws ActiveMQException {
                latch.countDown();
            }
        });
        server.getCriticalAnalyzer().add(new CriticalComponent() {

            @Override
            public boolean isExpired(long timeout) {
                return true;
            }
        });
        Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
        Wait.waitFor(() -> !server.isStarted());
        Assert.assertFalse(server.isStarted());
    } finally {
        server.stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) CriticalComponent(org.apache.activemq.artemis.utils.critical.CriticalComponent) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQServerPlugin(org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

ActiveMQServerPlugin (org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin)7 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 ServerSession (org.apache.activemq.artemis.core.server.ServerSession)2 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)2 Test (org.junit.Test)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 JMSException (javax.jms.JMSException)1 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)1 FileDeploymentManager (org.apache.activemq.artemis.core.config.FileDeploymentManager)1 OperationContext (org.apache.activemq.artemis.core.persistence.OperationContext)1 StompConnection (org.apache.activemq.artemis.core.protocol.stomp.StompConnection)1 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)1 JMSServerManager (org.apache.activemq.artemis.jms.server.JMSServerManager)1 SessionCallback (org.apache.activemq.artemis.spi.core.protocol.SessionCallback)1 CriticalComponent (org.apache.activemq.artemis.utils.critical.CriticalComponent)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1