List of usage examples for javax.management MBeanServerConnection getAttributes
public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException, IOException;
Retrieves the values of several attributes of a named MBean.
From source file:com.googlecode.jmxtrans.model.Query.java
public Iterable<Result> fetchResults(MBeanServerConnection mbeanServer, ObjectName queryName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { MBeanInfo info = mbeanServer.getMBeanInfo(queryName); ObjectInstance oi = mbeanServer.getObjectInstance(queryName); List<String> attributes; if (attr.isEmpty()) { attributes = new ArrayList<>(); for (MBeanAttributeInfo attrInfo : info.getAttributes()) { attributes.add(attrInfo.getName()); }//from w w w. j a v a 2s . com } 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(), info.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(); }
From source file:dk.netarkivet.harvester.harvesting.controller.BnfHeritrixController.java
/** * Executes a JMX call (attribute read or single operation) on a given bean. * * @param beanName// w ww. j a v a 2s . c o m * the MBean name. * @param retry * if true, will retry a number of times if the operation fails. * @param isOperation * true if the call is an operation, false if it's an attribute * read. * @param names * name of operation or name of attributes * @param args * optional arguments for operations * @return the object returned by the distant MBean */ private Object jmxCall(String beanName, boolean retry, boolean isOperation, String[] names, String... args) { MBeanServerConnection connection = getMBeanServerConnection(); int maxTries = 1; if (retry) { maxTries = jmxMaxTries; } int tries = 0; Throwable lastException; do { tries++; try { if (isOperation) { final String[] signature = new String[args.length]; Arrays.fill(signature, String.class.getName()); return connection.invoke(JMXUtils.getBeanName(beanName), names[0], args, signature); } else { return connection.getAttributes(JMXUtils.getBeanName(beanName), names).asList(); } } catch (IOException e) { lastException = e; } catch (ReflectionException e) { lastException = e; } catch (InstanceNotFoundException e) { lastException = e; } catch (MBeanException e) { lastException = e; } log.debug("Attempt " + tries + " out of " + maxTries + " attempts to make this jmxCall failed "); if (tries < maxTries) { TimeUtils.exponentialBackoffSleep(tries); } } while (tries < maxTries); String msg = ""; if (isOperation) { msg = "Failed to execute " + names[0] + " with args " + Arrays.toString(args) + " on " + beanName; } else { msg = "Failed to read attributes " + Arrays.toString(names) + " of " + beanName; } if (lastException != null) { msg += ", last exception was " + lastException.getClass().getName(); } msg += " after " + tries + " attempts"; throw new IOFailure(msg, lastException); }
From source file:org.helios.collector.jmx.connection.AbstractMBeanServerConnectionFactory.java
/** * Returns the values of the passed attribute names * @param objectName//from w ww . jav a 2 s. com * @param attributeNames * @return * @throws InstanceNotFoundException * @throws ReflectionException * @throws IOException */ @Override @ManagedOperation public AttributeList getAttributes(ObjectName objectName, String[] attributeNames) throws InstanceNotFoundException, ReflectionException, IOException { validateConn(); MBeanServerConnection conn = null; try { conn = getPooledConnection(); return conn.getAttributes(objectName, attributeNames); } catch (MBeanServerConnectionFactoryException e) { throw new RuntimeException("Failed to get pooled connection", e); } finally { try { this.returnPooledConnection(conn); } catch (Exception e) { log.debug(e.getMessage()); } } }
From source file:org.hyperic.hq.product.jmx.MxQuery.java
public void getAttributes(MBeanServerConnection mServer, ObjectName name, String[] attrs) throws PluginException { if (attrs.length == 0) { return;/*from w w w . j a v a 2 s . c o m*/ } AttributeList mBeanAttrs; try { mBeanAttrs = mServer.getAttributes(name, attrs); } catch (RemoteException e) { throw new PluginException("Cannot connect to server", e); } catch (InstanceNotFoundException e) { throw new PluginException("Cannot find MBean [" + name + "]", e); } catch (ReflectionException e) { throw new PluginException("MBean reflection exception", e); } catch (IOException e) { throw new PluginException("Cannot connect to server", e); } for (Iterator it = mBeanAttrs.iterator(); it.hasNext();) { Attribute attr = (Attribute) it.next(); Object value = attr.getValue(); if (value != null) { setAttribute(attr.getName(), value.toString()); } } }