Example usage for javax.management ObjectName getDomain

List of usage examples for javax.management ObjectName getDomain

Introduction

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

Prototype

public String getDomain() 

Source Link

Document

Returns the domain part.

Usage

From source file:org.apache.geode.management.internal.security.MBeanServerWrapper.java

private void checkDomain(ObjectName name) {
    if (ManagementConstants.OBJECTNAME__DEFAULTDOMAIN.equals(name.getDomain()))
        throw new SecurityException(ResourceConstants.ACCESS_DENIED_MESSAGE);
}

From source file:org.hyperic.hq.product.jmx.ServiceTypeFactory.java

private String getObjectNameProperty(ObjectName objectName) {
    final StringBuffer objectNameProperty = new StringBuffer(objectName.getDomain()).append(':');
    Hashtable keyProperties = objectName.getKeyPropertyList();
    for (Iterator iterator = keyProperties.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry keyProperty = (Map.Entry) iterator.next();
        objectNameProperty.append(keyProperty.getKey()).append('=');
        // for now, recognize only type and subtype - replace all others
        // with variable placeholders
        if ("type".equals(keyProperty.getKey()) || "subtype".equals(keyProperty.getKey())) {
            objectNameProperty.append(keyProperty.getValue());
        } else {/*  w  w  w .ja va2s.c o m*/
            objectNameProperty.append('%').append(keyProperty.getKey()).append('%');
        }
        objectNameProperty.append(',');
    }
    objectNameProperty.deleteCharAt(objectNameProperty.length() - 1);
    return objectNameProperty.toString();
}

From source file:org.wso2.carbon.analytics.common.jmx.agent.JmxAgentWebInterface.java

/**
 * @param url      : The URL for the JMX server
 * @param userName : The User name for the JMX server
 * @param password : The password for the JMX server
 * @return : The name array of the MBeans which the JMX server. The format of the array is
 *         [Domain name][MBean Canonical name]
 * @throws IOException/*from w ww.  ja  va2 s . co  m*/
 */
public String[][] getMBeans(String url, String userName, String password) throws IOException {

    JMXConnector jmxc = null;

    try {
        jmxc = getJmxConnector(url, userName, password);

        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

        int count = 0;
        Set<ObjectName> names = new TreeSet<ObjectName>(mbsc.queryNames(null, null));
        String[][] nameArr = new String[names.size()][2];

        for (ObjectName name : names) {
            nameArr[count][0] = name.getDomain();
            nameArr[count][1] = name.getCanonicalName();
            count++;
        }

        return nameArr;

    } catch (MalformedURLException e) {
        log.error(e);
        throw e;
    } catch (IOException e) {
        log.error(e);
        throw e;
    } finally {
        if (jmxc != null) {
            jmxc.close();
        }
    }
}

From source file:com.mtgi.jmx.export.naming.AppendNamingStrategy.java

public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
    ObjectName base = delegate.getObjectName(managedBean, beanKey);

    @SuppressWarnings("unchecked")
    HashMap<String, String> properties = new HashMap<String, String>(base.getKeyPropertyList());
    //change the domain if required
    String domain = this.domain;
    if (domain == null)
        domain = base.getDomain();
    else {//from www  .j  a  va  2 s. c  o m
        String oldDomain = base.getDomain();
        if (oldDomain != null) {
            //append the prior domain name onto the package property.
            String pkg = properties.get("package");
            pkg = (pkg == null) ? oldDomain : pkg + "." + oldDomain;
            properties.put("package", pkg);
        }
    }

    //append extra key if required
    if (key != null && value != null) {
        //append the extra key to the object name
        String oldValue = properties.remove(key);
        properties.put(key, value);

        //move the displaced prior value to a different property
        if (oldValue != null && renameKey != null) {
            String prefix = properties.remove(renameKey);
            if (prefix != null)
                oldValue = prefix + "." + oldValue;
            properties.put(renameKey, oldValue);
        }
    }

    StringBuffer buf = new StringBuffer();
    buf.append(quote(domain));
    char sep = ':';
    //enforce a canonical order on all specified properties
    for (String prop : PROPERTY_ORDER) {
        String value = properties.remove(prop);
        if (value != null) {
            buf.append(sep).append(prop).append('=').append(quote(value));
            sep = ',';
        }
    }
    //all remaining properties get appended in unspecified order
    for (Iterator<Map.Entry<String, String>> it = properties.entrySet().iterator(); it.hasNext();) {
        Map.Entry<String, String> prop = it.next();
        it.remove();
        buf.append(sep).append(prop.getKey()).append('=').append(quote(prop.getValue()));
        sep = ',';
    }

    return ObjectName.getInstance(buf.toString());
}

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

@RequestMapping("/domains")
@ResponseBody/*from   w  w w .java 2  s  . co  m*/
public Set<String> getMBeanDomains() throws IOException {
    Set<String> result = new HashSet<String>();
    Set<ObjectName> names = server.queryNames(null, null);
    for (ObjectName name : names) {
        result.add(name.getDomain());
    }
    return result;
}

From source file:org.jolokia.handler.list.MBeanInfoData.java

/**
 * Add information about an MBean as obtained from an {@link MBeanInfo} descriptor. The information added
 * can be restricted by a given path (which has already be prepared as a stack). Also, a max depth as given in the
 * constructor restricts the size of the map from the top.
 *
 * @param mBeanInfo the MBean info//from  w w w .j  a  v a 2  s  .c  om
 * @param pName the object name of the MBean
 */
public void addMBeanInfo(MBeanInfo mBeanInfo, ObjectName pName)
        throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {

    JSONObject mBeansMap = getOrCreateJSONObject(infoMap, pName.getDomain());
    JSONObject mBeanMap = getOrCreateJSONObject(mBeansMap, getKeyPropertyString(pName));
    // Trim down stack to get rid of domain/property list
    Stack<String> stack = truncatePathStack(2);
    if (stack.empty()) {
        addFullMBeanInfo(mBeanMap, mBeanInfo);
    } else {
        addPartialMBeanInfo(mBeanMap, mBeanInfo, stack);
    }
    // Trim if required
    if (mBeanMap.size() == 0) {
        mBeansMap.remove(getKeyPropertyString(pName));
        if (mBeansMap.size() == 0) {
            infoMap.remove(pName.getDomain());
        }
    }
}

From source file:org.jolokia.handler.list.MBeanInfoData.java

/**
 * The first two levels of this map (tree) consist of the MBean's domain name and name properties, which are
 * independent of an MBean's meta data. If the max depth given at construction time is less or equals than 2 (and
 * no inner path into the map is given), then a client of this map does not need to query the MBeanServer for
 * MBeanInfo meta data./*  w  ww.j a  v  a  2s .c  om*/
 * <p></p>
 * This method checks this condition and returns true if this is the case. As side effect it will update this
 * map with the name part extracted from the given object name
 *
 * @param pName the objectname used for the first two levels
 * @return true if the object name has been added.
 */
public boolean handleFirstOrSecondLevel(ObjectName pName) {
    if (maxDepth == 1 && pathStack.size() == 0) {
        // Only add domain names with a dummy value if max depth is restricted to 1
        // But only when used without path
        infoMap.put(pName.getDomain(), 1);
        return true;
    } else if (maxDepth == 2 && pathStack.size() == 0) {
        // Add domain an object name into the map, final value is a dummy value
        JSONObject mBeansMap = getOrCreateJSONObject(infoMap, pName.getDomain());
        mBeansMap.put(getKeyPropertyString(pName), 1);
        return true;
    }
    return false;
}

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

public MBeanServer getObject() throws Exception {
    if (instance == null) {
        InvocationHandler invocationHandler = new InvocationHandler() {
            /**/*from  ww w. j av a 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:com.heliosapm.tsdblite.metric.MetricCache.java

/**
 * Registers a new meta-source ObjectName
 * @param meta The meta ObjectName/*from w  w  w  .ja  v a2  s . c o m*/
 * @param name The meta key
 * @param value The meta value
 */
public void submit(final ObjectName meta, final String name, final String value) {
    if (meta != null) {
        final long hashCode = hashCode(meta.getDomain(), meta.getKeyPropertyList());
        MetricMeta m = metas.putIfAbsent(hashCode, MetricMeta.PLACEHOLDER);
        if (m == null) {
            m = new MetricMeta(hashCode, name, value);
            JMXHelper.registerMBean(metricMBeanServer, meta, m);
            metas.replace(hashCode, m);
        } else {
            m.addPair(name, value);
        }
    }
}

From source file:org.apache.catalina.core.StandardEngine.java

public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
    super.preRegister(server, name);

    this.setName(name.getDomain());

    return name;//from  w  w w . j av a  2  s .co  m
}