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.apache.geode.management.internal.web.controllers.ShellCommandsController.java

@RequestMapping(method = RequestMethod.POST, value = "/mbean/operation")
public ResponseEntity<?> invoke(@RequestParam("resourceName") final String resourceName,
        @RequestParam("operationName") final String operationName,
        @RequestParam(value = "signature", required = false) String[] signature,
        @RequestParam(value = "parameters", required = false) Object[] parameters)
        throws MalformedObjectNameException, MBeanException, InstanceNotFoundException, ReflectionException,
        IOException {//from w w w.ja  v  a2 s.c  o  m
    // Exceptions are caught by the @ExceptionHandler AbstractCommandsController.handleAppException
    signature = (signature != null ? signature : ArrayUtils.EMPTY_STRING_ARRAY);
    parameters = (parameters != null ? parameters : ObjectUtils.EMPTY_OBJECT_ARRAY);
    MBeanServer mBeanServer = getMBeanServer();
    ObjectName objectName = ObjectName.getInstance(decode(resourceName));
    final Object result = mBeanServer.invoke(objectName, decode(operationName), parameters, signature);
    byte[] serializedResult = IOUtils.serializeObject(result);
    return new ResponseEntity<>(serializedResult, HttpStatus.OK);
}

From source file:flens.query.JMXQuery.java

@SuppressWarnings("unchecked")
private void call(Query q, String[] rest) throws MalformedObjectNameException, NullPointerException,
        IOException, InstanceNotFoundException, MBeanException, ReflectionException {
    String name = rest[0];//from   www.j ava 2  s  .  c o  m
    String oppname = rest[1];

    Set<ObjectName> names = new TreeSet<ObjectName>(connection.queryNames(ObjectName.getInstance(name), null));

    Map<String, Object> out = new HashMap<>();

    for (ObjectName objectName : names) {
        List<Object> o = (List<Object>) q.getPayload().get("params");
        List<String> sig = (List<String>) q.getPayload().get("sig");
        out.put(objectName.getCanonicalName(),
                connection.invoke(objectName, oppname, o.toArray(), sig.toArray(new String[sig.size()])));
    }

    q.respond(out);

}

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

private static void unregisterDatasourceFromJmx(BasicDataSource dataSource) {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {/*  w ww . j  av  a  2s  . co m*/
        mbs.unregisterMBean(ObjectName.getInstance(dataSource.getJmxName()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:flens.query.JMXQuery.java

private void details(Query q, String[] rest) throws MalformedObjectNameException, NullPointerException,
        IOException, InstanceNotFoundException, IntrospectionException, ReflectionException {
    String name = rest[0];//from   ww w  . j  a  v  a  2s  . c om

    Set<ObjectName> names = new TreeSet<ObjectName>(connection.queryNames(ObjectName.getInstance(name), null));

    Map<String, Object> out = new HashMap<>();

    for (ObjectName objectName : names) {
        out.put(objectName.getCanonicalName(), getDetails(objectName));
    }

    q.respond(out);

}

From source file:org.springframework.integration.dsl.test.ftp.FtpTests.java

@Test
public void testMBeansForDSL() throws MalformedObjectNameException {
    assertFalse(this.mBeanServer.queryMBeans(ObjectName.getInstance(
            "org.springframework.integration:" + "type=MessageHandler,name=ftpMGetFlow.input,bean=anonymous"),
            null).isEmpty());/*w ww.  j av  a  2 s  .com*/
}

From source file:org.rhq.plugins.jbossas.util.AbstractMessagingConfigurationEditor.java

protected void bindSimplePropertiesToConfiguration(String[] properties, String elementName,
        String attributeName, Element componentElement) {
    for (String simpleAttribute : properties) {
        PropertySimple property = config.getSimple(simpleAttribute);
        if (property != null) {
            String value = property.getStringValue();
            if (value != null) {
                if (elementName.equals(DEPENDS)) {
                    try {
                        ObjectName.getInstance(value);
                    } catch (MalformedObjectNameException e) {
                        LOG.error("Dependency to " + value
                                + " does not exist or is not deployed. Because of this invalid dependency, this Topic/Queue will not be deployed.");
                        property.setErrorMessage("'" + value + "' is not a valid JMX object name.");
                        if (updateReport != null) {
                            updateReport.setStatus(ConfigurationUpdateStatus.FAILURE);
                        }//w  w w .  j av  a2 s  . c  o  m

                        if (createReport != null) {
                            createReport.setStatus(CreateResourceStatus.FAILURE);
                        }
                    }
                }

                Element element = new Element(elementName);
                Attribute attribute = new Attribute(attributeName, simpleAttribute);
                element.setAttribute(attribute);
                element.setText(value);
                componentElement.addContent(element);
            }
        }
    }
}

From source file:flens.query.JMXQuery.java

private void get(Query q, String[] rest)
        throws MalformedObjectNameException, NullPointerException, IOException, InstanceNotFoundException,
        IntrospectionException, ReflectionException, AttributeNotFoundException, MBeanException {
    String name = rest[0];//  w  w w  .j a  v a  2 s.  co m
    String att = rest[1];

    Set<ObjectName> names = new TreeSet<ObjectName>(connection.queryNames(ObjectName.getInstance(name), null));

    Map<String, Object> out = new HashMap<>();

    for (ObjectName objectName : names) {
        out.put(objectName.getCanonicalName(), connection.getAttribute(objectName, att));
    }

    q.respond(out);

}

From source file:de.iew.spring.integration.SpringIntegrationJmxTest.java

@Before
public void setUp() throws Exception {
    ObjectName objectName = ObjectName.getInstance(this.jmxTestServiceObjectName);
    this.clientConnector.addNotificationListener(objectName, this.jmxTestServiceNotificationListener, null,
            null);/*  w  w w.  j a  v a 2  s .c  om*/

    objectName = ObjectName.getInstance(this.springIntegrationTestObjectName);
    this.clientConnector.addNotificationListener(objectName, this.springIntegrationTestNotificationListener,
            null, null);
}

From source file:org.apache.geode.admin.jmx.internal.MBeanUtil.java

/**
 * Creates and registers a <code>ModelMBean</code> for the specified <code>ManagedResource</code>.
 * State changing callbacks into the <code>ManagedResource</code> will also be made.
 *
 * @param resource the ManagedResource to create a managing MBean for
 * @param managed the ManagedBean definition to create the MBean with
 * @see ManagedResource#setModelMBean/*from w w w. j  a v a2 s . c  om*/
 */
static ObjectName createMBean(ManagedResource resource, ManagedBean managed) {

    try {
        DynamicManagedBean mb = new DynamicManagedBean(managed);
        resource.setModelMBean(mb.createMBean(resource));

        // create the ObjectName and register the MBean...
        final ObjectName objName;
        try {
            objName = ObjectName.getInstance(resource.getMBeanName());
        } catch (MalformedObjectNameException e) {
            throw new MalformedObjectNameException(LocalizedStrings.MBeanUtil_0_IN_1
                    .toLocalizedString(new Object[] { e.getMessage(), resource.getMBeanName() }));
        }

        synchronized (MBeanUtil.class) {
            // Only register a bean once. Otherwise, you risk race
            // conditions with things like the RMI connector accessing it.

            if (mbeanServer != null && !mbeanServer.isRegistered(objName)) {
                mbeanServer.registerMBean(resource.getModelMBean(), objName);
                synchronized (managedResources) {
                    managedResources.put(objName, resource);
                }
            }
        }
        return objName;
    } catch (java.lang.Exception e) {
        throw new RuntimeAdminException(LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_MBEAN_FOR_0
                .toLocalizedString(new Object[] { resource.getMBeanName() }), e);
    }
}

From source file:fr.xebia.management.maven.WebApplicationMavenInformation.java

public void setObjectName(String objectName) throws MalformedObjectNameException {
    if (objectName == null) {
        this.objectName = null;
    } else {/*from www  .j a v  a  2 s.c  o  m*/
        this.objectName = ObjectName.getInstance(objectName);
    }
}