Example usage for javax.management MBeanServerFactory findMBeanServer

List of usage examples for javax.management MBeanServerFactory findMBeanServer

Introduction

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

Prototype

public synchronized static ArrayList<MBeanServer> findMBeanServer(String agentId) 

Source Link

Document

Return a list of registered MBeanServer objects.

Usage

From source file:fedorax.server.module.storage.IrodsExternalContentManager.java

@SuppressWarnings("unused")
private MBeanServer getMBeanServer() {
    MBeanServer mbserver = null;//from  www . j a va 2 s  .  c o m
    ArrayList<MBeanServer> mbservers = MBeanServerFactory.findMBeanServer(null);

    if (mbservers.size() > 0) {
        mbserver = (MBeanServer) mbservers.get(0);
    }

    if (mbserver != null) {
        System.out.println("Found our MBean server");
    } else {
        mbserver = MBeanServerFactory.createMBeanServer();
    }

    return mbserver;
}

From source file:org.wso2.carbon.caching.impl.CacheImpl.java

private MBeanServer getMBeanServer() {
    MBeanServer mserver;/*  w  ww. j  a v a 2  s. com*/
    if (MBeanServerFactory.findMBeanServer(null).size() > 0) {
        mserver = MBeanServerFactory.findMBeanServer(null).get(0);
    } else {
        mserver = MBeanServerFactory.createMBeanServer();
    }
    return mserver;
}

From source file:org.acmsl.commons.utils.jmx.MBeanRegistrator.java

/**
 * Obtains a reference to the MBean server. If at least one
 * MBean server already exists, then a reference to that MBean
 * server is returned. Otherwise a new instance is created.
 * @param cachedInstance the cached instance, if any.
 * @return such server./*  w w  w .  j  a v  a2  s  . c o m*/
 */
@Nullable
protected MBeanServer getMBeanServer(@Nullable final MBeanServer cachedInstance) {
    MBeanServer result = cachedInstance;

    if (result == null) {
        @NotNull
        final List<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null);

        @NotNull
        final Iterator<MBeanServer> serverIterator = mbeanServers.iterator();

        while (serverIterator.hasNext()) {
            @NotNull
            final MBeanServer mbeanServer = serverIterator.next();

            mbeanServer.queryMBeans(null, null);
        }

        result = (mbeanServers.size() > 0) ? mbeanServers.get(0) : MBeanServerFactory.createMBeanServer();

        setMBeanServer(result);
    }

    return result;
}

From source file:org.rzo.yajsw.app.WrapperManagerImpl.java

private void registerMBean(YajswConfiguration config) {
    MBeanServer server = null;/*ww  w. java2 s  .c o  m*/
    ArrayList servers = MBeanServerFactory.findMBeanServer(null);
    try {
        if (servers != null && servers.size() > 0)
            server = (MBeanServer) servers.get(0);
        if (server != null) {
            String name = config.getString("wrapper.console.title");
            if (name == null)
                name = config.getString("wrapper.ntservice.name");
            if (name == null)
                name = "yajsw.noname";
            ObjectName oName = new ObjectName("Wrapper", "name", name);
            server.registerMBean(this, oName);
            // System.out.println("found mbean server: " +
            // server.toString());
        } else
            System.out.println("ERROR: no mbean server found ");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.apache.juddi.v3.client.mapping.UDDIServiceCache.java

private MBeanServer getMBeanServer() {
    MBeanServer mbserver = null;//  w w w. j  a  va2  s .  co  m
    ArrayList<MBeanServer> mbservers = MBeanServerFactory.findMBeanServer(null);
    if (mbservers.size() > 0) {
        mbserver = (MBeanServer) mbservers.get(0);
    }
    if (mbserver != null && log.isDebugEnabled()) {
        log.debug("Found MBean server");
    } else {
        mbserver = ManagementFactory.getPlatformMBeanServer();
    }
    return mbserver;
}

From source file:com.evolveum.midpoint.web.page.PageTemplate.java

protected void clearLessJsCache(AjaxRequestTarget target) {
    try {//from w  w w . ja v a2  s  .c o m
        ArrayList<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
        if (servers.size() > 1) {
            LOGGER.info("Too many mbean servers, cache won't be cleared.");
            for (MBeanServer server : servers) {
                LOGGER.info(server.getDefaultDomain());
            }
            return;
        }
        MBeanServer server = servers.get(0);
        ObjectName objectName = ObjectName.getInstance("wro4j-idm:type=WroConfiguration");
        server.invoke(objectName, "reloadCache", new Object[] {}, new String[] {});
        if (target != null) {
            target.add(PageTemplate.this);
        }
    } catch (Exception ex) {
        LoggingUtils.logException(LOGGER, "Couldn't clear less/js cache", ex);
        error("Error occurred, reason: " + ex.getMessage());
        if (target != null) {
            target.add(getFeedbackPanel());
        }
    }
}

From source file:org.apache.camel.management.DefaultManagementAgent.java

protected MBeanServer findOrCreateMBeanServer() {

    // return platform mbean server if the option is specified.
    if (usePlatformMBeanServer) {
        return ManagementFactory.getPlatformMBeanServer();
    }//from  w  w  w .j ava  2s .  c o m

    // look for the first mbean server that has match default domain name
    List<MBeanServer> servers = (List<MBeanServer>) MBeanServerFactory.findMBeanServer(null);

    for (MBeanServer server : servers) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Found MBeanServer with default domain " + server.getDefaultDomain());
        }

        if (mBeanServerDefaultDomain.equals(server.getDefaultDomain())) {
            return server;
        }
    }

    // create a mbean server with the given default domain name
    return MBeanServerFactory.createMBeanServer(mBeanServerDefaultDomain);
}

From source file:org.apache.jk.common.JkMX.java

MBeanServer getMBeanServer() {
    MBeanServer server;/* ww  w  . j  a  v a2s .co  m*/
    if (MBeanServerFactory.findMBeanServer(null).size() > 0) {
        server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0);
    } else {
        server = MBeanServerFactory.createMBeanServer();
    }
    return (server);
}

From source file:com.octo.captcha.j2ee.ImageCaptchaService.java

/**
 * Register self to the first MBean server available in the JVM, if
 * any.//from w w w.j  a  v a 2s. co m
 * @param theRegisteringName the name the service will be registered
 * to the MBean server.
 * @throws ImageCaptchaServiceException in case of error. Possible
 * error details are :
 * <ul>
 *  <li> ImageCaptchaServiceException.MALFORMED_REGISTERING_NAME</li>
 *  <li> ImageCaptchaServiceException.INSTANCE_ALREADY_REGISTERED</li>
 * </ul>
 * @see com.octo.captcha.j2ee.ImageCaptchaServiceException#MALFORMED_REGISTERING_NAME
 * @see com.octo.captcha.j2ee.ImageCaptchaServiceException#INSTANCE_ALREADY_REGISTERED
 */
public void registerToMBeanServer(String theRegisteringName) throws ImageCaptchaServiceException {
    ArrayList mbeanServers = MBeanServerFactory.findMBeanServer(null);
    if (mbeanServers.size() == 0) {
        log.warn("No current MBean Server, skiping the registering process");
    } else {
        MBeanServer mbeanServer = (MBeanServer) mbeanServers.get(0);
        try {
            ObjectName name = new ObjectName(theRegisteringName);
            mbeanServer.registerMBean(this, name);
            this.registeredName = theRegisteringName;
        } catch (MalformedObjectNameException e) {
            throw new ImageCaptchaServiceException(ImageCaptchaServiceException.MALFORMED_REGISTERING_NAME, e);
        } catch (InstanceAlreadyExistsException e) {
            throw new ImageCaptchaServiceException(ImageCaptchaServiceException.INSTANCE_ALREADY_REGISTERED, e);
        } catch (MBeanRegistrationException e) {
            // this exception should never be raised (raised
            // only by an MBean that implements the MBeanRegistration
            // interface.
            log.error("An unexpected exception has been raised : " + "ImageCaptchaService needs maintenance !",
                    e);
        } catch (NotCompliantMBeanException e) {
            // this should never happens
            log.error("Exception trying to register the service to" + " the MBean server", e);
        }
    }
}

From source file:org.rhq.core.server.PersistenceUtility.java

/**
 * Enables the hibernate statistics mbean to provide access to information on the ejb3 persistence tier.
 *
 * @param entityManager an inject entity manager whose session factory will be tracked with these statistics
 * @param server        the MBeanServer where the statistics MBean should be registered; if <code>null</code>, the
 *                      first one in the list returned by MBeanServerFactory.findMBeanServer(null) is used
 *//*from  w  w  w  .  jav  a 2  s. c  o m*/
public static void enableHibernateStatistics(EntityManager entityManager, MBeanServer server) {
    try {
        SessionFactory sessionFactory = PersistenceUtility.getHibernateSession(entityManager)
                .getSessionFactory();

        if (server == null) {
            ArrayList<MBeanServer> list = MBeanServerFactory.findMBeanServer(null);
            server = list.get(0);
        }

        ObjectName objectName = new ObjectName(HIBERNATE_STATISTICS_MBEAN_OBJECTNAME);
        StatisticsService mBean = new StatisticsService();
        mBean.setSessionFactory(sessionFactory);
        server.registerMBean(mBean, objectName);
        sessionFactory.getStatistics().setStatisticsEnabled(true);
    } catch (InstanceAlreadyExistsException iaee) {
        LOG.info("Duplicate mbean registration ignored: " + HIBERNATE_STATISTICS_MBEAN_OBJECTNAME);
    } catch (Exception e) {
        LOG.warn("Couldn't register hibernate statistics mbean", e);
    }
}