Search in sources :

Example 16 with MBeanAttributeInfo

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;
}
Also used : Hashtable(java.util.Hashtable) ShellException(org.neo4j.shell.ShellException) JSONException(org.neo4j.shell.util.json.JSONException) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) JSONObject(org.neo4j.shell.util.json.JSONObject) Iterator(java.util.Iterator) JSONObject(org.neo4j.shell.util.json.JSONObject) Kernel(org.neo4j.jmx.Kernel) ManagementFactory.getPlatformMBeanServer(java.lang.management.ManagementFactory.getPlatformMBeanServer) MBeanServer(javax.management.MBeanServer)

Example 17 with MBeanAttributeInfo

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;
    }
}
Also used : ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) Arrays(java.util.Arrays) DOUBLE(com.facebook.presto.spi.type.DoubleType.DOUBLE) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) Inject(javax.inject.Inject) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) Type(com.facebook.presto.spi.type.Type) MBeanServer(javax.management.MBeanServer) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) TIMESTAMP(com.facebook.presto.spi.type.TimestampType.TIMESTAMP) ENGLISH(java.util.Locale.ENGLISH) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ImmutableMap(com.google.common.collect.ImmutableMap) WILDCARD(javax.management.ObjectName.WILDCARD) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Set(java.util.Set) Constraint(com.facebook.presto.spi.Constraint) ObjectName(javax.management.ObjectName) Maps(com.google.common.collect.Maps) MBeanInfo(javax.management.MBeanInfo) ConnectorSession(com.facebook.presto.spi.ConnectorSession) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) JMException(javax.management.JMException) Optional(java.util.Optional) Builder(com.google.common.collect.ImmutableList.Builder) MBeanInfo(javax.management.MBeanInfo) ImmutableList(com.google.common.collect.ImmutableList) JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Example 18 with MBeanAttributeInfo

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");
    }
}
Also used : Attribute(javax.management.Attribute) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 19 with MBeanAttributeInfo

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());
    }
}
Also used : ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) Test(org.junit.Test)

Example 20 with MBeanAttributeInfo

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());
}
Also used : ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) Test(org.junit.Test)

Aggregations

MBeanAttributeInfo (javax.management.MBeanAttributeInfo)106 MBeanInfo (javax.management.MBeanInfo)75 ObjectName (javax.management.ObjectName)45 MBeanOperationInfo (javax.management.MBeanOperationInfo)24 Test (org.junit.Test)21 MBeanServer (javax.management.MBeanServer)15 ArrayList (java.util.ArrayList)13 AttributeNotFoundException (javax.management.AttributeNotFoundException)12 ReflectionException (javax.management.ReflectionException)12 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)11 IOException (java.io.IOException)10 AttributeList (javax.management.AttributeList)10 Attribute (javax.management.Attribute)9 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 IntrospectionException (javax.management.IntrospectionException)9 MBeanParameterInfo (javax.management.MBeanParameterInfo)9 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)9 HashMap (java.util.HashMap)8 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)7 MBeanException (javax.management.MBeanException)7