Search in sources :

Example 11 with NotificationListener

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

the class DefaultMBeanServerInterceptor method removeNotificationListener.

private void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback, boolean removeAll) throws InstanceNotFoundException, ListenerNotFoundException {
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "removeNotificationListener", "ObjectName = " + name);
    }
    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, null, name, "removeNotificationListener");
    /* We could simplify the code by assigning broadcaster after
           assigning listenerWrapper, but that would change the error
           behavior when both the broadcaster and the listener are
           erroneous.  */
    Class<? extends NotificationBroadcaster> reqClass = removeAll ? NotificationBroadcaster.class : NotificationEmitter.class;
    NotificationBroadcaster broadcaster = getNotificationBroadcaster(name, instance, reqClass);
    NotificationListener listenerWrapper = getListenerWrapper(listener, name, instance, false);
    if (listenerWrapper == null)
        throw new ListenerNotFoundException("Unknown listener");
    if (removeAll)
        broadcaster.removeNotificationListener(listenerWrapper);
    else {
        NotificationEmitter emitter = (NotificationEmitter) broadcaster;
        emitter.removeNotificationListener(listenerWrapper, filter, handback);
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) NotificationEmitter(javax.management.NotificationEmitter) NotificationBroadcaster(javax.management.NotificationBroadcaster) ListenerNotFoundException(javax.management.ListenerNotFoundException) NotificationListener(javax.management.NotificationListener)

Example 12 with NotificationListener

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

the class SnmpMibTable method sendNotification.

// ----------------------------------------------------------------------
// PRIVATE METHODS
// ----------------------------------------------------------------------
/**
     * Enable this <CODE>SnmpMibTable</CODE> to send a notification.
     *
     * <p>
     * @param notification The notification to send.
     */
private synchronized void sendNotification(Notification notification) {
    //
    for (java.util.Enumeration<NotificationListener> k = handbackTable.keys(); k.hasMoreElements(); ) {
        NotificationListener listener = k.nextElement();
        // Get the associated handback list and the associated filter list
        //
        java.util.Vector<?> handbackList = handbackTable.get(listener);
        java.util.Vector<NotificationFilter> filterList = filterTable.get(listener);
        // loop on handback
        //
        java.util.Enumeration<NotificationFilter> f = filterList.elements();
        for (java.util.Enumeration<?> h = handbackList.elements(); h.hasMoreElements(); ) {
            Object handback = h.nextElement();
            NotificationFilter filter = f.nextElement();
            if ((filter == null) || (filter.isNotificationEnabled(notification))) {
                listener.handleNotification(notification, handback);
            }
        }
    }
}
Also used : NotificationFilter(javax.management.NotificationFilter) NotificationListener(javax.management.NotificationListener)

Example 13 with NotificationListener

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

use of javax.management.NotificationListener in project Payara by payara.

the class ListenerTest method testAddRemoveNotificationListener.

public void testAddRemoveNotificationListener() throws Exception {
    final long start = now();
    final Set<AMX> all = getAllAMX();
    final NotificationListener listener1 = new DummyListener();
    final NotificationListener listener2 = new DummyListener();
    final NotificationFilter filter = new NotificationFilterSupport();
    final Object handback = "handback";
    for (final AMX amx : all) {
        amx.getNotificationInfo();
        amx.addNotificationListener(listener1, null, null);
        amx.addNotificationListener(listener2, filter, handback);
    }
    for (final AMX amx : all) {
        amx.removeNotificationListener(listener1);
        amx.removeNotificationListener(listener2, filter, handback);
    }
    printElapsed("Added/removed NotificationListener", all.size(), start);
}
Also used : NotificationFilterSupport(javax.management.NotificationFilterSupport) AMX(com.sun.appserv.management.base.AMX) NotificationFilter(javax.management.NotificationFilter) NotificationListener(javax.management.NotificationListener)

Example 15 with NotificationListener

use of javax.management.NotificationListener in project fabric8 by jboss-fuse.

the class ManagedApiFeature method initialize.

@Override
public void initialize(Server server, Bus bus) {
    final ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
    final InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
    if (iMgr != null) {
        try {
            iMgr.register(mApi);
            final ServerLifeCycleManager slcMgr = bus.getExtension(ServerLifeCycleManager.class);
            if (slcMgr != null) {
                slcMgr.registerListener(mApi);
                slcMgr.startServer(server);
            }
            // Register notification listener to propagate unregistration of endpoint MBeans
            final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
            if (mBeanServer == null) {
                return;
            }
            NotificationListener listener = new NotificationListener() {

                @Override
                public void handleNotification(Notification notification, Object handback) {
                    MBeanServerNotification mbsNotification = (MBeanServerNotification) notification;
                    ObjectName objectName = mbsNotification.getMBeanName();
                    String type = mbsNotification.getType();
                    try {
                        if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(type) && mApi.isCompanion(objectName)) {
                            if (slcMgr != null) {
                                slcMgr.unRegisterListener(mApi);
                            }
                            iMgr.unregister(mApi);
                            mBeanServer.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this);
                        }
                    } catch (JMException e) {
                        LOG.log(Level.WARNING, "Unregistering ManagedApi failed.", e);
                    }
                }
            };
            mBeanServer.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, mBeanServerNotificationFilter, null);
        } catch (JMException jmex) {
            jmex.printStackTrace();
            LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
        }
    }
}
Also used : ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) MBeanServerNotification(javax.management.MBeanServerNotification) JMException(javax.management.JMException) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) Notification(javax.management.Notification) MBeanServerNotification(javax.management.MBeanServerNotification) MBeanServer(javax.management.MBeanServer) NotificationListener(javax.management.NotificationListener) ObjectName(javax.management.ObjectName)

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