private <T> T getAttribute(ObjectName beanName, String attributeName) throws Exception { if (beanName != null) { return (T) mbsc.getAttribute(beanName, attributeName); } else { return null; } }
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; }
private CompositeData getLastGcInfo() throws JMException, IOException { return (CompositeData)mserver.getAttribute(name, "LastGcInfo"); } }
private long getCollectionCount() throws JMException, IOException { return (Long)mserv.getAttribute(mbean, "CollectionCount"); }
private long getCollectionTime() throws JMException, IOException { return (Long)mserv.getAttribute(mbean, "CollectionTime"); }
private String getName() throws JMException, IOException { return (String) mserv.getAttribute(mbean, "Name"); }
private CompositeData getLastGcInfo() throws JMException, IOException { return (CompositeData)mserv.getAttribute(mbean, "LastGcInfo"); }
private boolean getThreadingMBeanCapability(String attrName) { try { Object val = mserver.getAttribute(THREADING_MBEAN, attrName); return Boolean.TRUE.equals(val); } catch(Exception e) { return false; } }
public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException { try { return delegate.getAttribute(name, attribute); } catch(IOException e) { throw new RuntimeException(e); } }
private long getProcessCpuTime() { try { ObjectName bean = new ObjectName("java.lang:type=OperatingSystem"); return (Long) mserver.getAttribute(bean, "ProcessCpuTime"); } catch (Exception e) { throw new RuntimeException(e); } }
public static int getJavaVersion(final MBeanServerConnection mbsc) throws Exception { Object version = mbsc.getAttribute(Client.getObjectName("java.lang:type=Runtime"), "SpecVersion"); String javaVersion = version.toString(); if (javaVersion.startsWith("1.8") || Double.parseDouble(javaVersion.substring(0, 3)) > 1.7) { return 8; } else if (javaVersion.startsWith("1.7")) { return 7; } else if (javaVersion.startsWith("1.6")) { return 6; } else { return 0; } } }
private static List<Attribute> individuallyLoadAttributes( MBeanServerConnection server, ObjectName objectName, List<String> matchingNames) { List<Attribute> attributes = new ArrayList<>(); for (String attrName : matchingNames) { try { Object value = server.getAttribute(objectName, attrName); attributes.add(new Attribute(attrName, value)); } catch (Exception e) { LOGGER.info("Couldn't load attribute {} for {} : {}", new Object[]{attrName, objectName, e.getMessage()}, e); } } return attributes; } }
@Override public Object getValue() { try { return mBeanServerConn.getAttribute(getObjectName(), attributeName); } catch (IOException e) { return null; } catch (JMException e) { return null; } }
return this.serverToUse.getAttribute(this.objectName, attributeName);
private Object getAttribute(ObjectName objName, String attrName) throws MBeanException, InstanceNotFoundException, AttributeNotFoundException, ReflectionException, IOException { final NameValueMap values = getCachedAttributes(objName, Collections.singleton(attrName)); Object value = values.get(attrName); if (value != null || values.containsKey(attrName)) { return value; } // Not in cache, presumably because it was omitted from the // getAttributes result because of an exception. Following // call will probably provoke the same exception. return conn.getAttribute(objName, attrName); }
@Override protected Object getAttribute(String attribute) throws SchedulerException { try { return server.getAttribute(getSchedulerObjectName(), attribute); } catch (Exception e) { throw new SchedulerException("Failed to get Scheduler MBean attribute: " + attribute, e); } }
@Override protected Object getAttribute(String attribute) throws SchedulerException { try { return server.getAttribute(getSchedulerObjectName(), attribute); } catch (Exception e) { throw new SchedulerException("Failed to get Scheduler MBean attribute: " + attribute, e); } }
public Object getProperty(String property) { try { return server.getAttribute(name, property); } catch (MBeanException e) { throwExceptionWithTarget("Could not access property: " + property + ". Reason: ", e); } catch (Exception e) { if (!ignoreErrors) throwException("Could not access property: " + property + ". Reason: ", e); } return null; }
private Object getAttribute(ObjectName objName, String attrName) throws MBeanException, InstanceNotFoundException, AttributeNotFoundException, ReflectionException, IOException { final NameValueMap values = getCachedAttributes( objName, Collections.singleton(attrName)); Object value = values.get(attrName); if (value != null || values.containsKey(attrName)) { return value; } // Not in cache, presumably because it was omitted from the // getAttributes result because of an exception. Following // call will probably provoke the same exception. return conn.getAttribute(objName, attrName); }
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; }