示例#1
0
  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(NotificationType.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(NotificationType.BRIDGE_STARTED, notif.getType());
    Assert.assertEquals(
        bridgeControl.getName(),
        notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
  }
示例#2
0
  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(NotificationType.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(NotificationType.BROADCAST_GROUP_STOPPED, notif.getType());
    Assert.assertEquals(
        bg.getName(),
        notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
  }
示例#3
0
  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(NotificationType.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(NotificationType.DISCOVERY_GROUP_STOPPED, notif.getType());
    Assert.assertEquals(
        dg.getName(),
        notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
  }
 public void onNotification(final Notification notification) {
   // removing the groupid if the binding has been removed
   if (notification.getType() == NotificationType.BINDING_REMOVED) {
     SimpleString clusterName =
         notification.getProperties().getSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME);
     List<SimpleString> list = groupMap.remove(clusterName);
     if (list != null) {
       for (SimpleString val : list) {
         if (val != null) {
           responses.remove(val);
         }
       }
     }
   }
 }