Example usage for javax.management MBeanServer addNotificationListener

List of usage examples for javax.management MBeanServer addNotificationListener

Introduction

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

Prototype

public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter,
        Object handback) throws InstanceNotFoundException;

Source Link

Usage

From source file:com.googlecode.psiprobe.beans.ContainerListenerBean.java

/**
 * Load ObjectNames for the relevant MBeans so they can be queried at a later stage without searching MBean server
 * over and over again./*from   w  w  w .j  a  v  a 2s  .c  om*/
 *
 * @throws Exception - this method does not handle any of the exceptions that may be thrown when querying MBean server.
 */
private synchronized void initialize() throws Exception {

    MBeanServer server = getContainerWrapper().getResourceResolver().getMBeanServer();
    String serverName = getContainerWrapper().getTomcatContainer().getName();
    Set threadPools = server.queryMBeans(new ObjectName(serverName + ":type=ThreadPool,*"), null);
    poolNames = new ArrayList(threadPools.size());
    for (Iterator it = threadPools.iterator(); it.hasNext();) {

        ThreadPoolObjectName threadPoolObjectName = new ThreadPoolObjectName();
        ObjectName threadPoolName = ((ObjectInstance) it.next()).getObjectName();

        String name = threadPoolName.getKeyProperty("name");

        threadPoolObjectName.setThreadPoolName(threadPoolName);
        ObjectName grpName = server
                .getObjectInstance(new ObjectName(
                        threadPoolName.getDomain() + ":type=GlobalRequestProcessor,name=" + name))
                .getObjectName();
        threadPoolObjectName.setGlobalRequestProcessorName(grpName);

        //
        // unfortunately exact workers could not be found at the time of testing
        // so we filter out the relevant workers within the loop
        //
        Set workers = server
                .queryMBeans(new ObjectName(threadPoolName.getDomain() + ":type=RequestProcessor,*"), null);

        for (Iterator wrkIt = workers.iterator(); wrkIt.hasNext();) {
            ObjectName wrkName = ((ObjectInstance) wrkIt.next()).getObjectName();
            if (name.equals(wrkName.getKeyProperty("worker"))) {
                threadPoolObjectName.getRequestProcessorNames().add(wrkName);
            }
        }

        poolNames.add(threadPoolObjectName);
    }

    Set executors = server.queryMBeans(new ObjectName(serverName + ":type=Executor,*"), null);
    executorNames = new ArrayList(executors.size());
    for (Iterator it = executors.iterator(); it.hasNext();) {
        ObjectName executorName = ((ObjectInstance) it.next()).getObjectName();
        executorNames.add(executorName);
    }

    // Register with MBean server
    server.addNotificationListener(new ObjectName("JMImplementation:type=MBeanServerDelegate"), this, null,
            null);

}

From source file:org.hyperic.hq.plugin.weblogic.config.WeblogicAttributeChangeListener.java

public void add() throws PluginException {

    MBeanServer mServer;

    try {//ww w . jav  a  2  s .  co  m
        mServer = WeblogicUtil.getMBeanServer(this.props);
    } catch (MetricUnreachableException e) {
        throw new PluginException(e.getMessage(), e);
    } catch (MetricNotFoundException e) {
        throw new PluginException(e.getMessage(), e);
    }

    String[] mbeans = translate(this.mbeans);

    for (int i = 0; i < mbeans.length; i++) {
        ObjectName obj;
        try {
            obj = new ObjectName(mbeans[i]);
        } catch (MalformedObjectNameException e) {
            //programmer error.
            throw new IllegalArgumentException(e.getMessage());
        }

        try {
            mServer.addNotificationListener(obj, this, getFilter(), getHandback());
            log.info("Added listener for: " + mbeans[i]);
        } catch (InstanceNotFoundException e) {
            throw new PluginException("InstanceNotFound: '" + mbeans[i] + "'", e);
        }
    }
}

From source file:org.josso.gateway.event.security.SSOEventManagerMBean.java

public void addNotificationListener(SSOEventListener listener) throws InstanceNotFoundException {

    MBeanServer server = this.registry.getMBeanServer();

    // Wrapp received listener with JMX listener.
    // This hardly works ... because in different versions of common-modeler, oname is a String or a ObjectName instance !!!
    server.addNotificationListener(oname, new NotificationSSOEventListener(listener), null, null);
}

From source file:org.rhq.enterprise.gui.startup.StartupServlet.java

/**
 * Registers a listener to the JBoss server's shutdown notification so some components can be cleaned up in an
 * orderly fashion when the server is shutdown.
 *
 * @throws ServletException if cannot register this service as a shutdown listener
 *//*from  www . j  a v  a 2  s  .  c o  m*/
private void registerShutdownListener() throws ServletException {
    // as of JBossAS 4.0.5, this is the known MBean name of the service that notifies when the server is shutting down
    try {
        ObjectName jbossServerName = new ObjectName("jboss.system:type=Server");
        MBeanServer jbossServer = MBeanServerLocator.locateJBoss();
        jbossServer.addNotificationListener(jbossServerName, new ShutdownListener(), null, null);
    } catch (Exception e) {
        throw new ServletException("Failed to register the Server Shutdown Listener", e);
    }
}