public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException, ReflectionException { try { return delegate.getMBeanInfo(name); } catch(IOException e) { throw new RuntimeException(e); } }
Map<String,String[]> env = new HashMap<String, String[]>(); env.put( JMXConnector.CREDENTIALS, new String[]{"user","pass"} ); JMXServiceURL address = new JMXServiceURL("service:rmi:///jndi/rmi://host:port/jmxrmi"); JMXConnector connector = JMXConnectorFactory.connect(address,env); MBeanServerConnection mbs = connector.getMBeanServerConnection(); //get all mbeans Set<ObjectInstance> beans = mbs.queryMBeans(null,null); for( ObjectInstance instance : beans ) { MBeanInfo info = mbs.getMBeanInfo( instance.getObjectName() ); }
private Map<String, String> getMBeanValues(MBeanServerConnection cnx, ObjectName on, String ... attributeNames) throws InstanceNotFoundException, IOException, ReflectionException, IntrospectionException { if (attributeNames == null) { MBeanInfo info = cnx.getMBeanInfo( on ); MBeanAttributeInfo[] attributeArray = info.getAttributes(); int i = 0; attributeNames = new String[attributeArray.length]; for (MBeanAttributeInfo ai : attributeArray) attributeNames[i++] = ai.getName(); } AttributeList attributes = cnx.getAttributes(on, attributeNames); Map<String, String> values = new HashMap<String, String>(); for (javax.management.Attribute attribute : attributes.asList()) { Object value = attribute.getValue(); values.put(attribute.getName(), value == null ? "" : value.toString()); } return values; }
private void checkDumpAllThreads() { synchronized (this) { hasDumpAllThreads = false; if(server == null){ if(System.getProperty("java.version").compareTo("1.5") >= 0){ hasDumpAllThreads = true; } }else{ try { MBeanOperationInfo[] mopis = server.getMBeanInfo(objName).getOperations(); if ( mopis != null ) { for ( MBeanOperationInfo op : mopis ) { if ( "dumpAllThreads".equals(op.getName()) ) { hasDumpAllThreads = true; break; } } } } catch ( Exception ex ) { ex.printStackTrace(); } } } } }
private void checkDumpAllThreads() { synchronized (this) { hasDumpAllThreads = false; if(server == null){ if(System.getProperty("java.version").compareTo("1.5") >= 0){ hasDumpAllThreads = true; } }else{ try { MBeanOperationInfo[] mopis = server.getMBeanInfo(objName).getOperations(); if ( mopis != null ) { for ( MBeanOperationInfo op : mopis ) { if ( "dumpAllThreads".equals(op.getName()) ) { hasDumpAllThreads = true; break; } } } } catch ( Exception ex ) { ex.printStackTrace(); } } } } }
private void checkDumpAllThreads() { synchronized (this) { hasDumpAllThreads = false; if(server == null){ if(System.getProperty("java.version").compareTo("1.5") >= 0){ hasDumpAllThreads = true; } }else{ try { MBeanOperationInfo[] mopis = server.getMBeanInfo(objName).getOperations(); if ( mopis != null ) { for ( MBeanOperationInfo op : mopis ) { if ( "dumpAllThreads".equals(op.getName()) ) { hasDumpAllThreads = true; break; } } } } catch ( Exception ex ) { ex.printStackTrace(); } } } } }
private void checkDumpAllThreads() { synchronized (this) { hasDumpAllThreads = false; if(server == null){ if(System.getProperty("java.version").compareTo("1.5") >= 0){ hasDumpAllThreads = true; } }else{ try { MBeanOperationInfo[] mopis = server.getMBeanInfo(objName).getOperations(); if ( mopis != null ) { for ( MBeanOperationInfo op : mopis ) { if ( "dumpAllThreads".equals(op.getName()) ) { hasDumpAllThreads = true; break; } } } } catch ( Exception ex ) { ex.printStackTrace(); } } } } }
private void checkDumpAllThreads() { synchronized (this) { hasDumpAllThreads = false; if(server == null){ if(System.getProperty("java.version").compareTo("1.5") >= 0){ hasDumpAllThreads = true; } }else{ try { MBeanOperationInfo[] mopis = server.getMBeanInfo(objName).getOperations(); if ( mopis != null ) { for ( MBeanOperationInfo op : mopis ) { if ( "dumpAllThreads".equals(op.getName()) ) { hasDumpAllThreads = true; break; } } } } catch ( Exception ex ) { ex.printStackTrace(); } } } } }
public String get(ObjectName bean, String attr) throws Exception { MBeanInfo mbinfo = mserver.getMBeanInfo(bean); MBeanAttributeInfo ai = attrInfo(mbinfo, attr); if (ai == null) { throw new IllegalArgumentException("No such attribute '" + attr + "'"); } if (!ai.isReadable()) { throw new IllegalArgumentException("Attribute '" + attr + "' is write-only"); } Object v = mserver.getAttribute(bean, attr); String type = ai.getType(); String text = format(v, type); return text; }
public void walkTree(MBeanServerConnection connection) throws Exception { // key here is null, null returns everything! Set<ObjectName> mbeans = connection.queryNames(null, null); for (ObjectName name : mbeans) { MBeanInfo info = connection.getMBeanInfo(name); MBeanAttributeInfo[] attrs = info.getAttributes(); String[] attrNames = new String[attrs.length]; for (int i = 0; i < attrs.length; i++) { attrNames[i] = attrs[i].getName(); } try { AttributeList attributes = connection.getAttributes(name, attrNames); for (Attribute attribute : attributes.asList()) { output(name.getCanonicalName() + "%" + attribute.getName(), attribute.getValue()); } } catch (Exception e) { log.error("error getting " + name + ":" + e.getMessage(), e); } } }
public void set(ObjectName bean, String attr, String value) throws Exception { MBeanInfo mbinfo = mserver.getMBeanInfo(bean); MBeanAttributeInfo ai = attrInfo(mbinfo, attr); if (ai == null) { throw new IllegalArgumentException("No such attribute '" + attr + "'"); } if (!ai.isWritable()) { throw new IllegalArgumentException("Attribute '" + attr + "' is not writeable"); } String type = ai.getType(); Object ov = convert(value, type); mserver.setAttribute(bean, new Attribute(attr, ov)); }
protected static String listOptions(MBeanServerConnection mbsc, ObjectInstance instance) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { StringBuffer result = new StringBuffer(); MBeanInfo info = mbsc.getMBeanInfo(instance.getObjectName()); MBeanAttributeInfo[] attributes = info.getAttributes(); if (attributes.length > 0) {
MBeanInfo info = server.getMBeanInfo(this.objectName);
public GroovyMBean(MBeanServerConnection server, ObjectName name, boolean ignoreErrors) throws JMException, IOException { this.server = server; this.name = name; this.ignoreErrors = ignoreErrors; this.beanInfo = server.getMBeanInfo(name); MBeanOperationInfo[] operationInfos = beanInfo.getOperations(); for (MBeanOperationInfo info : operationInfos) { String signature[] = createSignature(info); // Construct a simplistic key to support overloaded operations on the MBean. String operationKey = createOperationKey(info.getName(), signature.length); operations.put(operationKey, signature); } }
private static void listBeans(ObjectName query, JsonGenerator jg, MBeanServerConnection mBeanServer) throws Exception { Set<ObjectName> names = null; names = mBeanServer.queryNames(query, null); jg.writeArrayFieldStart("beans"); Iterator<ObjectName> it = names.iterator(); while (it.hasNext()) { ObjectName oname = it.next(); MBeanInfo minfo; String code = ""; minfo = mBeanServer.getMBeanInfo(oname); code = minfo.getClassName(); String prs = ""; if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) { prs = "modelerType"; code = (String) mBeanServer.getAttribute(oname, prs); } jg.writeStartObject(); jg.writeStringField("name", oname.toString()); jg.writeStringField("modelerType", code); MBeanAttributeInfo attrs[] = minfo.getAttributes(); for (int i = 0; i < attrs.length; i++) { writeAttribute(mBeanServer, jg, oname, attrs[i]); } jg.writeEndObject(); } jg.writeEndArray(); }
public void walkTree(MBeanServerConnection connection, Server server) throws Exception { // key here is null, null returns everything! Set<ObjectName> mbeans = connection.queryNames(null, null); for (ObjectName name : mbeans) { MBeanInfo info = connection.getMBeanInfo(name); MBeanAttributeInfo[] attrs = info.getAttributes(); Query.Builder queryBuilder = Query.builder() .setObj(name.getCanonicalName()) .addOutputWriterFactory(new StdOutWriter(ImmutableList.<String>of(), false, false, null, Collections.<String, Object>emptyMap())); for (MBeanAttributeInfo attrInfo : attrs) { queryBuilder.addAttr(attrInfo.getName()); } Query query = queryBuilder.build(); try { Iterable<Result> results = server.execute(query); query.runOutputWritersForQuery(server, results); } catch (AttributeNotFoundException anfe) { log.error("Error", anfe); } } } }
MBeanInfo info = server.getMBeanInfo(this.objectName);
@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("GetMBeanInfo"); byte paramType = input.readByte(); if (paramType != OBJECT_NAME) { throw new IOException("Unexpected paramType"); } Unmarshaller unmarshaller = prepareForUnMarshalling(input); ObjectName objectName; try { objectName = unmarshaller.readObject(ObjectName.class); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } try { MBeanInfo info = server.getMBeanServerConnection().getMBeanInfo(objectName); writeResponse(info, MBEAN_INFO, GET_MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Success Response Sent", correlationId); } catch (IntrospectionException e) { writeResponse(e, MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Failure Response Sent", correlationId); } catch (InstanceNotFoundException e) { writeResponse(e, MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Failure Response Sent", correlationId); } catch (ReflectionException e) { writeResponse(e, MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Failure Response Sent", correlationId); } }
public String invoke(ObjectName bean, String operation, String... params) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException, MBeanException { MBeanInfo mbinfo = mserver.getMBeanInfo(bean); MBeanOperationInfo op = null; for(MBeanOperationInfo oi: mbinfo.getOperations()) { if (oi.getName().equalsIgnoreCase(operation) && oi.getSignature().length == params.length) { if (op != null) { throw new IllegalArgumentException("Ambiguous " + operation + "/" + params.length + " operatition signature for " + bean); } op = oi; } } if (op == null) { throw new IllegalArgumentException("Operation " + operation + "/" + params.length + " not found for " + bean); } Object[] args = new Object[params.length]; String[] sig = new String[params.length]; for(int i = 0; i != params.length; ++i) { args[i] = convert(params[i], op.getSignature()[i].getType()); sig[i] = op.getSignature()[i].getType(); } return format(mserver.invoke(bean, op.getName(), args, sig), op.getReturnType()); }
@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("GetMBeanInfo"); byte paramType = input.readByte(); if (paramType != OBJECT_NAME) { throw new IOException("Unexpected paramType"); } Unmarshaller unmarshaller = prepareForUnMarshalling(input); ObjectName objectName; try { objectName = unmarshaller.readObject(ObjectName.class); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } try { MBeanInfo info = server.getMBeanServerConnection().getMBeanInfo(objectName); writeResponse(info, MBEAN_INFO, GET_MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Success Response Sent", correlationId); } catch (IntrospectionException e) { writeResponse(e, MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Failure Response Sent", correlationId); } catch (InstanceNotFoundException e) { writeResponse(e, MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Failure Response Sent", correlationId); } catch (ReflectionException e) { writeResponse(e, MBEAN_INFO, correlationId); log.tracef("[%d] GetMBeanInfo - Failure Response Sent", correlationId); } }