Search in sources :

Example 31 with Notification

use of javax.management.Notification in project jdk8u_jdk by JetBrains.

the class LoggingExceptionTest method main.

public static void main(String[] args) {
    Handler handler = new ConsoleHandler();
    Logger logger = Logger.getLogger("javax.management.modelmbean");
    logger.addHandler(handler);
    logger.setLevel(Level.FINEST);
    try {
        for (int i = 0; i < tests.length; i++) {
            System.out.println(">>> DescriptorSupportLoggingTest: Test Case " + i);
            DescriptorSupport ds;
            String msg = "Instantiate " + tests[i];
            System.out.println(msg);
            switch(i) {
                case 0:
                    ds = new DescriptorSupport();
                    break;
                case 1:
                    ds = new DescriptorSupport(10);
                    break;
                case 2:
                    ds = new DescriptorSupport(new DescriptorSupport().toXMLString());
                    break;
                case 3:
                    ds = new DescriptorSupport("name1=value1", "name2=value2");
                    break;
                case 4:
                    ds = new DescriptorSupport(new String[] { "name" }, new Object[] { "value" });
                    break;
                case 5:
                    ds = new DescriptorSupport(new DescriptorSupport());
                    break;
                case 6:
                    RequiredModelMBean mbean = new RequiredModelMBean();
                    NotificationListener nl = new NotificationListener() {

                        public void handleNotification(Notification notification, Object handback) {
                        }
                    };
                    mbean.addAttributeChangeNotificationListener(nl, null, null);
                    break;
                default:
                    throw new AssertionError();
            }
            System.out.println(msg + " OK");
        }
    } catch (Exception e) {
        System.out.println("Got unexpected exception = " + e);
        String msg = "Test FAILED!";
        System.out.println(msg);
        throw new IllegalArgumentException(msg);
    }
    System.out.println("Test PASSED!");
}
Also used : ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler) Notification(javax.management.Notification) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) NotificationListener(javax.management.NotificationListener)

Example 32 with Notification

use of javax.management.Notification in project jdk8u_jdk by JetBrains.

the class Basic method sendNotification.

/**
     * Send one Notification of the provided notifType type.
     */
public void sendNotification(String notifType) {
    Notification notification = null;
    if (notifType.equals(NOTIF_TYPE_0)) {
        notification = new Notification(NOTIF_TYPE_0, mbeanName, seqNumber, NOTIFICATION_MESSAGE);
    } else if (notifType.equals(NOTIF_TYPE_1)) {
        notification = new SqeNotification(NOTIF_TYPE_1, mbeanName, seqNumber, NOTIFICATION_MESSAGE);
    }
    seqNumber++;
    broadcaster.sendNotification(notification);
}
Also used : Notification(javax.management.Notification)

Example 33 with Notification

use of javax.management.Notification in project geode by apache.

the class SystemMemberJmxImpl method handleRegionCreate.

/**
   * Implementation handles creation of region by extracting the details from the given event object
   * and sending the {@link SystemMemberJmx#NOTIF_REGION_CREATED} notification to the connected JMX
   * Clients. Region Path is set as User Data in Notification.
   * 
   * @param event event object corresponding to the creation of a region
   */
public void handleRegionCreate(SystemMemberRegionEvent event) {
    Notification notification = new Notification(NOTIF_REGION_CREATED, this.modelMBean, Helper.getNextNotificationSequenceNumber(), Helper.getRegionEventDetails(event));
    notification.setUserData(event.getRegionPath());
    Helper.sendNotification(this, notification);
}
Also used : Notification(javax.management.Notification)

Example 34 with Notification

use of javax.management.Notification in project geode by apache.

the class SystemMemberJmxImpl method handleClientMembership.

/**
   * Implementation handles client membership changes.
   * 
   * @param clientId id of the client for whom membership change happened
   * @param eventType membership change type; one of {@link ClientMembershipMessage#JOINED},
   *        {@link ClientMembershipMessage#LEFT}, {@link ClientMembershipMessage#CRASHED}
   */
public void handleClientMembership(String clientId, int eventType) {
    String notifType = null;
    List<ManagedResource> cleanedUp = null;
    if (eventType == ClientMembershipMessage.LEFT) {
        notifType = NOTIF_CLIENT_LEFT;
        cleanedUp = cleanupBridgeClientResources(clientId);
    } else if (eventType == ClientMembershipMessage.CRASHED) {
        notifType = NOTIF_CLIENT_CRASHED;
        cleanedUp = cleanupBridgeClientResources(clientId);
    } else if (eventType == ClientMembershipMessage.JOINED) {
        notifType = NOTIF_CLIENT_JOINED;
    }
    if (cleanedUp != null) {
        for (ManagedResource resource : cleanedUp) {
            MBeanUtil.unregisterMBean(resource);
        }
    }
    Helper.sendNotification(this, new Notification(notifType, this.modelMBean, Helper.getNextNotificationSequenceNumber(), clientId));
}
Also used : Notification(javax.management.Notification)

Example 35 with Notification

use of javax.management.Notification in project geode by apache.

the class SystemMemberJmxImpl method handleRegionLoss.

/**
   * Implementation should handle loss of region by extracting the details from the given event
   * object and sending the {@link SystemMemberJmx#NOTIF_REGION_LOST} notification to the connected
   * JMX Clients. Region Path is set as User Data in Notification. Additionally, it also clears the
   * ManagedResources created for the region that is lost.
   * 
   * @param event event object corresponding to the loss of a region
   */
public void handleRegionLoss(SystemMemberRegionEvent event) {
    SystemMemberCacheJmxImpl cacheResource = this.managedSystemMemberCache;
    if (cacheResource != null) {
        ManagedResource cleanedUp = cacheResource.cleanupRegionResources(event.getRegionPath());
        if (cleanedUp != null) {
            MBeanUtil.unregisterMBean(cleanedUp);
        }
    }
    Notification notification = new Notification(NOTIF_REGION_LOST, this.modelMBean, Helper.getNextNotificationSequenceNumber(), Helper.getRegionEventDetails(event));
    notification.setUserData(event.getRegionPath());
    Helper.sendNotification(this, notification);
}
Also used : Notification(javax.management.Notification)

Aggregations

Notification (javax.management.Notification)204 ObjectName (javax.management.ObjectName)68 NotificationListener (javax.management.NotificationListener)35 AttributeChangeNotification (javax.management.AttributeChangeNotification)29 CompositeData (javax.management.openmbean.CompositeData)25 IOException (java.io.IOException)23 Test (org.junit.Test)20 HashMap (java.util.HashMap)19 MalformedObjectNameException (javax.management.MalformedObjectNameException)19 Test (org.testng.annotations.Test)18 ListenerNotFoundException (javax.management.ListenerNotFoundException)17 ArrayList (java.util.ArrayList)16 MBeanServer (javax.management.MBeanServer)16 NotificationFilter (javax.management.NotificationFilter)15 NotificationEmitter (javax.management.NotificationEmitter)14 JMXConnector (javax.management.remote.JMXConnector)14 JMXServiceURL (javax.management.remote.JMXServiceURL)14 MBeanServerConnection (javax.management.MBeanServerConnection)12 MalformedURLException (java.net.MalformedURLException)11 JMXConnectorServer (javax.management.remote.JMXConnectorServer)11