Example usage for javax.management ObjectName getCanonicalName

List of usage examples for javax.management ObjectName getCanonicalName

Introduction

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

Prototype

public String getCanonicalName() 

Source Link

Document

Returns the canonical form of the name; that is, a string representation where the properties are sorted in lexical order.

More precisely, the canonical form of the name is a String consisting of the domain part, a colon (:), the canonical key property list, and a pattern indication.

The canonical key property list is the same string as described for #getCanonicalKeyPropertyListString() .

The pattern indication is:

  • empty for an ObjectName that is not a property list pattern;
  • an asterisk for an ObjectName that is a property list pattern with no keys; or
  • a comma and an asterisk (,*) for an ObjectName that is a property list pattern with at least one key.

    Usage

    From source file:org.wso2.carbon.utils.MBeanRegistrar.java

    public static void unregisterAllMBeans() {
        MBeanServer mbs = ManagementFactory.getMBeanServer();
        for (ObjectName name : mbeans) {
            try {//ww  w  .  jav a2  s. com
                mbs.unregisterMBean(name);
            } catch (Exception e) {
                log.error("Cannot unregister MBean " + name.getCanonicalName());
            }
        }
    }
    

    From source file:org.apache.uima.examples.as.GetMetaRequest.java

    /**
     * Creates a connection to an MBean Server identified by
     * <code>remoteJMXServerHostName and remoteJMXServerPort</code>
     * /*from  w  w  w  .  j  a va2  s .c o  m*/
     * @param remoteJMXServerHostName
     *          - MBeanServer host name
     * @param remoteJMXServerPort
     *          - MBeanServer port
     * @return - none
     * 
     * @throws Exception
     */
    private static void initialize(String jmxDomain, String remoteJMXServerHostname, String remoteJMXServerPort)
            throws Exception {
        // Construct connect string to the JMX MBeanServer
        String remoteJmxUrl = "service:jmx:rmi:///jndi/rmi://" + remoteJMXServerHostname + ":" + remoteJMXServerPort
                + "/jmxrmi";
    
        try {
            JMXServiceURL url = new JMXServiceURL(remoteJmxUrl);
            jmxc = JMXConnectorFactory.connect(url, null);
            brokerMBeanServer = jmxc.getMBeanServerConnection();
            // Its possible that the above code succeeds even though the broker runs
            // with no JMX Connector. At least on windows the above does not throw an
            // exception as expected. It appears that the broker registers self JVMs MBeanServer
            // but it does *not* register any Connections, nor Queues. The code below 
            // checks if the MBean server we are connected to has any QueueMBeans registered.
            // A broker with jmx connector should have queue mbeans registered and thus
            //  the code below should always succeed. Conversely, a broker with no jmx connector
            // reports no queue mbeans.
    
            //  Query broker MBeanServer for QueueMBeans
            Set queueSet = brokerMBeanServer.queryNames(new ObjectName(jmxDomain + ":*,Type=Queue"),
                    (QueryExp) null);
            if (queueSet.isEmpty()) { //  No QueueMBeans, meaning no JMX support
                throw new JmxException("ActiveMQ Broker Not Configured With JMX Support");
            }
        } catch (Exception e) {
            return;
        }
        // Query JMX Server for Broker MBean. We need the broker's name from an MBean to construct
        // queue query string.
    
        for (Object nameObject : brokerMBeanServer.queryNames(new ObjectName(jmxDomain + ":*,Type=Broker"),
                (QueryExp) null)) {
            ObjectName brokerObjectName = (ObjectName) nameObject;
            if (brokerObjectName.getCanonicalName().endsWith("Type=Broker")) {
                // Extract just the name from the canonical name
                brokerName = brokerObjectName.getCanonicalName().substring(0,
                        brokerObjectName.getCanonicalName().indexOf(","));
                initialized = true;
                break; // got the broker name
            }
        }
    }
    

    From source file:Utilities.java

    /**
     * Prints bean attributes to a {@link VarOutputSink}.
     * //from   w w w .jav  a2 s. c om
     * @param sink The {@link VarOutputSink} to which attributes will be sent
     * @param mbs The {@link MBeanServer} with respect to which the
     *          {@code objectName} is accessed
     * @param objectName The {@link ObjectName} that identifies this bean
     */
    public static void printMBeanAttributes(VarOutputSink sink, MBeanServer mbs, ObjectName objectName) {
        MBeanInfo info = getMBeanInfoSafely(sink, mbs, objectName);
        if (info == null) {
            sink.printVariable(objectName.getCanonicalName(), "can't fetch info");
            return;
        }
        MBeanAttributeInfo[] attrInfo = info.getAttributes();
        if (attrInfo.length > 0) {
            for (int i = 0; i < attrInfo.length; i++) {
                String attrName = attrInfo[i].getName();
                Object attrValue = null;
                String attrValueString = null;
                try {
                    attrValue = mbs.getAttribute(objectName, attrName);
                } catch (AttributeNotFoundException e) {
                    attrValueString = "AttributeNotFoundException";
                } catch (InstanceNotFoundException e) {
                    attrValueString = "InstanceNotFoundException";
                } catch (MBeanException e) {
                    attrValueString = "MBeanException";
                } catch (ReflectionException e) {
                    attrValueString = "ReflectionException";
                }
                if (attrValueString == null) {
                    attrValueString = attrValue.toString();
                }
                sink.printVariable(attrName, attrValueString);
            }
        }
    }
    

    From source file:com.brienwheeler.lib.jmx.MBeanRegistrationSupport.java

    public static void registerMBean(Object mbean) {
        try {//from w  w w .  j a  va 2 s.  c  o m
            ObjectNamingStrategy namingStrategy = new IdentityNamingStrategy();
            ObjectName objectName = namingStrategy.getObjectName(mbean, null);
    
            MBeanRegistrationSupport registrar = new MBeanRegistrationSupport();
            registrar.setServer(JmxUtils.locateMBeanServer());
    
            // if item qualifies as MBean, export it directly
            if (JmxUtils.isMBean(mbean.getClass())) {
                registrar.doRegister(mbean, objectName);
                return;
            }
    
            // assemble MBean info (from annotations by default)
            ModelMBean modelMBean = new RequiredModelMBean();
            modelMBean.setManagedResource(mbean, MR_TYPE_OBJECT_REFERENCE);
            MBeanInfoAssembler mBeanInfoAssembler = new MetadataMBeanInfoAssembler(
                    new AnnotationJmxAttributeSource());
            modelMBean.setModelMBeanInfo(mBeanInfoAssembler.getMBeanInfo(mbean, objectName.getCanonicalName()));
            registrar.doRegister(modelMBean, objectName);
        } catch (Exception e) {
            throw new JmxRegisterException("error registering MBean", e);
        }
    }
    

    From source file:org.atomserver.utils.jmx.HttpAdaptorMgr.java

    public void mbeanUnregistered(ObjectName objectName) {
        if (adaptorName.equals(objectName.getCanonicalName())) {
            stop(objectName);// w w w . j  ava 2 s  .c  o m
        }
    }
    

    From source file:org.atomserver.utils.jmx.HttpAdaptorMgr.java

    /** When the specific MBean named "adapterName"
     *   is registered, it triggers a "start" for our MX4J HttpAdapter
     *//*from  w  ww . ja  v  a  2s. c om*/
    public void mbeanRegistered(ObjectName objectName) {
        if (adaptorName.equals(objectName.getCanonicalName())) {
            start(objectName);
        }
    }
    

    From source file:org.vbossica.springbox.jmx.MetadataNamingOverridingStrategy.java

    @Override
    public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
        ObjectName objectName = super.getObjectName(managedBean, beanKey);
        String finalName = resolver.resolve(objectName.getCanonicalName());
    
        if (finalName != null && StringUtils.hasText(finalName)) {
            logger.info("replacing " + objectName + " by " + finalName);
            return ObjectNameManager.getInstance(finalName);
        }//from  w  w w .  j  a  v  a2 s .  c  o  m
        return objectName;
    }
    

    From source file:fr.xebia.springframework.jmx.ServletContextAwareObjectNamingStrategy.java

    /**
     * <p>//from  w w w  . ja  v a2 s .c om
     * Compose <code>ObjectName</code> with underlying <code>objectNamingStrategy</code>'s
     * result and the following parameters: "<code>application=${servletcontextName},bean=${beanKey}</code>".
     * </p>
     */
    public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
        ObjectName objectName = this.objectNamingStrategy.getObjectName(managedBean, beanKey);
        String canonicalName = objectName.getCanonicalName();
        canonicalName += ",application=" + ObjectName.quote(this.servletContextName) + ",bean="
                + ObjectName.quote(beanKey);
        ObjectName result = ObjectName.getInstance(canonicalName);
        return result;
    }
    

    From source file:org.jolokia.request.JmxRequestBuilder.java

    public JmxRequestBuilder(RequestType pType, ObjectName pMBean) throws MalformedObjectNameException {
        this(pType, pMBean.getCanonicalName());
    }
    

    From source file:com.goSmarter.gemfire.claimcheckpattern.CustomMetadataNamingStrategy.java

    @Override
    public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
        ObjectName objectName = super.getObjectName(managedBean, beanKey);
    
        if (this.staticNameParts.length() == 0) {
            return objectName;
        }//from  w w w.  ja  va 2s .  co  m
        return new ObjectName(objectName.getCanonicalName() + this.staticNameParts);
    }