Java Code Examples for javax.management.Notification.getSource()

The following are Jave code examples for showing how to use getSource() of the javax.management.Notification class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenJSharp   File: DefaultMBeanServerInterceptor.java   View Source Code Vote up 6 votes
public void handleNotification(Notification notification,
                               Object handback) {
    if (notification != null) {
        if (notification.getSource() == mbean)
            notification.setSource(name);
    }

    /*
     * Listeners are not supposed to throw exceptions.  If
     * this one does, we could remove it from the MBean.  It
     * might indicate that a connector has stopped working,
     * for instance, and there is no point in sending future
     * notifications over that connection.  However, this
     * seems rather drastic, so instead we propagate the
     * exception and let the broadcaster handle it.
     */
    listener.handleNotification(notification, handback);
}
 
Example 2
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   View Source Code Vote up 6 votes
public void handleNotification(Notification notification,
                               Object handback) {
    if (notification != null) {
        if (notification.getSource() == mbean)
            notification.setSource(name);
    }

    /*
     * Listeners are not supposed to throw exceptions.  If
     * this one does, we could remove it from the MBean.  It
     * might indicate that a connector has stopped working,
     * for instance, and there is no point in sending future
     * notifications over that connection.  However, this
     * seems rather drastic, so instead we propagate the
     * exception and let the broadcaster handle it.
     */
    listener.handleNotification(notification, handback);
}
 
Example 3
Project: jdk8u-jdk   File: NotificationAccessControllerTest.java   View Source Code Vote up 6 votes
/**
 * Check received notifications
 */
public int checkNotifs(int size,
                       List<Notification> received,
                       List<ObjectName> expected) {
    if (received.size() != size) {
        echo("Error: expecting " + size + " notifications, got " +
                received.size());
        return 1;
    } else {
        for (Notification n : received) {
            echo("Received notification: " + n);
            if (!n.getType().equals("nb")) {
                echo("Notification type must be \"nb\"");
                return 1;
            }
            ObjectName o = (ObjectName) n.getSource();
            int index = (int) n.getSequenceNumber();
            ObjectName nb = expected.get(index);
            if (!o.equals(nb)) {
                echo("Notification source must be " + nb);
                return 1;
            }
        }
    }
    return 0;
}
 
Example 4
Project: jdk8u-jdk   File: NotificationEmissionTest.java   View Source Code Vote up 6 votes
public int checkNotifs(int size,
                       List<Notification> received,
                       List<ObjectName> expected) {
    if (received.size() != size) {
        echo("Error: expecting " + size + " notifications, got " +
                received.size());
        return 1;
    } else {
        for (Notification n : received) {
            echo("Received notification: " + n);
            if (!n.getType().equals("nb")) {
                echo("Notification type must be \"nb\"");
                return 1;
            }
            ObjectName o = (ObjectName) n.getSource();
            int index = (int) n.getSequenceNumber();
            ObjectName nb = expected.get(index);
            if (!o.equals(nb)) {
                echo("Notification source must be " + nb);
                return 1;
            }
        }
    }
    return 0;
}
 
Example 5
Project: openjdk-jdk10   File: DefaultMBeanServerInterceptor.java   View Source Code Vote up 6 votes
public void handleNotification(Notification notification,
                               Object handback) {
    if (notification != null) {
        if (notification.getSource() == mbean)
            notification.setSource(name);
    }

    /*
     * Listeners are not supposed to throw exceptions.  If
     * this one does, we could remove it from the MBean.  It
     * might indicate that a connector has stopped working,
     * for instance, and there is no point in sending future
     * notifications over that connection.  However, this
     * seems rather drastic, so instead we propagate the
     * exception and let the broadcaster handle it.
     */
    listener.handleNotification(notification, handback);
}
 
Example 6
Project: openjdk-jdk10   File: NotificationAccessControllerTest.java   View Source Code Vote up 6 votes
/**
 * Check received notifications
 */
public int checkNotifs(int size,
                       List<Notification> received,
                       List<ObjectName> expected) {
    if (received.size() != size) {
        echo("Error: expecting " + size + " notifications, got " +
                received.size());
        return 1;
    } else {
        for (Notification n : received) {
            echo("Received notification: " + n);
            if (!n.getType().equals("nb")) {
                echo("Notification type must be \"nb\"");
                return 1;
            }
            ObjectName o = (ObjectName) n.getSource();
            int index = (int) n.getSequenceNumber();
            ObjectName nb = expected.get(index);
            if (!o.equals(nb)) {
                echo("Notification source must be " + nb);
                return 1;
            }
        }
    }
    return 0;
}
 
Example 7
Project: openjdk-jdk10   File: NotificationEmissionTest.java   View Source Code Vote up 6 votes
public int checkNotifs(int size,
                       List<Notification> received,
                       List<ObjectName> expected) {
    if (received.size() != size) {
        echo("Error: expecting " + size + " notifications, got " +
                received.size());
        return 1;
    } else {
        for (Notification n : received) {
            echo("Received notification: " + n);
            if (!n.getType().equals("nb")) {
                echo("Notification type must be \"nb\"");
                return 1;
            }
            ObjectName o = (ObjectName) n.getSource();
            int index = (int) n.getSequenceNumber();
            ObjectName nb = expected.get(index);
            if (!o.equals(nb)) {
                echo("Notification source must be " + nb);
                return 1;
            }
        }
    }
    return 0;
}
 
Example 8
Project: rocketmq-flink-plugin   File: JMXGarbageCollectorNotificationClient.java   View Source Code Vote up 5 votes
public static void processNotification(MBeanServerConnection connection, Notification notification) {
    echo("\n<notification>");
    echo("\t<currentDatetime>" + DATE_FORMAT.format(Calendar.getInstance().getTime()) + "</currentDatetime>");
    echo("\t<notificationTime timestamp='" + notification.getTimeStamp() + "'>" + DATE_FORMAT.format(new Date(notification.getTimeStamp())) + "</notificationTime>");
    echo("\t<className>" + notification.getClass().getName() + "</className>");
    echo("\t<source>" + notification.getSource() + "</source>");
    echo("\t<type>" + notification.getType() + "</type>");
    echo("\t<message>" + notification.getMessage() + "</message>");
    if (notification instanceof AttributeChangeNotification) {
        echo("\t<attributeChanges>");
        AttributeChangeNotification acn = (AttributeChangeNotification) notification;
        echo("\t\t<attributeName>" + acn.getAttributeName() + "</attributeName>");
        echo("\t\t<attributeType>" + acn.getAttributeType() + "</attributeType>");
        echo("\t\t<newValue>" + acn.getNewValue() + "</newValue>");
        echo("\t\t<oldValue>" + acn.getOldValue() + "</oldValue>");
        echo("\t</attributeChanges>");
    }

    if (notification.getSource() instanceof ObjectName) {
        GarbageCollectorMXBean gcBean = JMX.newMXBeanProxy(connection, (ObjectName) notification.getSource(), GarbageCollectorMXBean.class);
        echo("\t<gcInfo>");
        echo("\t\t<collectionTime>" + gcBean.getCollectionTime() + "</collectionTime>");
        echo("\t\t<collectionCount>" + gcBean.getCollectionCount() + "</collectionCount>");
        GcInfo gcInfo = gcBean.getLastGcInfo();
        echo("\t\t<startTime>" + gcInfo.getStartTime() + "</startTime>");
        echo("\t\t<endTime>"   + gcInfo.getEndTime()   + "</endTime>");
        echo("\t\t<duration>"  + gcInfo.getDuration()  + "</duration>");
        outputMemoryUsages(gcInfo.getMemoryUsageBeforeGc(), "memoryUsageBeforeGC");
        outputMemoryUsages(gcInfo.getMemoryUsageAfterGc(), "memoryUsageAfterGC");
        echo("\t</gcInfo>");
    }

    echo("\n</notification>");
}
 
Example 9
Project: jdk8u-jdk   File: OldMBeanServerTest.java   View Source Code Vote up 4 votes
public void handleNotification(
        Notification notification, Object handback) {
    if (notification.getSource() == userMBean)
        notification.setSource(name);
    userListener.handleNotification(notification, handback);
}
 
Example 10
Project: openjdk-jdk10   File: OldMBeanServerTest.java   View Source Code Vote up 4 votes
public void handleNotification(
        Notification notification, Object handback) {
    if (notification.getSource() == userMBean)
        notification.setSource(name);
    userListener.handleNotification(notification, handback);
}
 
Example 11
Project: lams   File: ModelMBeanNotificationPublisher.java   View Source Code Vote up 2 votes
/**
 * From the {@link Notification javadoc}:
 * <p><i>"It is strongly recommended that notification senders use the object name
 * rather than a reference to the MBean object as the source."</i>
 * @param notification the {@link Notification} whose
 * {@link javax.management.Notification#getSource()} might need massaging
 */
private void replaceNotificationSourceIfNecessary(Notification notification) {
	if (notification.getSource() == null || notification.getSource().equals(this.managedResource)) {
		notification.setSource(this.objectName);
	}
}