org.apache.activemq.artemis.core.server.management.Notification

Here are the examples of the java api class org.apache.activemq.artemis.core.server.management.Notification taken from open source projects.

1. ClusterConnectionControlTest#getFirstNotificationOfType()

View license
private Notification getFirstNotificationOfType(List<Notification> notifications, CoreNotificationType type) {
    Notification result = null;
    // the notifications can change while we're looping
    List<Notification> notificationsClone = new ArrayList<>(notifications);
    for (Notification notification : notificationsClone) {
        if (notification.getType().equals(type)) {
            result = notification;
        }
    }
    return result;
}

2. GroupHandlingAbstract#sendUnproposal()

View license
protected void sendUnproposal(SimpleString groupid, SimpleString clusterName, int distance) {
    TypedProperties props = new TypedProperties();
    props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, groupid);
    props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, clusterName);
    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.UNPROPOSAL, props);
    try {
        managementService.sendNotification(notification);
    } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.errorHandlingMessage(e);
    }
}

3. LocalGroupingHandler#sendProposalResponse()

View license
@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);
}

4. RemoteGroupingHandler#receive()

View license
@Override
public Response receive(final Proposal proposal, final int distance) throws Exception {
    TypedProperties props = new TypedProperties();
    props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, proposal.getGroupId());
    props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, proposal.getClusterName());
    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, props);
    managementService.sendNotification(notification);
    return null;
}

5. BridgeControlTest#testNotifications()

View license
@Test
public void testNotifications() throws Exception {
    SimpleNotificationService.Listener notifListener = new SimpleNotificationService.Listener();
    BridgeControl bridgeControl = createBridgeControl(bridgeConfig.getName(), mbeanServer);
    server_0.getManagementService().addNotificationListener(notifListener);
    Assert.assertEquals(0, notifListener.getNotifications().size());
    bridgeControl.stop();
    Assert.assertEquals(1, notifListener.getNotifications().size());
    Notification notif = notifListener.getNotifications().get(0);
    Assert.assertEquals(CoreNotificationType.BRIDGE_STOPPED, notif.getType());
    Assert.assertEquals(bridgeControl.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
    bridgeControl.start();
    Assert.assertEquals(2, notifListener.getNotifications().size());
    notif = notifListener.getNotifications().get(1);
    Assert.assertEquals(CoreNotificationType.BRIDGE_STARTED, notif.getType());
    Assert.assertEquals(bridgeControl.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
}

6. ClusterConnectionControlTest#testNotifications()

View license
@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());
}

7. JMSServerManagerImpl#sendNotification()

View license
private void sendNotification(JMSNotificationType type, String message) {
    TypedProperties prop = new TypedProperties();
    prop.putSimpleStringProperty(JMSNotificationType.MESSAGE, SimpleString.toSimpleString(message));
    Notification notif = new Notification(null, type, prop);
    try {
        server.getManagementService().sendNotification(notif);
    } catch (Exception e) {
        ActiveMQJMSServerLogger.LOGGER.failedToSendNotification(notif.toString());
    }
}

8. RemoteGroupingHandler#propose()

View license
@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;
}

9. DiscoveryTest#testDiscoveryGroupNotifications()

Project: activemq-artemis
Source File: DiscoveryTest.java
View license
@Test
public void testDiscoveryGroupNotifications() 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();
    final int timeout = 500;
    dg = newDiscoveryGroup(RandomUtil.randomString(), RandomUtil.randomString(), null, groupAddress, groupPort, timeout, notifService);
    Assert.assertEquals(0, notifListener.getNotifications().size());
    dg.start();
    Assert.assertEquals(1, notifListener.getNotifications().size());
    Notification notif = notifListener.getNotifications().get(0);
    Assert.assertEquals(CoreNotificationType.DISCOVERY_GROUP_STARTED, notif.getType());
    Assert.assertEquals(dg.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
    dg.stop();
    Assert.assertEquals(2, notifListener.getNotifications().size());
    notif = notifListener.getNotifications().get(1);
    Assert.assertEquals(CoreNotificationType.DISCOVERY_GROUP_STOPPED, notif.getType());
    Assert.assertEquals(dg.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
}

10. DiscoveryTest#testBroadcastGroupNotifications()

Project: activemq-artemis
Source File: DiscoveryTest.java
View license
@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());
}

11. AcceptorControlTest#testNotifications()

View license
@Test
public void testNotifications() 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());
    SimpleNotificationService.Listener notifListener = new SimpleNotificationService.Listener();
    service.getManagementService().addNotificationListener(notifListener);
    Assert.assertEquals(0, notifListener.getNotifications().size());
    acceptorControl.stop();
    Assert.assertEquals(1, notifListener.getNotifications().size());
    Notification notif = notifListener.getNotifications().get(0);
    Assert.assertEquals(CoreNotificationType.ACCEPTOR_STOPPED, notif.getType());
    Assert.assertEquals(InVMAcceptorFactory.class.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("factory")).toString());
    acceptorControl.start();
    Assert.assertEquals(2, notifListener.getNotifications().size());
    notif = notifListener.getNotifications().get(1);
    Assert.assertEquals(CoreNotificationType.ACCEPTOR_STARTED, notif.getType());
    Assert.assertEquals(InVMAcceptorFactory.class.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("factory")).toString());
}