Search in sources :

Example 26 with Notification

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

the class BroadcastGroupImpl method start.

@Override
public synchronized void start() throws Exception {
    if (started) {
        return;
    }
    endpoint.openBroadcaster();
    started = true;
    if (notificationService != null) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(new SimpleString("name"), new SimpleString(name));
        Notification notification = new Notification(nodeManager.getNodeId().toString(), CoreNotificationType.BROADCAST_GROUP_STARTED, props);
        notificationService.sendNotification(notification);
    }
    activate();
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 27 with Notification

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

the class ClusterConnectionImpl method stop.

@Override
public void stop() throws Exception {
    if (!started) {
        return;
    }
    stopping = true;
    if (logger.isDebugEnabled()) {
        logger.debug(this + "::stopping ClusterConnection");
    }
    if (serverLocator != null) {
        serverLocator.removeClusterTopologyListener(this);
    }
    logger.debug("Cluster connection being stopped for node" + nodeManager.getNodeId() + ", server = " + this.server + " serverLocator = " + serverLocator);
    synchronized (this) {
        for (MessageFlowRecord record : records.values()) {
            try {
                record.close();
            } catch (Exception ignore) {
            }
        }
    }
    if (managementService != null) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(new SimpleString("name"), name);
        Notification notification = new Notification(nodeManager.getNodeId().toString(), CoreNotificationType.CLUSTER_CONNECTION_STOPPED, props);
        managementService.sendNotification(notification);
    }
    executor.execute(new Runnable() {

        @Override
        public void run() {
            synchronized (ClusterConnectionImpl.this) {
                closeLocator(serverLocator);
                serverLocator = null;
            }
        }
    });
    started = false;
}
Also used : MessageFlowRecord(org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 28 with Notification

use of org.apache.activemq.artemis.core.server.management.Notification 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)

Example 29 with Notification

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

the class ServerSessionImpl method createConsumer.

@Override
public ServerConsumer createConsumer(final long consumerID, final SimpleString queueName, final SimpleString filterString, final boolean browseOnly, final boolean supportLargeMessage, final Integer credits) throws Exception {
    final SimpleString unPrefixedQueueName = removePrefix(queueName);
    Binding binding = postOffice.getBinding(unPrefixedQueueName);
    if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
        throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(unPrefixedQueueName);
    }
    SimpleString address = removePrefix(binding.getAddress());
    if (browseOnly) {
        try {
            securityCheck(address, queueName, CheckType.BROWSE, this);
        } catch (Exception e) {
            securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.BROWSE, this);
        }
    } else {
        try {
            securityCheck(address, queueName, CheckType.CONSUME, this);
        } catch (Exception e) {
            securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.CONSUME, this);
        }
    }
    Filter filter = FilterImpl.createFilter(filterString);
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeCreateConsumer(consumerID, (QueueBinding) binding, filterString, browseOnly, supportLargeMessage));
    }
    ServerConsumer consumer = new ServerConsumerImpl(consumerID, this, (QueueBinding) binding, filter, started, browseOnly, storageManager, callback, preAcknowledge, strictUpdateDeliveryCount, managementService, supportLargeMessage, credits, server);
    consumers.put(consumer.getID(), consumer);
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterCreateConsumer(consumer));
    }
    if (!browseOnly) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
        props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
        props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
        props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
        Queue theQueue = (Queue) binding.getBindable();
        props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());
        // HORNETQ-946
        props.putSimpleStringProperty(ManagementHelper.HDR_USER, SimpleString.toSimpleString(username));
        props.putSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress()));
        props.putSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name));
        if (filterString != null) {
            props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
        }
        Notification notification = new Notification(null, CoreNotificationType.CONSUMER_CREATED, props);
        if (logger.isDebugEnabled()) {
            logger.debug("Session with user=" + username + ", connection=" + this.remotingConnection + " created a consumer on queue " + unPrefixedQueueName + ", filter = " + filterString);
        }
        managementService.sendNotification(notification);
    }
    return consumer;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQXAException(org.apache.activemq.artemis.core.exception.ActiveMQXAException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) XAException(javax.transaction.xa.XAException) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 30 with Notification

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

the class LocalGroupingHandler method sendProposalResponse.

@Override
public void sendProposalResponse(final Response response, final int distance) throws Exception {
    TypedProperties props = new TypedProperties();
    props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, response.getGroupId());
    props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, response.getClusterName());
    props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_ALT_VALUE, response.getAlternativeClusterName());
    props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX);
    props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
    props.putIntProperty(ManagementHelper.HDR_DISTANCE, distance);
    Notification notification = new Notification(null, CoreNotificationType.PROPOSAL_RESPONSE, props);
    managementService.sendNotification(notification);
}
Also used : TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Aggregations

Notification (org.apache.activemq.artemis.core.server.management.Notification)35 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)26 TypedProperties (org.apache.activemq.artemis.utils.collections.TypedProperties)24 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)9 Test (org.junit.Test)9 SimpleNotificationService (org.apache.activemq.artemis.tests.integration.SimpleNotificationService)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)3 Channel (io.netty.channel.Channel)2 ServerChannel (io.netty.channel.ServerChannel)2 EpollServerSocketChannel (io.netty.channel.epoll.EpollServerSocketChannel)2 KQueueServerSocketChannel (io.netty.channel.kqueue.KQueueServerSocketChannel)2 LocalServerChannel (io.netty.channel.local.LocalServerChannel)2 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)2 InetAddress (java.net.InetAddress)2 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)2 ActiveMQNonExistentQueueException (org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)2 BroadcastEndpoint (org.apache.activemq.artemis.api.core.BroadcastEndpoint)2 CoreNotificationType (org.apache.activemq.artemis.api.core.management.CoreNotificationType)2 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)2