Search in sources :

Example 21 with Notification

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

the class DynamicMBeanImpl method sendNotification.

/**
 * Sends a notification to a subscriber.
 *
 * @param msg the msg to send
 * @param attributeName the name of the attribute
 * @param attributeType the type of the attribute
 * @param oldValue the old value of the attribute
 * @param newValue the new value of the attribute
 */
public void sendNotification(String msg, String attributeName, String attributeType, Object oldValue, Object newValue) {
    long timeStamp = System.currentTimeMillis();
    if ((newValue == null && oldValue == null) || (newValue != null && newValue.equals(oldValue))) {
        return;
    }
    m_sequenceNumber++;
    Notification notification = new AttributeChangeNotification(this, m_sequenceNumber, timeStamp, msg, attributeName, attributeType, oldValue, newValue);
    sendNotification(notification);
    m_instanceManager.getFactory().getLogger().log(Logger.INFO, "Notification sent");
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification) Notification(javax.management.Notification) AttributeChangeNotification(javax.management.AttributeChangeNotification)

Example 22 with Notification

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

the class RemoteNotificationClientHandler method sendNotification.

private void sendNotification(TargetedNotification notification) {
    NotificationTuple tuple = null;
    synchronized (tuples) {
        tuple = (NotificationTuple) tuples.get(notification.getListenerID());
    }
    // It may be possible that a notification arrived after the client already removed the listener
    if (tuple == null)
        return;
    Notification notif = notification.getNotification();
    if (tuple.getInvokeFilter()) {
        // Invoke the filter on client side
        NotificationFilter filter = tuple.getNotificationFilter();
        RmiConnectorActivator.log(LogService.LOG_DEBUG, "Filtering notification " + notif + ", filter = " + filter, null);
        if (filter != null) {
            try {
                boolean deliver = filter.isNotificationEnabled(notif);
                if (!deliver)
                    return;
            } catch (RuntimeException x) {
                RmiConnectorActivator.log(LogService.LOG_WARNING, "RuntimeException caught from isNotificationEnabled, filter = " + filter, x);
            // And go on quietly
            }
        }
    }
    RmiConnectorActivator.log(LogService.LOG_DEBUG, "Sending Notification " + notif + ", listener info is " + tuple, null);
    NotificationListener listener = tuple.getNotificationListener();
    try {
        listener.handleNotification(notif, tuple.getHandback());
    } catch (RuntimeException x) {
        RmiConnectorActivator.log(LogService.LOG_WARNING, "RuntimeException caught from handleNotification, listener = " + listener, x);
    // And return quietly
    }
}
Also used : NotificationFilter(javax.management.NotificationFilter) TargetedNotification(javax.management.remote.TargetedNotification) Notification(javax.management.Notification) NotificationListener(javax.management.NotificationListener)

Example 23 with Notification

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

the class UserManager method notifyUserAdminEvent.

// ///////PRIVATE METHODS//////////////////////////
private void notifyUserAdminEvent(UserAdminEvent event) {
    String typedesc = null;
    switch(event.getType()) {
        case UserAdminEvent.ROLE_CREATED:
            typedesc = "created";
            break;
        case UserAdminEvent.ROLE_CHANGED:
            typedesc = "changed";
            break;
        case UserAdminEvent.ROLE_REMOVED:
            typedesc = "removed";
            break;
    }
    try {
        ObjectName source = new ObjectName(ObjectNames.UA_SERVICE);
        String message = "User Admin event: Role " + event.getRole().getName() + typedesc;
        Notification notification = new Notification(AgentConstants.USER_ADMIN_NOTIFICATION_TYPE, source, sequenceNumber++, message);
        CompositeData userData = OSGi2JMXCodec.encodeUserAdminEvent(event);
        notification.setUserData(userData);
        sendNotification(notification);
    } catch (Exception e) {
        ac.error("Unexpected exception", e);
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName)

Example 24 with Notification

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

the class ResultLogManager method clearMemoryLog.

// Clear the memory log, sends a notification indicating that
// the memory log was cleared.
//
private void clearMemoryLog() throws IOException {
    synchronized (this) {
        memoryLog.clear();
        memCapacityReached = false;
    }
    sendNotification(new Notification(MEMORY_LOG_CLEARED, objectName, getNextSeqNumber(), "memory log cleared"));
}
Also used : Notification(javax.management.Notification)

Example 25 with Notification

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

the class ServerNotifForwarder method snoopOnUnregister.

// The standard RMI connector client will register a listener on the MBeanServerDelegate
// in order to be told when MBeans are unregistered.  We snoop on fetched notifications
// so that we can know too, and remove the corresponding entry from the listenerMap.
// See 6957378.
private void snoopOnUnregister(NotificationResult nr) {
    List<IdAndFilter> copy = null;
    synchronized (listenerMap) {
        Set<IdAndFilter> delegateSet = listenerMap.get(MBeanServerDelegate.DELEGATE_NAME);
        if (delegateSet == null || delegateSet.isEmpty()) {
            return;
        }
        copy = new ArrayList<>(delegateSet);
    }
    for (TargetedNotification tn : nr.getTargetedNotifications()) {
        Integer id = tn.getListenerID();
        for (IdAndFilter idaf : copy) {
            if (idaf.id == id) {
                // This is a notification from the MBeanServerDelegate.
                Notification n = tn.getNotification();
                if (n instanceof MBeanServerNotification && n.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
                    MBeanServerNotification mbsn = (MBeanServerNotification) n;
                    ObjectName gone = mbsn.getMBeanName();
                    synchronized (listenerMap) {
                        listenerMap.remove(gone);
                    }
                }
            }
        }
    }
}
Also used : MBeanServerNotification(javax.management.MBeanServerNotification) TargetedNotification(javax.management.remote.TargetedNotification) TargetedNotification(javax.management.remote.TargetedNotification) Notification(javax.management.Notification) MBeanServerNotification(javax.management.MBeanServerNotification) ObjectName(javax.management.ObjectName)

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