use of javax.management.MBeanAttributeInfo in project neo4j by neo4j.
the class Dbinfo method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws Exception {
Kernel kernel = getKernel();
boolean list = parser.options().containsKey("l"), get = parser.options().containsKey("g");
if ((list && get) || (!list && !get)) {
StringBuilder usage = new StringBuilder();
getUsage(usage);
usage.append(".\n");
out.print(usage.toString());
return Continuation.INPUT_COMPLETE;
}
MBeanServer mbeans = getPlatformMBeanServer();
String bean = null;
String[] attributes = null;
if (list) {
bean = parser.options().get("l");
} else if (get) {
bean = parser.options().get("g");
attributes = parser.arguments().toArray(new String[parser.arguments().size()]);
}
if (// list beans
bean == null) {
StringBuilder result = new StringBuilder();
availableBeans(mbeans, kernel, result);
out.print(result.toString());
return Continuation.INPUT_COMPLETE;
}
ObjectName mbean;
{
mbean = kernel.getMBeanQuery();
Hashtable<String, String> properties = new Hashtable<String, String>(mbean.getKeyPropertyList());
properties.put("name", bean);
try {
Iterator<ObjectName> names = mbeans.queryNames(new ObjectName(mbean.getDomain(), properties), null).iterator();
if (names.hasNext()) {
mbean = names.next();
if (names.hasNext()) {
mbean = null;
}
} else {
mbean = null;
}
} catch (Exception e) {
mbean = null;
}
}
if (mbean == null) {
throw new ShellException("No such management bean \"" + bean + "\".");
}
if (// list attributes
attributes == null) {
for (MBeanAttributeInfo attr : mbeans.getMBeanInfo(mbean).getAttributes()) {
out.println(attr.getName() + " - " + attr.getDescription());
}
} else {
if (// specify all attributes
attributes.length == 0) {
MBeanAttributeInfo[] allAttributes = mbeans.getMBeanInfo(mbean).getAttributes();
attributes = new String[allAttributes.length];
for (int i = 0; i < allAttributes.length; i++) {
attributes[i] = allAttributes[i].getName();
}
}
JSONObject json = new JSONObject();
for (Object value : mbeans.getAttributes(mbean, attributes)) {
printAttribute(json, value);
}
out.println(json.toString(2));
}
return Continuation.INPUT_COMPLETE;
}
use of javax.management.MBeanAttributeInfo in project presto by prestodb.
the class JmxMetadata method getJmxTableHandle.
private JmxTableHandle getJmxTableHandle(SchemaTableName tableName) {
try {
String canonicalName = new ObjectName(tableName.getTableName()).getCanonicalName();
Optional<ObjectName> objectName = mbeanServer.queryNames(WILDCARD, null).stream().filter(name -> canonicalName.equalsIgnoreCase(name.getCanonicalName())).findFirst();
if (!objectName.isPresent()) {
return null;
}
MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName.get());
ImmutableList.Builder<JmxColumnHandle> columns = ImmutableList.builder();
columns.add(new JmxColumnHandle(NODE_COLUMN_NAME, createUnboundedVarcharType()));
// Since this method is being called on all nodes in the cluster, we must ensure (by sorting)
// that attributes are in the same order on all of them.
Arrays.stream(mbeanInfo.getAttributes()).filter(MBeanAttributeInfo::isReadable).map(attribute -> new JmxColumnHandle(attribute.getName(), getColumnType(attribute))).sorted((column1, column2) -> column1.getColumnName().compareTo(column2.getColumnName())).forEach(columns::add);
return new JmxTableHandle(objectName.get().toString(), columns.build(), true);
} catch (JMException e) {
return null;
}
}
use of javax.management.MBeanAttributeInfo in project spring-framework by spring-projects.
the class MBeanClientInterceptor method invokeAttribute.
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation) throws JMException, IOException {
String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing);
MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName);
// management interface.
if (inf == null) {
throw new InvalidInvocationException("Attribute '" + pd.getName() + "' is not exposed on the management interface");
}
if (invocation.getMethod().equals(pd.getReadMethod())) {
if (inf.isReadable()) {
return this.serverToUse.getAttribute(this.objectName, attributeName);
} else {
throw new InvalidInvocationException("Attribute '" + attributeName + "' is not readable");
}
} else if (invocation.getMethod().equals(pd.getWriteMethod())) {
if (inf.isWritable()) {
this.serverToUse.setAttribute(this.objectName, new Attribute(attributeName, invocation.getArguments()[0]));
return null;
} else {
throw new InvalidInvocationException("Attribute '" + attributeName + "' is not writable");
}
} else {
throw new IllegalStateException("Method [" + invocation.getMethod() + "] is neither a bean property getter nor a setter");
}
}
use of javax.management.MBeanAttributeInfo in project spring-framework by spring-projects.
the class AbstractJmxAssemblerTests method testGetMBeanAttributeInfo.
@Test
public void testGetMBeanAttributeInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
MBeanAttributeInfo[] inf = info.getAttributes();
assertEquals("Invalid number of Attributes returned", getExpectedAttributeCount(), inf.length);
for (int x = 0; x < inf.length; x++) {
assertNotNull("MBeanAttributeInfo should not be null", inf[x]);
assertNotNull("Description for MBeanAttributeInfo should not be null", inf[x].getDescription());
}
}
use of javax.management.MBeanAttributeInfo in project spring-framework by spring-projects.
the class MethodExclusionMBeanInfoAssemblerComboTests method testNickNameIsExposed.
@Test
public void testNickNameIsExposed() throws Exception {
ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
MBeanAttributeInfo attr = inf.getAttribute("NickName");
assertNotNull("Nick Name should not be null", attr);
assertTrue("Nick Name should be writable", attr.isWritable());
assertTrue("Nick Name should be readable", attr.isReadable());
}
Aggregations