Search in sources :

Example 6 with NotificationListener

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

the class ConcurrentModificationTest method main.

public static void main(String[] args) throws Exception {
    System.out.println(">>> test on Concurrent Modification.");
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            e.printStackTrace();
            if (e instanceof ConcurrentModificationException) {
                uncaughtException = e;
            }
        }
    });
    delegateName = new ObjectName("JMImplementation:type=MBeanServerDelegate");
    for (int i = 0; i < number; i++) {
        timerNames[i] = new ObjectName("MBean:name=Timer" + i);
        listeners[i] = new NotificationListener() {

            @Override
            public void handleNotification(Notification notification, Object handback) {
            // nothing
            }
        };
    }
    String errors = "";
    for (int i = 0; i < protocols.length; i++) {
        uncaughtException = null;
        System.out.println(">>> Test for protocol " + protocols[i]);
        test(protocols[i]);
        if (uncaughtException != null) {
            if ("".equals(errors)) {
                errors = "Failed to " + protocols[i] + ": " + uncaughtException;
            } else {
                errors = errors + ", failed to " + protocols[i] + ": " + uncaughtException;
            }
            System.out.println(">>> FAILED for protocol " + protocols[i]);
        } else {
            System.out.println(">>> PASSED for protocol " + protocols[i]);
        }
    }
    if ("".equals(errors)) {
        System.out.println("All Passed!");
    } else {
        System.out.println("!!!!!! Failed.");
        throw new RuntimeException(errors);
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) NotificationListener(javax.management.NotificationListener)

Example 7 with NotificationListener

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

the class MBeanProxyInvocationHandler method invokeBroadcasterMethod.

/**
   * The call will delegate to Managed Node for NotificationHub to register a local listener to
   * listen for notification from the MBean
   * 
   * Moreover it will also add the client to local listener list by adding to the contained emitter.
   * 
   * @param proxy the proxy object
   * @param method method to be invoked
   * @param args method arguments
   * @return result value if any
   * @throws Exception
   */
private Object invokeBroadcasterMethod(Object proxy, Method method, Object[] args) throws Throwable {
    final String methodName = method.getName();
    final int nargs = (args == null) ? 0 : args.length;
    final Class[] paramTypes = method.getParameterTypes();
    final String[] signature = new String[paramTypes.length];
    if (methodName.equals("addNotificationListener")) {
        if (nargs != 3) {
            final String msg = "Bad arg count to addNotificationListener: " + nargs;
            throw new IllegalArgumentException(msg);
        }
        /*
       * Other inconsistencies will produce ClassCastException below.
       */
        NotificationListener listener = (NotificationListener) args[0];
        NotificationFilter filter = (NotificationFilter) args[1];
        Object handback = args[2];
        emitter.addNotificationListener(listener, filter, handback);
        delegateToFucntionService(objectName, methodName, null, signature);
        return null;
    } else if (methodName.equals("removeNotificationListener")) {
        /*
       * NullPointerException if method with no args, but that shouldn't happen because removeNL
       * does have args.
       */
        NotificationListener listener = (NotificationListener) args[0];
        switch(nargs) {
            case 1:
                emitter.removeNotificationListener(listener);
                /**
           * No need to send listener and filter details to other members. We only need to send a
           * message saying remove the listner registered for this object on your side. Fixes Bug[
           * #47075 ]
           */
                delegateToFucntionService(objectName, methodName, null, signature);
                return null;
            case 3:
                NotificationFilter filter = (NotificationFilter) args[1];
                Object handback = args[2];
                emitter.removeNotificationListener(listener, filter, handback);
                delegateToFucntionService(objectName, methodName, null, signature);
                return null;
            default:
                final String msg = "Bad arg count to removeNotificationListener: " + nargs;
                throw new IllegalArgumentException(msg);
        }
    } else if (methodName.equals("getNotificationInfo")) {
        if (args != null) {
            throw new IllegalArgumentException("getNotificationInfo has " + "args");
        }
        if (!MBeanJMXAdapter.mbeanServer.isRegistered(objectName)) {
            return new MBeanNotificationInfo[0];
        }
        /**
       * MBean info is delegated to function service as intention is to get the info of the actual
       * mbean rather than the proxy
       */
        Object obj = delegateToFucntionService(objectName, methodName, args, signature);
        if (obj instanceof String) {
            return new MBeanNotificationInfo[0];
        }
        MBeanInfo info = (MBeanInfo) obj;
        return info.getNotifications();
    } else {
        throw new IllegalArgumentException("Bad method name: " + methodName);
    }
}
Also used : MBeanNotificationInfo(javax.management.MBeanNotificationInfo) MBeanInfo(javax.management.MBeanInfo) NotificationFilter(javax.management.NotificationFilter) NotificationListener(javax.management.NotificationListener)

Example 8 with NotificationListener

use of javax.management.NotificationListener 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 9 with NotificationListener

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

the class RMIConnectionInvoker method addNotificationListeners.

public Integer[] addNotificationListeners(ObjectName[] names, MarshalledObject[] filters, Subject[] delegates) throws InstanceNotFoundException, IOException {
    ArrayList ids = new ArrayList();
    for (int i = 0; i < names.length; ++i) {
        ObjectName name = names[i];
        MarshalledObject filter = filters[i];
        NotificationFilter f = (NotificationFilter) RMIMarshaller.unmarshal(filter, server.getClassLoaderFor(name), defaultLoader);
        Integer id = notificationHandler.generateListenerID(name, f);
        NotificationListener listener = notificationHandler.getServerNotificationListener();
        server.addNotificationListener(name, listener, f, id);
        notificationHandler.addNotificationListener(id, new NotificationTuple(name, listener, f, id));
        ids.add(id);
    }
    return (Integer[]) ids.toArray(new Integer[ids.size()]);
}
Also used : NotificationTuple(org.apache.felix.mosgi.jmx.rmiconnector.mx4j.remote.NotificationTuple) MarshalledObject(java.rmi.MarshalledObject) ArrayList(java.util.ArrayList) NotificationFilter(javax.management.NotificationFilter) ObjectName(javax.management.ObjectName) NotificationListener(javax.management.NotificationListener)

Example 10 with NotificationListener

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

the class DefaultMBeanServerInterceptor method removeNotificationListener.

public void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException {
    NotificationListener instance = getListener(listener);
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "removeNotificationListener", "ObjectName = " + name + ", Listener = " + listener);
    }
    server.removeNotificationListener(name, instance, filter, handback);
}
Also used : NotificationListener(javax.management.NotificationListener)

Aggregations

NotificationListener (javax.management.NotificationListener)52 Notification (javax.management.Notification)36 ObjectName (javax.management.ObjectName)18 MBeanServer (javax.management.MBeanServer)11 NotificationFilter (javax.management.NotificationFilter)10 JMXConnector (javax.management.remote.JMXConnector)10 JMXServiceURL (javax.management.remote.JMXServiceURL)10 AttributeChangeNotification (javax.management.AttributeChangeNotification)9 MBeanServerConnection (javax.management.MBeanServerConnection)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 NotificationEmitter (javax.management.NotificationEmitter)8 JMXConnectorServer (javax.management.remote.JMXConnectorServer)8 Attribute (javax.management.Attribute)7 Test (org.junit.Test)6 JMXPluggableAuthenticator (com.sun.jmx.remote.security.JMXPluggableAuthenticator)5 RemoteException (java.rmi.RemoteException)5 LocateRegistry (java.rmi.registry.LocateRegistry)5 Registry (java.rmi.registry.Registry)5 Properties (java.util.Properties)5