Example usage for javax.management MBeanServer isRegistered

List of usage examples for javax.management MBeanServer isRegistered

Introduction

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

Prototype

public boolean isRegistered(ObjectName name);

Source Link

Usage

From source file:com.amazonaws.client.metrics.jmx.MBeans.java

/**
 * Returns true if an MBean identified by the specified object name is
 * already registered with the first MBean server, or the platform MBean
 * server if there is no explicitly registered MBean server; false
 * otherwise./*from w  w  w.ja  v a  2s  . co  m*/
 */
public static boolean isRegistered(String objectName) {
    MBeanServer server = getMBeanServer();
    try {
        return server.isRegistered(new ObjectName(objectName));
    } catch (MalformedObjectNameException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:org.nuxeo.ecm.webapp.seam.SeamHotReloadHelper.java

/**
 * Flushes resources for tomcat cache//  w  w w .java2  s .  c o m
 *
 * @since 5.5
 */
protected static void flushWebResources() throws ReflectiveOperationException, JMException {
    ObjectName on = new ObjectName("org.nuxeo:type=sdk,name=web-resources");
    MBeanServer mbs = Framework.getLocalService(ServerLocator.class).lookupServer();
    if (mbs.isRegistered(on)) {
        // only in tomcat container
        mbs.invoke(on, "flushWebResources", new Object[0], new String[0]);
    }
}

From source file:com.meltmedia.cadmium.deployer.JBossUtil.java

public static void addVirtualHost(String domain, Logger log) throws InstanceNotFoundException,
        MalformedObjectNameException, ReflectionException, MBeanException, NullPointerException {
    MBeanServer server = MBeanServerLocator.locateJBoss();
    boolean aliasFound = server.isRegistered(new ObjectName("jboss.web:type=Host,host=" + domain));
    if (!aliasFound) {
        log.info("Adding vHost {} to jboss", domain);
        Host host = (Host) server.instantiate("org.apache.catalina.core.StandardHost");
        host.setName(domain);//from   w  ww.  ja v  a  2 s . com

        server.invoke(new ObjectName("jboss.web:type=Engine"), "addChild", new Object[] { host },
                new String[] { "org.apache.catalina.Container" });
    }
}

From source file:com.espertech.esper.metrics.jmx.CommonJMXUtil.java

private static void registerMbean(MBeanServer server, ModelMBean mbean, ObjectName name) {
    try {/*from  w w  w.j a  v a  2  s.co m*/
        synchronized (LOCK) {
            if (server.isRegistered(name))
                unregisterMbean(server, name);
            server.registerMBean(mbean, name);
        }
    } catch (Exception e) {
        log.error("Error registering mbean:" + e.getMessage(), e);
    }
}

From source file:org.dspace.kernel.DSpaceKernelManager.java

/**
 * Register a new kernel MBean with the given name or fail
 * @param mBeanName the bean name to use
 * @param kernel the kernel bean to register
 * @throws IllegalStateException if the MBean cannot be registered
 *///from  w  w  w  . ja v a 2 s  . c o  m
public static void registerMBean(String mBeanName, DSpaceKernel kernel) {
    String checkedMBeanName = DSpaceKernelManager.checkName(mBeanName);
    synchronized (mBeanName) {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        try {
            ObjectName name = new ObjectName(checkedMBeanName);
            if (!mbs.isRegistered(name)) {
                // register the MBean
                mbs.registerMBean(kernel, name);
                log.info("Registered new Kernel MBEAN: " + checkedMBeanName + " [" + kernel + "]");
            }
        } catch (MalformedObjectNameException e) {
            throw new IllegalStateException(e);
        } catch (InstanceAlreadyExistsException e) {
            throw new IllegalStateException(e);
        } catch (MBeanRegistrationException e) {
            throw new IllegalStateException(e);
        } catch (NotCompliantMBeanException e) {
            throw new IllegalStateException(e);
        } catch (NullPointerException e) {
            throw new IllegalStateException(e);
        }
    }
}

From source file:org.ofbiz.core.entity.transaction.DBCPConnectionFactory.java

private static void unregisterMBeanIfPresent() {
    // We want to make sure mBean will be unregistered
    final Properties dbcpProperties = loadDbcpProperties();
    if (dbcpProperties.containsKey(PROP_JMX) && Boolean.valueOf(dbcpProperties.getProperty(PROP_JMX))) {
        final String mBeanName = dbcpProperties.getProperty(PROP_MBEANNAME);
        try {/*from  w  ww .  j  a v a2  s. c om*/
            final ObjectName objectName = ObjectName.getInstance(dbcpProperties.getProperty(PROP_MBEANNAME));
            final MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
            if (platformMBeanServer.isRegistered(objectName)) {
                platformMBeanServer.unregisterMBean(objectName);
            }
        } catch (Exception e) {
            log.error("Exception un-registering MBean data source " + mBeanName, e);
        }
    }
}

From source file:com.flexive.shared.CacheAdmin.java

/**
 * Check if the cache MBean is installed in the application server
 *
 * @return cache MBean installed/*from  www .java  2  s . c om*/
 */
public static boolean isCacheMBeanInstalled() {
    MBeanServer server = MBeanHelper.locateServer();
    try {
        return server.isRegistered((new FxCacheProxy(server)).getName());
    } catch (MalformedObjectNameException e) {
        LOG.error(e);
        return false;
    }
}

From source file:com.flexive.shared.CacheAdmin.java

/**
 * Returns the FxCache instance.//from   ww w.j av  a2  s  .c  o m
 *
 * @return the cache instance
 */
public static synchronized FxCacheMBean getInstance() {
    if (cache != null) {
        return cache;
    }
    //        System.out.println("Locating ....");

    try {
        MBeanServer server = MBeanHelper.locateServer();
        cache = new FxCacheProxy(server);
        if (!server.isRegistered(((FxCacheProxy) cache).getName())) {
            LOG.info("Registering FxCacheMBean .... ");
            EJBLookup.getGlobalConfigurationEngine().registerCacheMBean(((FxCacheProxy) cache).getName());
            //                    server.registerMBean(new FxCache(), ((FxCacheProxy)cache).getName());
            if (LOG.isDebugEnabled())
                LOG.debug("Registered: " + server.isRegistered(((FxCacheProxy) cache).getName()));
            cache.create();
        } else if (!isSharedCache()) {
            // check if MBean Server is from current deployment. Currently this is disabled
            // if the cache is shared between different deployments in the same VM, so undeploying
            // the instance that provides will remove the cache for the other applications until
            // a new flexive application is deployed.

            String deployedId = cache.getDeploymentId();
            if (MBeanHelper.DEPLOYMENT_ID.equals(deployedId))
                return cache;
            LOG.info(
                    "Redeployment! Have to undeploy " + deployedId + " (vs " + MBeanHelper.DEPLOYMENT_ID + ")");
            uninstallLocalInstance();
            EJBLookup.getGlobalConfigurationEngine().registerCacheMBean(((FxCacheProxy) cache).getName());
            LOG.debug("Registered: " + server.isRegistered(((FxCacheProxy) cache).getName()));
            cache.create();
        }
        return cache;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        return null;
    }
}

From source file:com.adaptris.core.runtime.AdapterRegistry.java

public static AdapterRegistryMBean findInstance(Properties cfg)
        throws MalformedObjectNameException, CoreException {
    MBeanServer mbs = JmxHelper.findMBeanServer();
    AdapterRegistryMBean result = null;/*w ww.  j a va 2 s  .c om*/
    ObjectName objName = ObjectName.getInstance(STANDARD_REGISTRY_JMX_NAME);
    if (mbs.isRegistered(objName)) {
        result = JMX.newMBeanProxy(mbs, objName, AdapterRegistryMBean.class);
        result.addConfiguration(cfg);
    } else {
        result = new AdapterRegistry();
        result.registerMBean();
        result.addConfiguration(cfg);
    }
    return result;
}

From source file:org.jahia.bin.errors.ErrorFileDumper.java

public static boolean isHeapDumpSupported() throws MalformedObjectNameException {
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName hotSpotDiagnostic = new ObjectName("com.sun.management:type=HotSpotDiagnostic");
    return mBeanServer.isRegistered(hotSpotDiagnostic);
}