Example usage for javax.management ObjectName getInstance

List of usage examples for javax.management ObjectName getInstance

Introduction

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

Prototype

public static ObjectName getInstance(ObjectName name) 

Source Link

Document

Return an instance of ObjectName that can be used anywhere the given object can be used.

Usage

From source file:org.mule.management.agents.JmxAgent.java

public void unregisterComponentService(String name)
        throws MalformedObjectNameException, InstanceNotFoundException, MBeanRegistrationException {
    ObjectName on = ObjectName.getInstance(getDomainName() + ":type=control,name=" + name + "ComponentService");
    logger.debug("Unregistering component with name: " + on);
    mBeanServer.unregisterMBean(on);/*from  ww  w.j  a va 2 s .  c  o  m*/
    registeredMBeans.remove(on);
}

From source file:org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory.java

/**
 * Registers the Platform MBeanServer as OSGi service. This would enable
 * Aries JMX Whitboard support to then register the JMX MBean which are registered as OSGi service
 * to be registered against the MBean server
 *//*from   w  w w .  j  ava 2 s  .  c o  m*/
private static void registerMBeanServer(PojoServiceRegistry registry) {
    MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    Hashtable<String, Object> mbeanProps = new Hashtable<String, Object>();
    try {
        ObjectName beanName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
        AttributeList attrs = platformMBeanServer.getAttributes(beanName,
                new String[] { "MBeanServerId", "SpecificationName", "SpecificationVersion",
                        "SpecificationVendor", "ImplementationName", "ImplementationVersion",
                        "ImplementationVendor" });
        for (Object object : attrs) {
            Attribute attr = (Attribute) object;
            if (attr.getValue() != null) {
                mbeanProps.put(attr.getName(), attr.getValue().toString());
            }
        }
    } catch (Exception je) {
        log.info("Cannot set service properties of Platform MBeanServer service, registering without", je);
    }
    registry.registerService(MBeanServer.class.getName(), platformMBeanServer, mbeanProps);
}

From source file:org.mule.management.agents.JmxAgent.java

protected void registerEndpointServices() throws NotCompliantMBeanException, MBeanRegistrationException,
        InstanceAlreadyExistsException, MalformedObjectNameException {
    Iterator iter = MuleManager.getInstance().getConnectors().values().iterator();
    UMOConnector connector;//ww w . j  a va2 s . c o  m
    List endpointMBeans;

    while (iter.hasNext()) {
        connector = (UMOConnector) iter.next();
        if (connector instanceof AbstractConnector) {
            endpointMBeans = ((AbstractConnector) connector).getEndpointMBeans();

            for (ListIterator iterator = endpointMBeans.listIterator(); iterator.hasNext();) {
                EndpointServiceMBean mBean = (EndpointServiceMBean) iterator.next();
                if (logger.isDebugEnabled()) {
                    logger.debug("Attempting to register service with name: " + getDomainName()
                            + ":type=control,name=" + mBean.getName() + " EndpointService");
                }
                ObjectName on = ObjectName.getInstance(getDomainName() + ":type=control,name=" + mBean.getName()
                        + "_" + iterator.nextIndex() + " EndpointService");
                mBeanServer.registerMBean(mBean, on);
                registeredMBeans.add(on);
                logger.info("Registered Endpoint Service with name: " + on);
            }
        } else {
            logger.warn("Connector: " + connector
                    + " is not an istance of AbstractConnector, cannot obtain Endpoint MBeans from it");
        }

    }
}

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 w  w .  ja v a 2s  .co  m
            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:io.soabase.core.SoaBundle.java

private void addMetrics(Environment environment) {
    Metric metric = new Gauge<Double>() {
        private double lastValue = 0.0;

        @Override/*from   ww w .  ja  va  2s .  c om*/
        public Double getValue() {
            try {
                MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
                ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
                AttributeList list = mbs.getAttributes(name, new String[] { "SystemCpuLoad" });
                if ((list != null) && (list.size() > 0)) {
                    // unfortunately, this bean reports bad values occasionally. Filter them out.
                    Object value = list.asList().get(0).getValue();
                    double d = (value instanceof Number) ? ((Number) value).doubleValue() : 0.0;
                    d = ((d > 0.0) && (d < 1.0)) ? d : lastValue;
                    lastValue = d;
                    return d;
                }
            } catch (Exception ignore) {
                // ignore
            }
            return lastValue;
        }
    };
    environment.metrics().register("system.cpu.load", metric);
}

From source file:org.mule.management.agents.JmxAgent.java

/**
 * Register a list of endpoint services. Registering one endpoint service
 * at a time does not work, because getEndpointMBeans() returns an empty
 * list. Instead, this method takes a list of all the endpoints and goes
 * through the same process as the above method, while only registering 
 * endpoints contained in the list.// www.j av  a2  s  . c o  m
 * @param names
 */
public void registerEndpointServices(List<String> names) throws NotCompliantMBeanException,
        MBeanRegistrationException, InstanceAlreadyExistsException, MalformedObjectNameException {
    Iterator iter = MuleManager.getInstance().getConnectors().values().iterator();
    UMOConnector connector;
    List endpointMBeans;

    while (iter.hasNext()) {
        connector = (UMOConnector) iter.next();
        if (connector instanceof AbstractConnector) {
            if (names.contains(connector.getName())) {
                endpointMBeans = ((AbstractConnector) connector).getEndpointMBeans();

                for (ListIterator iterator = endpointMBeans.listIterator(); iterator.hasNext();) {
                    EndpointServiceMBean mBean = (EndpointServiceMBean) iterator.next();
                    if (logger.isDebugEnabled()) {
                        logger.debug("Attempting to register service with name: " + getDomainName()
                                + ":type=control,name=" + mBean.getName() + " EndpointService");
                    }
                    ObjectName on = ObjectName.getInstance(getDomainName() + ":type=control,name="
                            + mBean.getName() + "_" + iterator.nextIndex() + " EndpointService");
                    mBeanServer.registerMBean(mBean, on);
                    registeredMBeans.add(on);
                    logger.info("Registered Endpoint Service with name: " + on);
                }
            }
        } else {
            logger.warn("Connector: " + connector
                    + " is not an istance of AbstractConnector, cannot obtain Endpoint MBeans from it");
        }

    }
}

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

private ObjectName createRetrierObjectName(AdapterManager parent) throws MalformedObjectNameException {
    return ObjectName.getInstance(JMX_FAILED_MESSAGE_RETRIER_TYPE + parent.createObjectHierarchyString()
            + ID_PREFIX + DefaultFailedMessageRetrier.class.getSimpleName());
}

From source file:org.mule.management.agents.JmxAgent.java

public void registerConnectorServices() throws MalformedObjectNameException, NotCompliantMBeanException,
        MBeanRegistrationException, InstanceAlreadyExistsException {
    Iterator iter = MuleManager.getInstance().getConnectors().values().iterator();
    while (iter.hasNext()) {
        UMOConnector connector = (UMOConnector) iter.next();
        ConnectorServiceMBean mBean = new ConnectorService(connector);
        final String stringName = getDomainName() + ":type=control,name=" + mBean.getName() + "Service";
        if (logger.isDebugEnabled()) {
            logger.debug("Attempting to register service with name: " + stringName);
        }//from   ww w  .  ja v  a 2s .  co  m
        ObjectName oName = ObjectName.getInstance(stringName);
        mBeanServer.registerMBean(mBean, oName);
        registeredMBeans.add(oName);
        logger.info("Registered Connector Service with name " + oName);
    }
}

From source file:org.mule.management.agents.JmxAgent.java

public void registerConnectorService(UMOConnector connector) throws MalformedObjectNameException,
        NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException {
    ConnectorServiceMBean mBean = new ConnectorService(connector);
    final String stringName = getDomainName() + ":type=control,name=" + mBean.getName() + "Service";
    if (logger.isDebugEnabled()) {
        logger.debug("Attempting to register service with name: " + stringName);
    }/* w ww. j  a  v a2 s .com*/
    ObjectName oName = ObjectName.getInstance(stringName);
    mBeanServer.registerMBean(mBean, oName);
    registeredMBeans.add(oName);
    logger.info("Registered Connector Service with name " + oName);
}

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

private ObjectName createMessageErrorDigestObjectName(String adapterName, String digesterId)
        throws MalformedObjectNameException {
    return ObjectName
            .getInstance(JMX_MSG_ERR_DIGESTER_TYPE + ADAPTER_PREFIX + adapterName + ID_PREFIX + digesterId);

}