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.jk.core.JkHandler.java

public ObjectName preRegister(MBeanServer server, ObjectName oname) throws Exception {
    this.oname = oname;
    mserver = server;//  ww w .  j  a v a  2s .c  o m
    domain = oname.getDomain();
    if (name == null) {
        name = oname.getKeyProperty("name");
    }

    // we need to create a workerEnv or set one.
    ObjectName wEnvName = new ObjectName(domain + ":type=JkWorkerEnv");
    if (wEnv == null) {
        wEnv = new WorkerEnv();
    }
    if (!mserver.isRegistered(wEnvName)) {
        Registry.getRegistry().registerComponent(wEnv, wEnvName, null);
    }
    mserver.invoke(wEnvName, "addHandler", new Object[] { name, this },
            new String[] { "java.lang.String", "org.apache.jk.core.JkHandler" });
    return oname;
}

From source file:org.jumpmind.symmetric.JmxCommand.java

@Override
protected boolean executeWithOptions(final CommandLine line) throws Exception {
    if (line.hasOption(OPTION_LISTBEANS)) {
        execute(new IJmxTemplate<Object>() {
            @Override// w  w  w. java  2  s  .  co m
            public Object execute(String engineName, MBeanServerConnection mbeanConn) throws Exception {
                Set<ObjectName> beanSet = mbeanConn.queryNames(null, null);
                for (ObjectName objectName : beanSet) {
                    if (objectName.getDomain().startsWith("org.jumpmind.symmetric." + engineName)) {
                        System.out.println(objectName.toString());
                    }
                }
                return null;
            }
        });
    } else if (line.hasOption(OPTION_LISTMETHODS) || line.hasOption(OPTION_METHOD)) {
        if (line.hasOption(OPTION_BEAN)) {

            execute(new IJmxTemplate<Object>() {
                @Override
                public Object execute(String engineName, MBeanServerConnection mbeanConn) throws Exception {
                    String beanName = line.getOptionValue(OPTION_BEAN);
                    MBeanInfo info = mbeanConn.getMBeanInfo(new ObjectName(beanName));
                    if (info != null) {
                        if (line.hasOption(OPTION_LISTMETHODS)) {
                            MBeanOperationInfo[] operations = info.getOperations();
                            Map<String, MBeanOperationInfo> orderedMap = new TreeMap<String, MBeanOperationInfo>();
                            for (MBeanOperationInfo methodInfo : operations) {
                                orderedMap.put(methodInfo.getName(), methodInfo);
                            }
                            for (MBeanOperationInfo methodInfo : orderedMap.values()) {
                                System.out.print(methodInfo.getName() + "(");
                                MBeanParameterInfo[] params = methodInfo.getSignature();
                                int index = 0;
                                for (MBeanParameterInfo p : params) {
                                    if (index > 0) {
                                        System.out.print(", ");
                                    }
                                    System.out.print(p.getType() + " " + p.getName());
                                    index++;
                                }
                                System.out.print(")");
                                if (methodInfo.getReturnType() != null
                                        && !methodInfo.getReturnType().equals("void")) {
                                    System.out.print(" : " + methodInfo.getReturnType());
                                }
                                System.out.println();
                            }
                        } else if (line.hasOption(OPTION_METHOD)) {
                            String argsDelimiter = line.getOptionValue(OPTION_ARGS_DELIM);
                            if (isBlank(argsDelimiter)) {
                                argsDelimiter = ",";
                            } else {
                                argsDelimiter = argsDelimiter.trim();
                            }
                            String methodName = line.getOptionValue(OPTION_METHOD);
                            String[] args = null;
                            if (line.hasOption(OPTION_ARGS)) {
                                String argLine = line.getOptionValue(OPTION_ARGS);
                                args = argsDelimiter == "," ? CsvUtils.tokenizeCsvData(argLine)
                                        : argLine.split(argsDelimiter);
                                ;
                            } else {
                                args = new String[0];
                            }

                            MBeanOperationInfo[] operations = info.getOperations();
                            for (MBeanOperationInfo methodInfo : operations) {
                                MBeanParameterInfo[] paramInfos = methodInfo.getSignature();
                                if (methodInfo.getName().equals(methodName)
                                        && paramInfos.length == args.length) {
                                    String[] signature = new String[args.length];
                                    Object[] objArgs = new Object[args.length];
                                    int index = 0;
                                    for (MBeanParameterInfo paramInfo : paramInfos) {
                                        signature[index] = paramInfo.getType();
                                        if (!paramInfo.getType().equals(String.class.getName())) {
                                            Class<?> clazz = Class.forName(paramInfo.getType());
                                            Constructor<?> constructor = clazz.getConstructor(String.class);
                                            objArgs[index] = constructor.newInstance(args[index]);
                                        } else {
                                            objArgs[index] = args[index];
                                        }
                                        index++;
                                    }
                                    Object returnValue = mbeanConn.invoke(new ObjectName(beanName), methodName,
                                            objArgs, signature);
                                    if (methodInfo.getReturnType() != null
                                            && !methodInfo.getReturnType().equals("void")) {
                                        System.out.println(returnValue);
                                    }
                                    System.exit(0);
                                }
                            }

                            System.out.println("ERROR: Could not locate a JMX method named: " + methodName
                                    + " with " + args.length + " arguments on bean: " + beanName);
                            System.exit(1);

                            return null;

                        }
                    } else {
                        System.out.println("ERROR: Could not locate a JMX bean with the name of: " + beanName);
                        System.exit(1);
                    }
                    return null;
                }
            });
        } else {
            System.out.println("ERROR: Must specifiy the --bean option.");
            System.exit(1);
        }
    } else {
        return false;
    }

    return true;
}

From source file:com.sun.grizzly.http.jk.core.JkHandler.java

public ObjectName preRegister(MBeanServer server, ObjectName oname) throws Exception {
    this.oname = oname;
    mserver = server;//  w w w.  j a v  a2  s. c  o  m
    domain = oname.getDomain();
    if (name == null) {
        name = oname.getKeyProperty("name");
    }

    // we need to create a workerEnv or set one.
    ObjectName wEnvName = new ObjectName(domain + ":type=JkWorkerEnv");
    if (wEnv == null) {
        wEnv = new WorkerEnv();
    }
    if (!mserver.isRegistered(wEnvName)) {
        Registry.getRegistry(null, null).registerComponent(wEnv, wEnvName, null);
    }
    mserver.invoke(wEnvName, "addHandler", new Object[] { name, this },
            new String[] { "java.lang.String", "com.sun.grizzly.http.jk.core.JkHandler" });
    return oname;
}

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

@RequestMapping("/varz/domains")
@ResponseBody//w w w. j av  a2  s.  c  o  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.hyperic.hq.plugin.weblogic.jmx.WeblogicDiscover.java

private void discoverInit(MBeanServer mServer) throws Exception {

    // only exists on the admin server
    final String scope = "*:Type=ApplicationConfig,*";

    for (Iterator it = mServer.queryNames(new ObjectName(scope), null).iterator(); it.hasNext();) {
        ObjectName oName = (ObjectName) it.next();
        if (this.domain == null) {
            this.domain = oName.getDomain();
        }//from  www  . ja  v  a2  s.c o m
        if (this.adminName == null) {
            this.adminName = oName.getKeyProperty("Location");
        }

        String name = oName.getKeyProperty("Name");

        // special case for console so we can control it
        if (name.equals("console")) {
            continue;
        }

        boolean isInternal = ((Boolean) mServer.getAttribute(oName, "InternalApp")).booleanValue();

        if (isInternal) {
            this.internalApps.put(name, Boolean.TRUE);
        }
    }
}

From source file:org.apache.synapse.commons.snmp.SNMPAgent.java

@Override
protected void registerManagedObjects() {
    log.info("Initializing Synapse SNMP MIB");
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectInstance> instances = mbs.queryMBeans(null, null);

    try {// w w  w .j a v a  2 s  .  com
        for (ObjectInstance instance : instances) {
            ObjectName objectName = instance.getObjectName();
            if (objectName.getDomain().equals("org.apache.synapse")) {
                String oidString = SynapseMIBUtils.getOID(objectName);
                if (oidString == null) {
                    continue;
                }

                MBeanInfo info = mbs.getMBeanInfo(objectName);
                MBeanAttributeInfo[] attributes = info.getAttributes();
                List<String> attributeNames = new ArrayList<String>();
                List<String> mapAttributes = new ArrayList<String>();
                for (MBeanAttributeInfo attributeInfo : attributes) {
                    attributeNames.add(attributeInfo.getName());
                    if (Map.class.getName().equals(attributeInfo.getType())) {
                        mapAttributes.add(attributeInfo.getName());
                    }
                }
                Collections.sort(attributeNames);

                doRegister(attributeNames, mapAttributes, oidString, objectName);
            }
        }
    } catch (Exception e) {
        log.error("Error while initializing the SNMP MIB", e);
    }
}

From source file:org.elasticsearch.river.jolokia.strategy.simple.SimpleRiverSource.java

private String getObjectName(ObjectName o) {
    return o.getDomain() + ":" + o.getCanonicalName();
}

From source file:com.heliosapm.tsdblite.handlers.json.SplitTraceInputHandler.java

public String toHostObjectNameName(final ObjectName on) {
    final StringBuilder b = new StringBuilder("meta.");
    TreeMap<String, String> tgs = new TreeMap<String, String>(on.getKeyPropertyList());
    final String metricName = on.getDomain();
    String h = tgs.remove("host");
    String a = tgs.remove("app");
    final String host = h; //==null ? "*" : h;
    final String app = a == null ? "ANYAPP" : a;
    final int segIndex = metricName.indexOf('.');
    final String seg = segIndex == -1 ? metricName : metricName.substring(0, segIndex);
    if (host != null) {
        b.append(host).append(".").append(seg).append(":");
    }/*from   w ww  . ja va  2 s.  c  o  m*/
    if (app != null) {
        tgs.put("app", app);
        //         b.append(app).append(".").append(seg).append(":");
    }

    //      if(segIndex!=-1) {
    //         tgs.put("app", metricName.substring(segIndex+1));
    //      }
    for (Map.Entry<String, String> entry : tgs.entrySet()) {
        b.append(entry.getKey()).append("=").append(entry.getValue()).append(",");
    }
    b.deleteCharAt(b.length() - 1);
    return b.toString();
}

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

/**
 * Name prepared according to requested formatting note. The key ordering can be influenced by the
 * processing parameter {@link ConfigKey#CANONICAL_NAMING}. If not given or set to "true",
 * then the canonical order is used, if set to "initial" the name is given to construction time
 * is used./*from  w ww  . ja v  a 2  s . c om*/
 *
 * @param pName name to format
 * @return formatted string
 */
public String getOrderedObjectName(ObjectName pName) {
    // For patterns we always return the canonical name
    if (pName.isPattern()) {
        return pName.getCanonicalName();
    }
    if (getParameterAsBool(ConfigKey.CANONICAL_NAMING)) {
        return pName.getCanonicalName();
    } else {
        return pName.getDomain() + ":" + pName.getKeyPropertyListString();
    }
}

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

private void addException(ObjectName pName, Exception pExp) {
    JSONObject mBeansMap = getOrCreateJSONObject(infoMap, pName.getDomain());
    JSONObject mBeanMap = getOrCreateJSONObject(mBeansMap, getKeyPropertyString(pName));
    mBeanMap.put(DataKeys.ERROR.getKey(), pExp.toString());
}