List of usage examples for javax.management ObjectName toString
@Override
public String toString()
Returns a string representation of the object name.
From source file:catalina.mbeans.DefaultContextMBean.java
/** * Add a resource link for this web application. * * @param resourceLinkName New resource link name */// ww w.ja va 2 s .c om public String addResourceLink(String resourceLinkName, String global, String name, String type) throws MalformedObjectNameException { NamingResources nresources = getNamingResources(); if (nresources == null) { return null; } ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName); if (resourceLink != null) { throw new IllegalArgumentException( "Invalid resource link name - already exists'" + resourceLinkName + "'"); } resourceLink = new ContextResourceLink(); resourceLink.setGlobal(global); resourceLink.setName(resourceLinkName); resourceLink.setType(type); nresources.addResourceLink(resourceLink); // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("ContextResourceLink"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resourceLink); return (oname.toString()); }
From source file:catalina.mbeans.NamingResourcesMBean.java
/** * Return the MBean Names of all the defined resource references for this * application./* w w w .j a v a 2s . c o m*/ */ public String[] getResources() { ContextResource[] resources = ((NamingResources) this.resource).findResources(); ArrayList results = new ArrayList(); for (int i = 0; i < resources.length; i++) { try { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resources[i]); results.add(oname.toString()); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException("Cannot create object name for resource " + resources[i]); } } return ((String[]) results.toArray(new String[results.size()])); }
From source file:catalina.mbeans.DefaultContextMBean.java
/** * Return the MBean Names of all the defined resource references for this * application./*from w ww . j av a 2 s .co m*/ */ public String[] getResources() { ContextResource[] resources = getNamingResources().findResources(); ArrayList results = new ArrayList(); for (int i = 0; i < resources.length; i++) { try { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resources[i]); results.add(oname.toString()); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException("Cannot create object name for resource " + resources[i]); } } return ((String[]) results.toArray(new String[results.size()])); }
From source file:catalina.mbeans.NamingResourcesMBean.java
/** * Return the MBean Names of all the defined resource link references for * this application.//from www . j a v a 2s . c o m */ public String[] getResourceLinks() { ContextResourceLink[] resourceLinks = ((NamingResources) this.resource).findResourceLinks(); ArrayList results = new ArrayList(); for (int i = 0; i < resourceLinks.length; i++) { try { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resourceLinks[i]); results.add(oname.toString()); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException("Cannot create object name for resource " + resourceLinks[i]); } } return ((String[]) results.toArray(new String[results.size()])); }
From source file:org.openmrs.module.jmx.impl.JMXServiceImpl.java
/** * @see org.openmrs.module.jmx.JMXService#registerBean(String, Object) *///from w w w . j a va 2s. c o m @Override public void registerMBean(String folder, String name, Object mbean) { Object proxiedBean = MBeanProxifier.getProxy(mbean); try { ObjectName objName = getObjectName(folder, name); MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer(); if (beanServer.isRegistered(objName)) beanServer.unregisterMBean(objName); beanServer.registerMBean(proxiedBean, objName); log.debug("Registered MBean: " + objName.toString()); } catch (MalformedObjectNameException e) { log.error("Invalid MBean name", e); } catch (Exception e) { log.error("Unable to register MBean", e); } }
From source file:org.hyperic.hq.product.jmx.MxLiveDataPlugin.java
private Object queryMBeans(String pattern, Properties props) throws PluginException { MBeanServerConnection mServer; try {/*from w w w .j a va 2 s .com*/ mServer = MxUtil.getMBeanServer(props); } catch (Exception e) { throw new PluginException("getMBeanServer(" + props.getProperty(MxUtil.PROP_JMX_URL) + "): " + e, e); } ObjectName query; try { query = new ObjectName(pattern); } catch (Exception e) { throw new PluginException("Invalid query '" + pattern + "': " + e); } Map res = new HashMap(); try { Iterator beans = mServer.queryNames(query, null).iterator(); while (beans.hasNext()) { ObjectName obj = (ObjectName) beans.next(); Map bean = new HashMap(); Map attrs = new LinkedHashMap(); bean.put(PROP_ATTRIBUTE + "s", attrs); res.put(obj.toString(), bean); MBeanInfo info = mServer.getMBeanInfo(obj); MBeanAttributeInfo[] attrInfo = info.getAttributes(); for (int i = 0; i < attrInfo.length; i++) { MBeanAttributeInfo mia = attrInfo[i]; String name = mia.getName(); Map attr = new HashMap(); Object val; try { val = mServer.getAttribute(obj, name); } catch (Exception e) { continue; //XXX } if (val == null) { val = "-"; } attr.put("Value", val); attr.put("Description", mia.getDescription()); attr.put("isWritable", new Boolean(mia.isWritable())); attrs.put(name, attr); } bean.put(PROP_METHOD + "s", info.getOperations()); } } catch (Exception e) { throw new PluginException("Error in query '" + pattern + "': " + e, e); } return res; }
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//from w w w .j a v a 2s. c om 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:catalina.mbeans.MemoryUserDatabaseMBean.java
/** * Return the MBean Name for the specified role name (if any); * otherwise return <code>null</code>. * * @param rolename Role name to look up//from ww w .j a v a2s. co m */ public String findRole(String rolename) { UserDatabase database = (UserDatabase) this.resource; Role role = database.findRole(rolename); if (role == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedRole.getDomain(), role); return (oname.toString()); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException("Cannot create object name for role " + role); } }
From source file:catalina.mbeans.MemoryUserDatabaseMBean.java
/** * Return the MBean Name for the specified user name (if any); * otherwise return <code>null</code>. * * @param username User name to look up//w w w .java2 s . c o m */ public String findUser(String username) { UserDatabase database = (UserDatabase) this.resource; User user = database.findUser(username); if (user == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user); return (oname.toString()); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException("Cannot create object name for user " + user); } }
From source file:catalina.mbeans.MemoryUserDatabaseMBean.java
/** * Return the MBean Name for the specified group name (if any); * otherwise return <code>null</code>. * * @param groupname Group name to look up *//* www . j av a2s .c om*/ public String findGroup(String groupname) { UserDatabase database = (UserDatabase) this.resource; Group group = database.findGroup(groupname); if (group == null) { return (null); } try { ObjectName oname = MBeanUtils.createObjectName(managedGroup.getDomain(), group); return (oname.toString()); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException("Cannot create object name for group " + group); } }