List of usage examples for javax.management MBeanInfo getOperations
public MBeanOperationInfo[] getOperations()
From source file:Utilities.java
/** * Prints info about a bean to a {@link VarOutputSink}. * //from w ww . j a v a 2 s .c o m * @param sink The {@link VarOutputSink} to which info 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 printMBeanInfo(VarOutputSink sink, MBeanServer mbs, ObjectName objectName) { MBeanInfo info = getMBeanInfoSafely(sink, mbs, objectName); if (info == null) { return; } sink.echo("\nCLASSNAME: \t" + info.getClassName()); sink.echo("\nDESCRIPTION: \t" + info.getDescription()); sink.echo("\nATTRIBUTES"); MBeanAttributeInfo[] attrInfo = info.getAttributes(); sink.printVariable("attrcount", Integer.toString(attrInfo.length)); if (attrInfo.length > 0) { for (int i = 0; i < attrInfo.length; i++) { sink.echo(" ** NAME: \t" + attrInfo[i].getName()); sink.echo(" DESCR: \t" + attrInfo[i].getDescription()); sink.echo(" TYPE: \t" + attrInfo[i].getType() + "\tREAD: " + attrInfo[i].isReadable() + "\tWRITE: " + attrInfo[i].isWritable()); } } else sink.echo(" ** No attributes **"); sink.echo("\nCONSTRUCTORS"); MBeanConstructorInfo[] constrInfo = info.getConstructors(); for (int i = 0; i < constrInfo.length; i++) { sink.echo(" ** NAME: \t" + constrInfo[i].getName()); sink.echo(" DESCR: \t" + constrInfo[i].getDescription()); sink.echo(" PARAM: \t" + constrInfo[i].getSignature().length + " parameter(s)"); } sink.echo("\nOPERATIONS"); MBeanOperationInfo[] opInfo = info.getOperations(); if (opInfo.length > 0) { for (int i = 0; i < opInfo.length; i++) { sink.echo(" ** NAME: \t" + opInfo[i].getName()); sink.echo(" DESCR: \t" + opInfo[i].getDescription()); sink.echo(" PARAM: \t" + opInfo[i].getSignature().length + " parameter(s)"); } } else sink.echo(" ** No operations ** "); sink.echo("\nNOTIFICATIONS"); MBeanNotificationInfo[] notifInfo = info.getNotifications(); if (notifInfo.length > 0) { for (int i = 0; i < notifInfo.length; i++) { sink.echo(" ** NAME: \t" + notifInfo[i].getName()); sink.echo(" DESCR: \t" + notifInfo[i].getDescription()); String notifTypes[] = notifInfo[i].getNotifTypes(); for (int j = 0; j < notifTypes.length; j++) { sink.echo(" TYPE: \t" + notifTypes[j]); } } } else sink.echo(" ** No notifications **"); }
From source file:com.springsource.hq.plugin.tcserver.plugin.appmgmt.TomcatJmxScriptingApplicationManager.java
private boolean isTcRuntime250OrLater(String objectName, String operationName, int expected25OrLaterArgumentCount, ConfigResponse config) throws JMException, IOException { MBeanServerConnection mBeanServer = mxUtil.getMBeanServer(config.toProperties()); MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(new ObjectName(objectName)); for (MBeanOperationInfo operationInfo : mBeanInfo.getOperations()) { if (operationInfo.getName().equals(operationName) && (expected25OrLaterArgumentCount == operationInfo.getSignature().length)) { return true; }//from w w w. j a va2 s . com } return false; }
From source file:com.springsource.hq.plugin.tcserver.plugin.appmgmt.TomcatJmxApplicationManager.java
private boolean isTcRuntime250OrLater(String objectName, String operationName, int expected25OrLaterArgumentCount, Properties config) throws PluginException { try {//from www . j ava2s. co m MBeanServerConnection mBeanServer = mxUtil.getMBeanServer(config); MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(new ObjectName(objectName)); for (MBeanOperationInfo operationInfo : mBeanInfo.getOperations()) { if (operationName.equals(operationInfo.getName()) && expected25OrLaterArgumentCount == operationInfo.getSignature().length) { return true; } } return false; } catch (Exception e) { throw createPluginException(e); } }
From source file:com.stumbleupon.hbaseadmin.JMXQuery.java
protected void listOptions(MBeanServerConnection mbsc, ObjectInstance instance) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { final MBeanInfo info = mbsc.getMBeanInfo(instance.getObjectName()); final MBeanAttributeInfo[] attributes = info.getAttributes(); if (attributes.length > 0) { System.out.println("Attributes:"); for (int i = 0; i < attributes.length; ++i) { System.out.println(' ' + attributes[i].getName() + ": " + attributes[i].getDescription() + " (type=" + attributes[i].getType() + ")"); }// ww w. jav a 2 s. com } MBeanOperationInfo[] operations = info.getOperations(); if (operations.length > 0) { System.out.println("Operations:"); for (int i = 0; i < operations.length; ++i) { final MBeanParameterInfo[] params = operations[i].getSignature(); final StringBuffer paramsStrBuffer = new StringBuffer(); if (params != null) { for (int j = 0; j < params.length; ++j) { paramsStrBuffer.append("\n name="); paramsStrBuffer.append(params[j].getName()); paramsStrBuffer.append(" type="); paramsStrBuffer.append(params[j].getType()); paramsStrBuffer.append(" "); paramsStrBuffer.append(params[j].getDescription()); } } System.out.println(' ' + operations[i].getName() + ": " + operations[i].getDescription() + "\n Parameters " + params.length + ", return type=" + operations[i].getReturnType() + paramsStrBuffer.toString()); } } }
From source file:org.jolokia.jmx.JsonDymamicMBeanImplTest.java
@Test public void checkMBeanInfo() throws Exception { MBeanInfo info = platformServer.getMBeanInfo(testName); MBeanAttributeInfo aInfo[] = info.getAttributes(); Map<String, MBeanAttributeInfo> attributes = new HashMap<String, MBeanAttributeInfo>(); for (MBeanAttributeInfo a : aInfo) { attributes.put(a.getName(), a);/*from w w w . j a v a 2s . co m*/ } assertEquals(attributes.get("Chili").getType(), String.class.getName()); assertEquals(attributes.get("Numbers").getType(), String.class.getName()); assertEquals(attributes.get("User").getType(), String.class.getName()); MBeanOperationInfo oInfo[] = info.getOperations(); Map<String, MBeanOperationInfo> ops = new HashMap<String, MBeanOperationInfo>(); for (MBeanOperationInfo o : oInfo) { ops.put(o.getName(), o); } assertEquals(ops.get("lookup").getReturnType(), String.class.getName()); assertEquals(ops.get("epoch").getReturnType(), "long"); assertEquals(ops.get("charTest").getReturnType(), "char"); MBeanParameterInfo p[] = ops.get("lookup").getSignature(); assertEquals(p[0].getType(), String.class.getName()); assertEquals(p[1].getType(), String.class.getName()); p = ops.get("epoch").getSignature(); assertEquals(p[0].getType(), String.class.getName()); p = ops.get("charTest").getSignature(); assertEquals(p[0].getType(), Character.class.getName()); }
From source file:org.apache.geode.management.internal.security.MBeanServerWrapper.java
private ResourcePermission getOperationContext(ObjectName objectName, String featureName, boolean isOp) throws InstanceNotFoundException, ReflectionException { MBeanInfo beanInfo; try {// ww w . j av a2 s . c o m beanInfo = mbs.getMBeanInfo(objectName); } catch (IntrospectionException e) { throw new GemFireSecurityException("error getting beanInfo of " + objectName, e); } // If there is no annotation defined either in the class level or method level, we should // consider this operation/attribute freely accessible ResourcePermission result = null; // find the context in the beanInfo if defined in the class level result = getOperationContext(beanInfo.getDescriptor(), result); MBeanFeatureInfo[] featureInfos; if (isOp) { featureInfos = beanInfo.getOperations(); } else { featureInfos = beanInfo.getAttributes(); } // still look into the attributes/operations to see if it's defined in the method level for (MBeanFeatureInfo info : featureInfos) { if (info.getName().equals(featureName)) { // found the featureInfo of this method on the bean result = getOperationContext(info.getDescriptor(), result); break; } } return result; }
From source file:org.springframework.jmx.access.MBeanClientInterceptor.java
/** * Loads the management interface info for the configured MBean into the caches. * This information is used by the proxy when determining whether an invocation matches * a valid operation or attribute on the management interface of the managed resource. *//*from w w w . j a v a 2 s .c o m*/ private void retrieveMBeanInfo(MBeanServerConnection server) throws MBeanInfoRetrievalException { try { MBeanInfo info = server.getMBeanInfo(this.objectName); MBeanAttributeInfo[] attributeInfo = info.getAttributes(); this.allowedAttributes = new HashMap<>(attributeInfo.length); for (MBeanAttributeInfo infoEle : attributeInfo) { this.allowedAttributes.put(infoEle.getName(), infoEle); } MBeanOperationInfo[] operationInfo = info.getOperations(); this.allowedOperations = new HashMap<>(operationInfo.length); for (MBeanOperationInfo infoEle : operationInfo) { Class<?>[] paramTypes = JmxUtils.parameterInfoToTypes(infoEle.getSignature(), this.beanClassLoader); this.allowedOperations.put(new MethodCacheKey(infoEle.getName(), paramTypes), infoEle); } } catch (ClassNotFoundException ex) { throw new MBeanInfoRetrievalException("Unable to locate class specified in method signature", ex); } catch (IntrospectionException ex) { throw new MBeanInfoRetrievalException("Unable to obtain MBean info for bean [" + this.objectName + "]", ex); } catch (InstanceNotFoundException ex) { // if we are this far this shouldn't happen, but... throw new MBeanInfoRetrievalException( "Unable to obtain MBean info for bean [" + this.objectName + "]: it is likely that this bean was unregistered during the proxy creation process", ex); } catch (ReflectionException ex) { throw new MBeanInfoRetrievalException("Unable to read MBean info for bean [ " + this.objectName + "]", ex); } catch (IOException ex) { throw new MBeanInfoRetrievalException("An IOException occurred when communicating with the " + "MBeanServer. It is likely that you are communicating with a remote MBeanServer. " + "Check the inner exception for exact details.", ex); } }
From source file:org.hyperic.hq.product.jmx.MxLiveDataPlugin.java
private Object queryMBeans(String pattern, Properties props) throws PluginException { MBeanServerConnection mServer; try {/*from ww w . ja v a 2s. co m*/ 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:com.tesora.dve.tools.DVEConfigCLI.java
public void cmd_jmx_mbean(Scanner scanner) throws PEException { checkJMXConnected();/*from w w w .j ava2 s . c o m*/ checkJMXDomain(); final String mbean = scan(scanner, "mbean"); final ObjectName on = jmxConnector.makeObjectName(jmxDomain, mbean); final MBeanInfo info = jmxConnector.getBeanInfo(on); jmxMBean = on; jmxMBeanInfo = info; printlnDots("MBean '" + jmxMBean + "' selected"); println("Attributes = " + (info.getAttributes() == null ? "N/A" : info.getAttributes().length)); println("Operations = " + (info.getOperations() == null ? "N/A" : info.getOperations().length)); }
From source file:org.hyperic.hq.product.jmx.MBeanDumper.java
public void dump(Set beans) { Iterator iter = beans.iterator(); while (iter.hasNext()) { ObjectName obj = (ObjectName) iter.next(); try {/*from www . ja va 2s .c o m*/ MBeanInfo info = getMBeanInfo(obj); System.out.println("MBean: " + info.getClassName()); System.out.println("Name: " + obj); MBeanAttributeInfo[] attrs = info.getAttributes(); for (int k = 0; k < attrs.length; k++) { String name = attrs[k].getName(); String value = "null"; try { Object o = getAttribute(obj, name); if (o != null) { if (o.getClass().isArray()) { value = Arrays.asList((Object[]) o).toString(); } else { value = o.toString(); } } } catch (Exception e) { value = "ERROR"; if (log.isDebugEnabled()) { e.printStackTrace(); } } String perms = ""; if (attrs[k].isReadable()) { perms += "r"; } if (attrs[k].isWritable()) { perms += "w"; } System.out.println("\t" + k + ". Attribute: " + name + " = " + value + " (" + perms + ")"); } MBeanOperationInfo[] ops = info.getOperations(); for (int i = 0; i < ops.length; i++) { ArrayList sig = new ArrayList(); MBeanParameterInfo[] params = ops[i].getSignature(); for (int j = 0; j < params.length; j++) { sig.add(params[j].getType()); } System.out.println( "\t Operation: " + ops[i].getReturnType() + " " + ops[i].getName() + " " + sig); } } catch (Exception e) { if (log.isDebugEnabled()) { e.printStackTrace(); } } System.out.println(""); } }