Example usage for javax.management MBeanServerNotification MBeanServerNotification

List of usage examples for javax.management MBeanServerNotification MBeanServerNotification

Introduction

In this page you can find the example usage for javax.management MBeanServerNotification MBeanServerNotification.

Prototype

public MBeanServerNotification(String type, Object source, long sequenceNumber, ObjectName objectName) 

Source Link

Document

Creates an MBeanServerNotification object specifying object names of the MBeans that caused the notification and the specified notification type.

Usage

From source file:net.sbbi.upnp.jmx.upnp.UPNPConnectorServer.java

public void start() throws IOException {
    MBeanServer server = getMBeanServer();
    if (exposeMBeansAsUPNP.booleanValue()) {
        try {/*from w  w w.jav a 2s  . co m*/
            ObjectName delegate = new ObjectName("JMImplementation:type=MBeanServerDelegate");
            NotificationEmitter emmiter = (NotificationEmitter) MBeanServerInvocationHandler
                    .newProxyInstance(server, delegate, NotificationEmitter.class, false);
            // register for MBeans registration
            emmiter.addNotificationListener(this, null, this);
        } catch (Exception ex) {
            IOException ioEx = new IOException("UPNPConnector start error");
            ioEx.initCause(ex);
            throw ioEx;
        }
    }
    if (exposeUPNPAsMBeans.booleanValue()) {
        int timeout = 2500;
        if (env.containsKey(EXPOSE_UPNP_DEVICES_AS_MBEANS_TIMEOUT)) {
            timeout = ((Integer) env.get(EXPOSE_UPNP_DEVICES_AS_MBEANS_TIMEOUT)).intValue();
        }
        try {
            discoveryBeanName = new ObjectName("UPNPLib discovery:name=Discovery MBean_" + this.hashCode());
            UPNPDiscoveryMBean bean = new UPNPDiscovery(timeout, handleSSDPMessages.booleanValue(), true);
            server.registerMBean(bean, discoveryBeanName);
        } catch (Exception ex) {
            IOException ioEx = new IOException("Error occured during MBeans discovery");
            ioEx.initCause(ex);
            throw ioEx;
        }
    }
    if (exposeExistingMBeansAsUPNP.booleanValue()) {
        int c = 0;
        Set objectInstances = super.getMBeanServer().queryNames(null, null);
        for (Iterator i = objectInstances.iterator(); i.hasNext();) {
            ObjectName name = (ObjectName) i.next();
            MBeanServerNotification not = new MBeanServerNotification(
                    MBeanServerNotification.REGISTRATION_NOTIFICATION, this, c++, name);
            handleNotification(not, this);
        }
    }
}