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(String domain, Hashtable<String, String> table)
        throws MalformedObjectNameException 

Source Link

Document

Return an instance of ObjectName that can be used anywhere an object obtained with #ObjectName(String,Hashtable) new ObjectName(domain, table) can be used.

Usage

From source file:co.runrightfast.core.utils.JmxUtils.java

static ObjectName applicationMBeanObjectName(final String domain, @NonNull final Class<?> mbeanType,
        final String name) {
    checkArgument(isNotBlank(domain));//from w ww  .  ja va  2 s  .  c  om
    checkArgument(isNotBlank(name));
    try {
        @SuppressWarnings("UseOfObsoleteCollectionType")
        final Hashtable<String, String> attributes = new Hashtable<>();
        attributes.put("type", mbeanType.getSimpleName());
        attributes.put("name", name);
        return ObjectName.getInstance(domain, attributes);
    } catch (final MalformedObjectNameException e) {
        throw new RuntimeException(e);
    }
}

From source file:fr.xebia.management.ServletContextAwareMBeanServerFactory.java

public MBeanServer getObject() throws Exception {
    if (instance == null) {
        InvocationHandler invocationHandler = new InvocationHandler() {
            /**//  w  w w  . j  a  va 2  s  .c o m
             * <p>
             * Copy the given <code>objectName</code> adding the extra
             * attributes.
             * </p>
             */
            protected ObjectName addExtraAttributesToObjectName(ObjectName objectName)
                    throws MalformedObjectNameException {
                Hashtable<String, String> table = new Hashtable<String, String>(
                        objectName.getKeyPropertyList());
                table.putAll(objectNameExtraAttributes);

                ObjectName result = ObjectName.getInstance(objectName.getDomain(), table);
                logger.trace("addExtraAttributesToObjectName({}): {}", objectName, result);

                return result;
            }

            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                Object[] modifiedArgs = args.clone();
                for (int i = 0; i < modifiedArgs.length; i++) {
                    Object arg = modifiedArgs[i];
                    if (arg instanceof ObjectName) {
                        ObjectName objectName = (ObjectName) arg;
                        modifiedArgs[i] = addExtraAttributesToObjectName(objectName);
                    }
                }
                if (logger.isDebugEnabled()) {
                    logger.debug(method + " : " + Arrays.asList(modifiedArgs));
                }
                try {
                    return method.invoke(server, modifiedArgs);
                } catch (InvocationTargetException ite) {
                    throw ite.getCause();
                }
            }
        };
        instance = (MBeanServer) Proxy.newProxyInstance(ClassUtils.getDefaultClassLoader(),
                new Class[] { MBeanServer.class }, invocationHandler);

    }
    return instance;
}

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

public void unregisterEndpointService(String name)
        throws MalformedObjectNameException, InstanceNotFoundException, MBeanRegistrationException {
    Hashtable<String, String> properties = new Hashtable<String, String>();
    properties.put("type", "control");
    properties.put("name", "*" + name + "* EndpointService");
    Set<ObjectName> objectNameSet = mBeanServer.queryNames(ObjectName.getInstance(getDomainName(), properties),
            null);/*from w  w w.  j a v a2  s . com*/

    for (ObjectName on : objectNameSet) {
        logger.debug("Unregistering endpoint service with name: " + on);
        mBeanServer.unregisterMBean(on);
        registeredMBeans.remove(on);
    }
}

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

public void unregisterConnectorService(String name)
        throws MalformedObjectNameException, InstanceNotFoundException, MBeanRegistrationException {
    Hashtable<String, String> properties = new Hashtable<String, String>();
    properties.put("type", "control");
    properties.put("name", name + "Service");
    Set<ObjectName> objectNameSet = mBeanServer.queryNames(ObjectName.getInstance(getDomainName(), properties),
            null);/* w ww. j av  a 2  s  .  c o  m*/

    for (ObjectName on : objectNameSet) {
        logger.debug("Unregistering connector service with name: " + on);
        mBeanServer.unregisterMBean(on);
        registeredMBeans.remove(on);
    }
}

From source file:org.apache.activemq.network.BrokerNetworkWithStuckMessagesTest.java

private Object[] browseQueueWithJmx(BrokerService broker) throws Exception {
    Hashtable<String, String> params = new Hashtable<String, String>();
    params.put("brokerName", broker.getBrokerName());
    params.put("type", "Broker");
    params.put("destinationType", "Queue");
    params.put("destinationName", queueName);
    ObjectName queueObjectName = ObjectName.getInstance(amqDomain, params);

    ManagementContext mgmtCtx = broker.getManagementContext();
    QueueViewMBean queueView = (QueueViewMBean) mgmtCtx.newProxyInstance(queueObjectName, QueueViewMBean.class,
            true);/* w w w  .  j  a  va  2  s.  c  o m*/

    Object[] messages = queueView.browse();

    LOG.info("+Browsed with JMX: " + messages.length);

    return messages;
}