public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException { try { return delegate.getAttributes(name, attributes); } catch(IOException e) { throw new RuntimeException(e); } }
private static List<Attribute> batchLoadAttributes( MBeanServerConnection server, ObjectName objectName, List<String> matchingNames) throws InstanceNotFoundException, ReflectionException, IOException { final String[] namesArray = matchingNames.toArray(new String[matchingNames.size()]); return server.getAttributes(objectName, namesArray).asList(); }
private long totalTime(long id) throws JMException, IOException { AttributeList list = mserver.getAttributes(name, new String[]{"CollectionCount", "CollectionTime"}); long rid = ((Number)((Attribute)list.get(0)).getValue()).longValue(); if (id == rid) { return ((Number)((Attribute)list.get(1)).getValue()).longValue(); } else { return -1; } }
@Override protected AttributeList getAttributes(String[] attributes) throws SchedulerException { try { return server.getAttributes(getSchedulerObjectName(), attributes); } catch (Exception e) { throw new SchedulerException("Failed to get Scheduler MBean attributes: " + Arrays.asList(attributes), e); } }
@Override protected AttributeList getAttributes(String[] attributes) throws SchedulerException { try { return server.getAttributes(getSchedulerObjectName(), attributes); } catch (Exception e) { throw new SchedulerException("Failed to get Scheduler MBean attributes: " + Arrays.asList(attributes), e); } }
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 synchronized NameValueMap getCachedAttributes(ObjectName objName, Set<String> attrNames) throws InstanceNotFoundException, ReflectionException, IOException { NameValueMap values = cachedValues.get(objName); if (values != null && values.keySet().containsAll(attrNames)) { return values; } attrNames = new TreeSet<String>(attrNames); Set<String> oldNames = cachedNames.get(objName); if (oldNames != null) { attrNames.addAll(oldNames); } values = new NameValueMap(); final AttributeList attrs = conn.getAttributes(objName, attrNames.toArray(new String[attrNames.size()])); for (Attribute attr : attrs.asList()) { values.put(attr.getName(), attr.getValue()); } cachedValues.put(objName, values); cachedNames.put(objName, attrNames); return values; }
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); } } }
private synchronized NameValueMap getCachedAttributes( ObjectName objName, Set<String> attrNames) throws InstanceNotFoundException, ReflectionException, IOException { NameValueMap values = cachedValues.get(objName); if (values != null && values.keySet().containsAll(attrNames)) { return values; } attrNames = new TreeSet<String>(attrNames); Set<String> oldNames = cachedNames.get(objName); if (oldNames != null) { attrNames.addAll(oldNames); } values = new NameValueMap(); final AttributeList attrs = conn.getAttributes( objName, attrNames.toArray(new String[attrNames.size()])); for (Attribute attr : attrs.asList()) { values.put(attr.getName(), attr.getValue()); } cachedValues.put(objName, values); cachedNames.put(objName, attrNames); return values; }
public Iterable<Result> fetchResults(MBeanServerConnection mbeanServer, ObjectName queryName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { ObjectInstance oi = mbeanServer.getObjectInstance(queryName); List<String> attributes; if (attr.isEmpty()) { attributes = new ArrayList<>(); MBeanInfo info = mbeanServer.getMBeanInfo(queryName); for (MBeanAttributeInfo attrInfo : info.getAttributes()) { attributes.add(attrInfo.getName()); } } else { attributes = attr; } try { if (!attributes.isEmpty()) { logger.debug("Executing queryName [{}] from query [{}]", queryName.getCanonicalName(), this); AttributeList al = mbeanServer.getAttributes(queryName, attributes.toArray(new String[attributes.size()])); return new JmxResultProcessor(this, oi, al.asList(), oi.getClassName(), queryName.getDomain()).getResults(); } } catch (UnmarshalException ue) { if ((ue.getCause() != null) && (ue.getCause() instanceof ClassNotFoundException)) { logger.debug("Bad unmarshall, continuing. This is probably ok and due to something like this: " + "http://ehcache.org/xref/net/sf/ehcache/distribution/RMICacheManagerPeerListener.html#52", ue.getMessage()); } else { throw ue; } } return ImmutableList.of(); }
protected static Object doAttributeOperation(MBeanServerConnection mbsc, ObjectInstance instance, String command, MBeanAttributeInfo[] infos) throws Exception { // Usually we get attributes. If an argument, then we're being asked // to set attribute. CommandParse parse = new CommandParse(command); if (parse.getArgs() == null || parse.getArgs().length == 0) { // Special-casing. If the subCommand is 'Attributes', then return // list of all attributes. if (command.equals("Attributes")) { String[] names = new String[infos.length]; for (int i = 0; i < infos.length; i++) { names[i] = infos[i].getName(); } return mbsc.getAttributes(instance.getObjectName(), names); } return mbsc.getAttribute(instance.getObjectName(), parse.getCmd()); } if (parse.getArgs().length != 1) { throw new IllegalArgumentException("One only argument setting " + "attribute values: " + parse.getArgs()); } // Get first attribute of name 'cmd'. Assumption is no method // overrides. Then, look at the attribute and use its type. MBeanAttributeInfo info = (MBeanAttributeInfo) getFeatureInfo(infos, parse.getCmd()); java.lang.reflect.Constructor c = Class.forName(info.getType()).getConstructor(new Class[] { String.class }); Attribute a = new Attribute(parse.getCmd(), c.newInstance(new Object[] { parse.getArgs()[0] })); mbsc.setAttribute(instance.getObjectName(), a); return null; }
AttributeList attributeValues = server.getMBeanServerConnection().getAttributes(objectName, attributes);
AttributeList attributeValues = server.getMBeanServerConnection().getAttributes(objectName, attributes);
attributes = beanConn.getAttributes(mbeanName, name2AttrInfo.keySet().toArray(new String[0])); } catch (Exception e) { logScrape(mbeanName, name2AttrInfo.keySet(), "Fail: " + e);
public AttributeList getAttributes(String[] names) { try { return mbsc.getAttributes(objectName, names); } catch (RuntimeException e) { throw e; } catch (Exception e) { return new AttributeList(); } }
@Override public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException, IOException { try { return connection.getAttributes(name, attributes); } catch (IOException e) { checkConnection(); return connection.getAttributes(name, attributes); } }
private static List<Attribute> batchLoadAttributes( MBeanServerConnection server, ObjectName objectName, List<String> matchingNames) throws InstanceNotFoundException, ReflectionException, IOException { final String[] namesArray = matchingNames.toArray(new String[matchingNames.size()]); return server.getAttributes(objectName, namesArray).asList(); }
ObjectName oName = new ObjectName("java.lang:type=OperatingSystem"); MBeanServerConnection conn ; // you should get the connection following the api, take a look the java api/ google some example javax.management.AttributeList list = conn.getAttributes(oName, new String[]{"OpenFileDescriptorCount", "MaxFileDescriptorCount"}); for(Attribute attr: list.asList()){ System.out.println(attr.getName() + ": " + attr.getValue()); }
public AttributeList getAttributes(String[] attributes) { AttributeList attList = null; try{ attList = this.conn.getAttributes(this.runtimeObjName, attributes); AttributeList jsrList = createAddAttributes(); attList.addAll(jsrList); }catch(Exception ex){ //System.out.println("Error in getAttributes of ServerInfo " + ex.getMessage()); return attList; } return attList; }
@Test public void testGetAttributes() throws Exception { assertEquals(mbeanServerConnection.getAttributes(testMBeanName, new String[]{"Value", "ObjectValue"}), new AttributeList(ImmutableList.of(new Attribute("Value", null), new Attribute("ObjectValue", null)))); testMBean.setValue("FOO"); testMBean.setObjectValue(UUID.randomUUID()); assertEquals(mbeanServerConnection.getAttributes(testMBeanName, new String[]{"Value", "ObjectValue"}), new AttributeList(ImmutableList.of(new Attribute("Value", "FOO"), new Attribute("ObjectValue", testMBean.getObjectValue())))); }