Search in sources :

Example 1 with NotificationListener

use of org.apache.activemq.artemis.core.server.management.NotificationListener in project activemq-artemis by apache.

the class ClusteredGroupingTest method testGroupingGroupTimeoutSendRemote.

@Test
public void testGroupingGroupTimeoutSendRemote() throws Exception {
    setupServer(0, isFileStorage(), isNetty());
    setupServer(1, isFileStorage(), isNetty());
    setupServer(2, isFileStorage(), isNetty());
    setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1, 2);
    setupClusterConnection("cluster1", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0, 2);
    setupClusterConnection("cluster2", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 2, 0, 1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.LOCAL, 0, -1, 2000, 500);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 2);
    startServers(0, 1, 2);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());
    setupSessionFactory(2, isNetty());
    createQueue(0, "queues.testaddress", "queue0", null, false);
    createQueue(1, "queues.testaddress", "queue0", null, false);
    createQueue(2, "queues.testaddress", "queue0", null, false);
    addConsumer(0, 2, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 0, true);
    waitForBindings(1, "queues.testaddress", 1, 0, true);
    waitForBindings(2, "queues.testaddress", 1, 1, true);
    waitForBindings(0, "queues.testaddress", 2, 1, false);
    waitForBindings(1, "queues.testaddress", 2, 1, false);
    waitForBindings(2, "queues.testaddress", 2, 0, false);
    final CountDownLatch latch = new CountDownLatch(4);
    getServer(1).getManagementService().addNotificationListener(new NotificationListener() {

        @Override
        public void onNotification(Notification notification) {
            if (!(notification.getType() instanceof CoreNotificationType))
                return;
            if (notification.getType() == CoreNotificationType.UNPROPOSAL) {
                latch.countDown();
            }
        }
    });
    getServer(2).getManagementService().addNotificationListener(new NotificationListener() {

        @Override
        public void onNotification(Notification notification) {
            if (!(notification.getType() instanceof CoreNotificationType))
                return;
            if (notification.getType() == CoreNotificationType.UNPROPOSAL) {
                latch.countDown();
            }
        }
    });
    sendWithProperty(2, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id1"));
    verifyReceiveAll(10, 0);
    sendWithProperty(1, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id2"));
    verifyReceiveAll(10, 0);
    removeConsumer(0);
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    addConsumer(0, 1, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 0, true);
    waitForBindings(1, "queues.testaddress", 1, 1, true);
    waitForBindings(2, "queues.testaddress", 1, 0, true);
    waitForBindings(0, "queues.testaddress", 2, 1, false);
    waitForBindings(1, "queues.testaddress", 2, 0, false);
    waitForBindings(2, "queues.testaddress", 2, 1, false);
    sendWithProperty(2, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id1"));
    verifyReceiveAll(10, 0);
    sendWithProperty(1, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id2"));
    verifyReceiveAll(10, 0);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) CoreNotificationType(org.apache.activemq.artemis.api.core.management.CoreNotificationType) Notification(org.apache.activemq.artemis.core.server.management.Notification) NotificationListener(org.apache.activemq.artemis.core.server.management.NotificationListener) Test(org.junit.Test)

Example 2 with NotificationListener

use of org.apache.activemq.artemis.core.server.management.NotificationListener in project activemq-artemis by apache.

the class ManagementServiceImpl method sendNotification.

@Override
public void sendNotification(final Notification notification) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("Sending Notification = " + notification + ", notificationEnabled=" + notificationsEnabled + " messagingServerControl=" + messagingServerControl);
    }
    // This needs to be synchronized since we need to ensure notifications are processed in strict sequence
    synchronized (this) {
        if (messagingServerControl != null && notificationsEnabled) {
            // if a notification occurs at same time as sendQueueInfoToQueue is processed
            synchronized (postOffice.getNotificationLock()) {
                // First send to any local listeners
                for (NotificationListener listener : listeners) {
                    try {
                        listener.onNotification(notification);
                    } catch (Exception e) {
                        // Exception thrown from one listener should not stop execution of others
                        ActiveMQServerLogger.LOGGER.errorCallingNotifListener(e);
                    }
                }
                // https://jira.jboss.org/jira/browse/HORNETQ-317
                if (messagingServer == null || !messagingServer.isActive()) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("ignoring message " + notification + " as the server is not initialized");
                    }
                    return;
                }
                long messageID = storageManager.generateID();
                Message notificationMessage = new CoreMessage(messageID, 512);
                // Notification messages are always durable so the user can choose whether to add a durable queue to
                // consume them in
                notificationMessage.setDurable(true);
                notificationMessage.setAddress(managementNotificationAddress);
                if (notification.getProperties() != null) {
                    TypedProperties props = notification.getProperties();
                    for (SimpleString name : notification.getProperties().getPropertyNames()) {
                        notificationMessage.putObjectProperty(name, props.getProperty(name));
                    }
                }
                notificationMessage.putStringProperty(ManagementHelper.HDR_NOTIFICATION_TYPE, new SimpleString(notification.getType().toString()));
                notificationMessage.putLongProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP, System.currentTimeMillis());
                if (notification.getUID() != null) {
                    notificationMessage.putStringProperty(new SimpleString("foobar"), new SimpleString(notification.getUID()));
                }
                postOffice.route(notificationMessage, false);
            }
        }
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) InvocationTargetException(java.lang.reflect.InvocationTargetException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) NotificationListener(org.apache.activemq.artemis.core.server.management.NotificationListener)

Example 3 with NotificationListener

use of org.apache.activemq.artemis.core.server.management.NotificationListener in project activemq-artemis by apache.

the class ClusteredGroupingTest method testGroupingGroupTimeoutWithUnproposal.

@Test
public void testGroupingGroupTimeoutWithUnproposal() throws Exception {
    setupServer(0, isFileStorage(), isNetty());
    setupServer(1, isFileStorage(), isNetty());
    setupServer(2, isFileStorage(), isNetty());
    setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1, 2);
    setupClusterConnection("cluster1", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0, 2);
    setupClusterConnection("cluster2", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 2, 0, 1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.LOCAL, 0, 2000, 1000, 100);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 1, 2000, 1000, 100);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 2, 2000, 1000, 100);
    startServers(0, 1, 2);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());
    setupSessionFactory(2, isNetty());
    createQueue(0, "queues.testaddress", "queue0", null, false);
    createQueue(1, "queues.testaddress", "queue0", null, false);
    createQueue(2, "queues.testaddress", "queue0", null, false);
    addConsumer(0, 2, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 0, true);
    waitForBindings(1, "queues.testaddress", 1, 0, true);
    waitForBindings(2, "queues.testaddress", 1, 1, true);
    waitForBindings(0, "queues.testaddress", 2, 1, false);
    waitForBindings(1, "queues.testaddress", 2, 1, false);
    waitForBindings(2, "queues.testaddress", 2, 0, false);
    final CountDownLatch latch = new CountDownLatch(4);
    getServer(1).getManagementService().addNotificationListener(new NotificationListener() {

        @Override
        public void onNotification(Notification notification) {
            if (!(notification.getType() instanceof CoreNotificationType))
                return;
            if (notification.getType() == CoreNotificationType.UNPROPOSAL) {
                latch.countDown();
            }
        }
    });
    getServer(2).getManagementService().addNotificationListener(new NotificationListener() {

        @Override
        public void onNotification(Notification notification) {
            if (!(notification.getType() instanceof CoreNotificationType))
                return;
            if (notification.getType() == CoreNotificationType.UNPROPOSAL) {
                latch.countDown();
            }
        }
    });
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id1"));
    verifyReceiveAll(10, 0);
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id2"));
    verifyReceiveAll(10, 0);
    QueueImpl queue0Server2 = (QueueImpl) servers[2].locateQueue(SimpleString.toSimpleString("queue0"));
    assertEquals(2, queue0Server2.getGroupsUsed().size());
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    long timeLimit = System.currentTimeMillis() + 5000;
    while (timeLimit > System.currentTimeMillis() && queue0Server2.getGroupsUsed().size() != 0) {
        Thread.sleep(10);
    }
    assertEquals("Unproposal should cleanup the queue group as well", 0, queue0Server2.getGroupsUsed().size());
    removeConsumer(0);
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    addConsumer(0, 0, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 1, true);
    waitForBindings(1, "queues.testaddress", 1, 0, true);
    waitForBindings(2, "queues.testaddress", 1, 0, true);
    waitForBindings(0, "queues.testaddress", 2, 0, false);
    waitForBindings(1, "queues.testaddress", 2, 1, false);
    waitForBindings(2, "queues.testaddress", 2, 1, false);
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id1"));
    verifyReceiveAll(10, 0);
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id2"));
    verifyReceiveAll(10, 0);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) CoreNotificationType(org.apache.activemq.artemis.api.core.management.CoreNotificationType) Notification(org.apache.activemq.artemis.core.server.management.Notification) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) NotificationListener(org.apache.activemq.artemis.core.server.management.NotificationListener) Test(org.junit.Test)

Aggregations

SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 NotificationListener (org.apache.activemq.artemis.core.server.management.NotificationListener)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 CoreNotificationType (org.apache.activemq.artemis.api.core.management.CoreNotificationType)2 Notification (org.apache.activemq.artemis.core.server.management.Notification)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)1 Message (org.apache.activemq.artemis.api.core.Message)1 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)1 QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)1 TypedProperties (org.apache.activemq.artemis.utils.collections.TypedProperties)1