use of org.apache.activemq.artemis.core.server.management.Notification in project activemq-artemis by apache.
the class RemoteGroupingHandler method propose.
@Override
public Response propose(final Proposal proposal) throws Exception {
// return it from the cache first
Response response = responses.get(proposal.getGroupId());
if (response != null) {
checkTimeout(response);
return response;
}
if (!started) {
throw ActiveMQMessageBundle.BUNDLE.groupWhileStopping();
}
Notification notification = null;
try {
lock.lock();
notification = createProposalNotification(proposal.getGroupId(), proposal.getClusterName());
pendingNotifications.add(notification);
managementService.sendNotification(notification);
long timeLimit = System.currentTimeMillis() + timeout;
do {
sendCondition.await(timeout, TimeUnit.MILLISECONDS);
response = responses.get(proposal.getGroupId());
// You could have this response being null if you had multiple threads calling propose
if (response != null) {
break;
}
} while (timeLimit > System.currentTimeMillis());
} finally {
if (notification != null) {
pendingNotifications.remove(notification);
}
lock.unlock();
}
if (response == null) {
ActiveMQServerLogger.LOGGER.groupHandlerSendTimeout();
}
return response;
}
use of org.apache.activemq.artemis.core.server.management.Notification in project activemq-artemis by apache.
the class ServerConsumerImpl method close.
@Override
public void close(final boolean failed) throws Exception {
if (logger.isTraceEnabled()) {
logger.trace("ServerConsumerImpl::" + this + " being closed with failed=" + failed, new Exception("trace"));
}
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.beforeCloseConsumer(this, failed));
}
setStarted(false);
LargeMessageDeliverer del = largeMessageDeliverer;
if (del != null) {
del.finish();
}
removeItself();
LinkedList<MessageReference> refs = cancelRefs(failed, false, null);
Iterator<MessageReference> iter = refs.iterator();
Transaction tx = new TransactionImpl(storageManager);
while (iter.hasNext()) {
MessageReference ref = iter.next();
if (logger.isTraceEnabled()) {
logger.trace("ServerConsumerImpl::" + this + " cancelling reference " + ref);
}
ref.getQueue().cancel(tx, ref, true);
}
tx.rollback();
messageQueue.recheckRefCount(session.getSessionContext());
if (!browseOnly) {
TypedProperties props = new TypedProperties();
props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());
props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filter == null ? null : filter.getFilterString());
props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, messageQueue.getConsumerCount());
// HORNETQ-946
props.putSimpleStringProperty(ManagementHelper.HDR_USER, SimpleString.toSimpleString(session.getUsername()));
props.putSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(((ServerSessionImpl) session).getRemotingConnection().getRemoteAddress()));
props.putSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(session.getName()));
Notification notification = new Notification(null, CoreNotificationType.CONSUMER_CLOSED, props);
managementService.sendNotification(notification);
}
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.afterCloseConsumer(this, failed));
}
}
use of org.apache.activemq.artemis.core.server.management.Notification in project activemq-artemis by apache.
the class DiscoveryTest method testBroadcastGroupNotifications.
@Test
public void testBroadcastGroupNotifications() throws Exception {
SimpleNotificationService notifService = new SimpleNotificationService();
SimpleNotificationService.Listener notifListener = new SimpleNotificationService.Listener();
notifService.addNotificationListener(notifListener);
final InetAddress groupAddress = InetAddress.getByName(address1);
final int groupPort = getUDPDiscoveryPort();
bg = newBroadcast(RandomUtil.randomString(), RandomUtil.randomString(), null, -1, groupAddress, groupPort);
bg.setNotificationService(notifService);
Assert.assertEquals(0, notifListener.getNotifications().size());
bg.start();
Assert.assertEquals(1, notifListener.getNotifications().size());
Notification notif = notifListener.getNotifications().get(0);
Assert.assertEquals(CoreNotificationType.BROADCAST_GROUP_STARTED, notif.getType());
Assert.assertEquals(bg.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
bg.stop();
Assert.assertEquals(2, notifListener.getNotifications().size());
notif = notifListener.getNotifications().get(1);
Assert.assertEquals(CoreNotificationType.BROADCAST_GROUP_STOPPED, notif.getType());
Assert.assertEquals(bg.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
}
use of org.apache.activemq.artemis.core.server.management.Notification in project activemq-artemis by apache.
the class ClusterConnectionControlTest method testNotifications.
@Test
public void testNotifications() throws Exception {
SimpleNotificationService.Listener notifListener = new SimpleNotificationService.Listener();
checkResource(ObjectNameBuilder.DEFAULT.getClusterConnectionObjectName(clusterConnectionConfig1.getName()));
ClusterConnectionControl clusterConnectionControl = createManagementControl(clusterConnectionConfig1.getName());
server_0.getManagementService().addNotificationListener(notifListener);
Assert.assertEquals(0, notifListener.getNotifications().size());
clusterConnectionControl.stop();
Assert.assertTrue(notifListener.getNotifications().size() > 0);
Notification notif = getFirstNotificationOfType(notifListener.getNotifications(), CoreNotificationType.CLUSTER_CONNECTION_STOPPED);
Assert.assertNotNull(notif);
Assert.assertEquals(clusterConnectionControl.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
clusterConnectionControl.start();
Assert.assertTrue(notifListener.getNotifications().size() > 0);
notif = getFirstNotificationOfType(notifListener.getNotifications(), CoreNotificationType.CLUSTER_CONNECTION_STARTED);
Assert.assertNotNull(notif);
Assert.assertEquals(clusterConnectionControl.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
}
use of org.apache.activemq.artemis.core.server.management.Notification 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);
}
Aggregations