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:org.mc4j.ems.impl.jmx.connection.bean.DMBean.java

public boolean isRegistered() {

    MBeanServer server = getConnectionProvider().getMBeanServer();

    return server.isRegistered(getObjectName());
}

From source file:com.neophob.sematrix.core.jmx.PixelControllerStatus.java

/**
 * Register the JMX Bean.//ww  w .  ja va 2  s .  c  o m
 *
 * @param configuredFps the configured fps
 */
public PixelControllerStatus(Collector col, int configuredFps) {
    LOG.log(Level.INFO, "Initialize the PixelControllerStatus JMX Bean");

    this.configuredFps = configuredFps;
    this.col = col;

    // initialize all buffers 
    this.timeMeasureMapGlobal = new ConcurrentHashMap<TimeMeasureItemGlobal, CircularFifoBuffer>();
    for (TimeMeasureItemGlobal timeMeasureItem : TimeMeasureItemGlobal.values()) {
        this.timeMeasureMapGlobal.put(timeMeasureItem, new CircularFifoBuffer(this.configuredFps * SECONDS));
    }
    this.timeMeasureMapOutput = new ConcurrentHashMap<IOutput, Map<TimeMeasureItemOutput, CircularFifoBuffer>>();
    this.outputList = new ArrayList<IOutput>();

    startTime = System.currentTimeMillis();

    // register MBean
    try {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = new ObjectName(JMX_BEAN_NAME);
        // check if the MBean is already registered
        if (!server.isRegistered(name)) {
            server.registerMBean(this, name);
        }
    } catch (JMException ex) {
        LOG.log(Level.WARNING, "Error while registering class as JMX Bean.", ex);
    }
}

From source file:org.jolokia.jmx.JolokiaMBeanServerTest.java

@Test
public void simple() throws NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanException,
        MalformedObjectNameException, AttributeNotFoundException, ReflectionException,
        InstanceNotFoundException, ParseException, InvalidTargetObjectTypeException, NoSuchMethodException,
        IntrospectionException {//from  w ww .  j a  va 2s  .  c  o m
    JolokiaMBeanServer server = new JolokiaMBeanServer();

    ObjectName oName = new ObjectName("test:type=jsonMBean");
    server.registerMBean(new JsonAnnoTest(), oName);

    CompositeData chiliCD = (CompositeData) server.getAttribute(oName, "Chili");
    assertEquals((String) chiliCD.get("name"), "Bhut Jolokia");
    assertEquals(chiliCD.get("scoville"), 1000000L);

    MBeanServer pServer = ManagementFactory.getPlatformMBeanServer();
    String chiliS = (String) pServer.getAttribute(oName, "Chili");
    JSONObject chiliJ = (JSONObject) new JSONParser().parse(chiliS);
    assertEquals(chiliJ.get("name"), "Bhut Jolokia");
    assertEquals(chiliJ.get("scoville"), 1000000L);

    server.unregisterMBean(oName);
    Assert.assertFalse(pServer.isRegistered(oName));
    Assert.assertFalse(server.isRegistered(oName));
}

From source file:org.apache.ode.jbi.OdeLifeCycle.java

private void unregisterMBean() throws JBIException {
    try {//from ww  w . java  2  s .c  om
        if (_mbeanName != null) {
            MBeanServer server = _ode.getContext().getMBeanServer();
            assert server != null;
            if (server.isRegistered(_mbeanName)) {
                server.unregisterMBean(_mbeanName);
            }
        }
    } catch (Exception e) {
        throw new JBIException(e);
    }
}

From source file:org.apache.axis2.transport.base.AbstractTransportListener.java

private void unregisterMBean(String objectName) {
    try {/*from w  ww.  ja  v  a  2s  .  co m*/
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName objName = new ObjectName(objectName);
        if (mbs.isRegistered(objName)) {
            mbs.unregisterMBean(objName);
        }
    } catch (Exception e) {
        log.warn("Error un-registering a MBean with objectname ' " + objectName + " ' for JMX management", e);
    }
}

From source file:org.apache.ode.jbi.OdeLifeCycle.java

private void registerMBean() throws JBIException {
    ProcessAndInstanceManagementMBean pmapi = new ProcessAndInstanceManagementMBean(_ode._server, _ode._store);
    MBeanServer server = _ode.getContext().getMBeanServer();
    try {/*from   www  .  ja va 2s. co  m*/
        if (server != null) {
            _mbeanName = _ode.getContext().getMBeanNames().createCustomComponentMBeanName("Management");
            if (server.isRegistered(_mbeanName)) {
                server.unregisterMBean(_mbeanName);
            }
            server.registerMBean(pmapi, _mbeanName);
        }
    } catch (Exception e) {
        throw new JBIException(e);
    }
}

From source file:org.jolokia.jmx.JolokiaMBeanServerTest.java

@Test
public void withConstraint()
        throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException,
        MBeanException, AttributeNotFoundException, ReflectionException, InstanceNotFoundException,
        ParseException, InvalidTargetObjectTypeException, NoSuchMethodException, IntrospectionException {
    JolokiaMBeanServer server = new JolokiaMBeanServer();

    ObjectName oName = new ObjectName("test:type=jsonMBean");

    server.registerMBean(new JsonAnnoPlainTest(), oName);

    MBeanServer plattformServer = ManagementFactory.getPlatformMBeanServer();

    String deepDive = (String) plattformServer.getAttribute(oName, "DeepDive");
    JSONObject deepDiveS = (JSONObject) new JSONParser().parse(deepDive);
    assertEquals(deepDiveS.size(), 1);// w  w w .j  a  v  a2  s .  com
    // Serialization is truncated because of maxDepth = 1
    assertTrue(deepDiveS.get("map") instanceof String);
    assertTrue(deepDiveS.get("map").toString().matches(".*hot=.*Chili.*"));
    server.unregisterMBean(oName);
    Assert.assertFalse(plattformServer.isRegistered(oName));
    Assert.assertFalse(server.isRegistered(oName));
}

From source file:org.red5.server.winstone.WinstoneLoader.java

protected void registerJMX() {
    // register with jmx
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {/*from w  w  w .  j  ava  2s .c om*/
        ObjectName oName = new ObjectName("org.red5.server:type=WinstoneLoader");
        // check for existing registration before registering
        if (!mbs.isRegistered(oName)) {
            mbs.registerMBean(this, oName);
        } else {
            log.debug("ContextLoader is already registered in JMX");
        }
    } catch (Exception e) {
        log.warn("Error on jmx registration", e);
    }
}