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:de.iew.spring.integration.SpringIntegrationJmxTest.java

@After
public void tearDown() throws Exception {
    ObjectName objectName = ObjectName.getInstance(this.jmxTestServiceObjectName);
    this.clientConnector.removeNotificationListener(objectName, this.jmxTestServiceNotificationListener);

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

From source file:org.cloudfoundry.identity.uaa.varz.VarzEndpoint.java

private Map<String, ?> getMBeans(String domain, String pattern) throws Exception {
    Set<ObjectName> names = server.queryNames(ObjectName.getInstance(domain + ":" + pattern), null);

    Map<String, Object> result = new LinkedHashMap<String, Object>();

    for (ObjectName name : names) {

        Map<String, Object> map = new MBeanMap(server, name);

        Map<String, Object> objects = getMap((Map<String, Object>) result, domain);

        String type = name.getKeyProperty("type");
        if (type != null) {
            type = MBeanMap.prettify(type);
            objects = getMap(objects, type);
        }/*from ww  w. j a  v  a2 s  . c om*/

        String key = name.getKeyProperty("name");
        if (key != null) {
            key = MBeanMap.prettify(key);
            objects = getMap(objects, key);
        }

        for (String property : name.getKeyPropertyList().keySet()) {
            if (property.equals("type") || property.equals("name")) {
                continue;
            }
            key = MBeanMap.prettify(property);
            objects = getMap(objects, key);
            String value = name.getKeyProperty(property);
            objects = getMap(objects, value);
        }

        if (key == null) {
            key = type;
        }
        if (key == null) {
            key = domain;
        }
        objects.putAll(map);
    }

    return result;

}

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

private ObjectName createComponentCheckerObjectName(String adapterName) throws MalformedObjectNameException {
    return ObjectName.getInstance(COMPONENT_CHECKER_TYPE + ADAPTER_PREFIX + adapterName + ID_PREFIX
            + AdapterComponentChecker.class.getSimpleName());
}

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

protected void registerStatisticsService() throws NotCompliantMBeanException, MBeanRegistrationException,
        InstanceAlreadyExistsException, MalformedObjectNameException {
    ObjectName on = ObjectName.getInstance(getDomainName() + ":type=statistics");
    StatisticsService mBean = new StatisticsService();
    mBean.setManager(MuleManager.getInstance());
    mBean.setEnabled(isEnableStatistics());
    logger.debug("Registering statistics with name: " + on);
    mBeanServer.registerMBean(mBean, on);
    registeredMBeans.add(on);//  www.  j  av  a  2s.c  o  m
}

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

/**
 * Returns the ObjectName of the Region for the specified path.
 *
 * @throws AdminException If no region with path <code>path</code> exists
 *//*from w  w  w. j  ava 2  s.  c om*/
public ObjectName manageRegion(String path) throws AdminException, MalformedObjectNameException {
    try {
        SystemMemberRegionJmxImpl region = null;

        try {
            region = (SystemMemberRegionJmxImpl) getRegion(path);

        } catch (AdminException e) {
            MBeanUtil.logStackTrace(Level.WARN, e);
            throw e;
        }

        if (region == null) {
            throw new AdminException(
                    LocalizedStrings.SystemMemberCacheJmxImpl_THIS_CACHE_DOES_NOT_CONTAIN_REGION_0
                            .toLocalizedString(path));

        } else {
            return ObjectName.getInstance(region.getMBeanName());
        }
    } catch (RuntimeException e) {
        MBeanUtil.logStackTrace(Level.WARN, e);
        throw e;
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // If this ever returns, rethrow the error. We're poisoned
        // now, so don't let this thread continue.
        throw err;
    } catch (Error e) {
        // Whenever you catch Error or Throwable, you must also
        // catch VirtualMachineError (see above). However, there is
        // _still_ a possibility that you are dealing with a cascading
        // error condition, so you also need to check to see if the JVM
        // is still usable:
        SystemFailure.checkFailure();
        MBeanUtil.logStackTrace(Level.ERROR, e);
        throw e;
    }
}

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

/**
 * Ensures that an MBean is registered for the specified <code>ManagedResource</code>. If an MBean
 * cannot be found in the <code>MBeanServer</code>, then this creates and registers a
 * <code>ModelMBean</code>. State changing callbacks into the <code>ManagedResource</code> will
 * also be made./*from ww  w  .  java 2  s  .  c  o  m*/
 *
 * @param resource the ManagedResource to create a managing MBean for
 *
 * @return The object name of the MBean that manages the ManagedResource
 *
 * @see ManagedResource#setModelMBean
 */
static ObjectName ensureMBeanIsRegistered(ManagedResource resource) {
    try {
        ObjectName objName = ObjectName.getInstance(resource.getMBeanName());
        synchronized (MBeanUtil.class) {
            if (mbeanServer != null && !mbeanServer.isRegistered(objName)) {
                return createMBean(resource);
            }
        }
        raiseOnFailure(mbeanServer.isRegistered(objName),
                LocalizedStrings.MBeanUtil_COULDNT_FIND_MBEAN_REGISTERED_WITH_OBJECTNAME_0
                        .toLocalizedString(new Object[] { objName.toString() }));
        return objName;
    } catch (java.lang.Exception e) {
        throw new RuntimeAdminException(e);
    }
}

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

protected void registerModelService() throws NotCompliantMBeanException, MBeanRegistrationException,
        InstanceAlreadyExistsException, MalformedObjectNameException {
    ObjectName on = ObjectName.getInstance(getDomainName() + ":type=control,name=ModelService");
    ModelServiceMBean serviceMBean = new ModelService();
    logger.debug("Registering model with name: " + on);
    mBeanServer.registerMBean(serviceMBean, on);
    registeredMBeans.add(on);//from w  ww .j a v a2 s.  c  o  m
}

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

protected void registerMuleService() throws NotCompliantMBeanException, MBeanRegistrationException,
        InstanceAlreadyExistsException, MalformedObjectNameException {
    ObjectName on = ObjectName.getInstance(getDomainName() + ":type=control,name=MuleService");
    MuleServiceMBean serviceMBean = new MuleService();
    logger.debug("Registering mule with name: " + on);
    mBeanServer.registerMBean(serviceMBean, on);
    registeredMBeans.add(on);/* w  ww  . j av  a 2  s  .co m*/
}

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

private void checkDependencies(String value, Property property) {
    try {//w  ww . j  a  v a 2s  . c  o  m
        ObjectName name = ObjectName.getInstance(value);
    } catch (MalformedObjectNameException e) {
        LOG.error("Dependency to " + value
                + " does not exist or is not deployed. because of this dependency this Topic/Queue will not deploy either.");
        property.setErrorMessage(value + " is not a valid value.");
        if (updateReport != null) {
            updateReport.setStatus(ConfigurationUpdateStatus.FAILURE);
        }

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

From source file:org.blue.star.plugins.check_jmx.java

public boolean execute_check() {
    /* Our Jboss Specific Properties */
    p = new Properties();
    p.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    p.put(InitialContext.PROVIDER_URL, "jnp://" + hostname + ":" + port);
    p.put(InitialContext.URL_PKG_PREFIXES, "org.jboss.naming.interfaces");

    /* Attempt our connection */
    try {//from w w w .  j  a v a  2  s .c om
        server = (MBeanServerConnection) new InitialContext(p).lookup(jndiAdaptorName);
    } catch (NamingException e) {
        checkMessage = "Critical - Unable to connect to MBean Server at jnp://" + hostname + ":" + port;
        checkState = common_h.STATE_CRITICAL;
        return false;
    }

    /* Has the user specified a bean to check ? */
    if (mbeanName != null) {
        try {
            objectName = ObjectName.getInstance(mbeanName);
        } catch (MalformedObjectNameException e) {
            checkMessage = "Critical - Malformed Object name for MBean instance";
            checkState = common_h.STATE_CRITICAL;
            return false;
        }

        /* Are we testing a specific attribute of that bean */
        if (attribute != null) {
            try {
                Object o = server.getAttribute(objectName, attribute);

                /* Check for expected value? */
                if (expectString != null)
                    if (!expectString.equals(o.toString())) {
                        checkMessage = "Warning - Value of Attribute does not match expected value.";
                        checkState = common_h.STATE_WARNING;
                        return false;
                    }

                /* Are we comparing the value to warn/crit thresholds */
                if (compareThresholds)
                    if (!compareThresholds(o.toString()))
                        return false;
            } catch (InstanceNotFoundException e) {
                checkMessage = "Critical - No Instance of MBean " + mbeanName + " found on MBean Server";
                checkState = common_h.STATE_CRITICAL;
                return false;
            } catch (AttributeNotFoundException e) {
                checkMessage = "Critical - Attribute " + attribute + " not found for MBean " + mbeanName;
                checkState = common_h.STATE_CRITICAL;
                return false;
            } catch (Exception e) {
                checkMessage = "Critical - Error retrieving Attribute value of " + attribute + " for Mbean "
                        + mbeanName;
                checkState = common_h.STATE_CRITICAL;
                return false;
            }
        }

    }

    /* Check to see if the specified domain exists */
    if (domain != null)
        if (!checkDomains())
            return false;

    /* Perform MBean count checks */
    if (count > -1)
        if (!checkCount())
            return false;

    /* Mbean checking takes precedence in our reporting */
    if (mbeanName != null) {
        checkMessage = "OK - MBean " + mbeanName + " alive on MBean Server jnp://" + hostname + ":" + port;
        checkState = common_h.STATE_OK;
    }

    return true;
}