Search in sources :

Example 36 with MBeanInfo

use of javax.management.MBeanInfo in project geode by apache.

the class LocalProcessControllerJUnitTest method testProcessMBean.

@Test
public void testProcessMBean() throws Exception {
    // validate basics of the ProcessMBean
    Set<ObjectName> mbeanNames = this.server.queryNames(objectName, null);
    assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
    assertEquals(1, mbeanNames.size());
    final ObjectName name = mbeanNames.iterator().next();
    final MBeanInfo info = this.server.getMBeanInfo(name);
    final MBeanOperationInfo[] operInfo = info.getOperations();
    assertEquals(1, operInfo.length);
    assertEquals("stop", operInfo[0].getName());
    final MBeanAttributeInfo[] attrInfo = info.getAttributes();
    assertEquals(2, attrInfo.length);
    // The order of these attributes is indeterminate
    assertTrue("Pid".equals(attrInfo[0].getName()) || "Process".equals(attrInfo[0].getName()));
    assertTrue("Pid".equals(attrInfo[1].getName()) || "Process".equals(attrInfo[1].getName()));
    assertNotNull(this.server.getAttribute(name, "Pid"));
    assertNotNull(this.server.getAttribute(name, "Process"));
    assertEquals(pid, this.server.getAttribute(name, "Pid"));
    assertEquals(true, this.server.getAttribute(name, "Process"));
    // validate query using only Pid attribute
    QueryExp constraint = Query.eq(Query.attr("Pid"), Query.value(pid));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
    // validate query with wrong Pid finds nothing
    constraint = Query.eq(Query.attr("Pid"), Query.value(pid + 1));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertTrue("Found matching mbeans", mbeanNames.isEmpty());
    // validate query using both attributes
    constraint = Query.and(Query.eq(Query.attr("Process"), Query.value(true)), Query.eq(Query.attr("Pid"), Query.value(pid)));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
    // validate query with wrong attribute finds nothing
    constraint = Query.and(Query.eq(Query.attr("Process"), Query.value(false)), Query.eq(Query.attr("Pid"), Query.value(pid)));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertTrue("Found matching mbeans", mbeanNames.isEmpty());
}
Also used : MBeanInfo(javax.management.MBeanInfo) QueryExp(javax.management.QueryExp) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 37 with MBeanInfo

use of javax.management.MBeanInfo in project geode by apache.

the class MBeanUtil method printBeanDetails.

public static void printBeanDetails(ObjectName objName) throws Exception {
    MBeanAttributeInfo[] attributeInfos;
    MBeanInfo info = null;
    try {
        info = mbeanServer.getMBeanInfo(objName);
    } catch (IntrospectionException e1) {
        fail("Could not obtain Sender Proxy Details");
    } catch (InstanceNotFoundException e1) {
        fail("Could not obtain Sender Proxy Details");
    } catch (ReflectionException e1) {
        fail("Could not obtain Sender Proxy Details");
    }
    attributeInfos = info.getAttributes();
    for (MBeanAttributeInfo attributeInfo : attributeInfos) {
        Object propertyValue = null;
        String propertyName = null;
        try {
            propertyName = attributeInfo.getName();
            propertyValue = mbeanServer.getAttribute(objName, propertyName);
            LogWriterUtils.getLogWriter().info("<ExpectedString> " + propertyName + " = " + propertyValue + "</ExpectedString> ");
        } catch (Exception e) {
        }
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MBeanInfo(javax.management.MBeanInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException)

Example 38 with MBeanInfo

use of javax.management.MBeanInfo in project geode by apache.

the class MBeanProxyInvocationHandler method invokeBroadcasterMethod.

/**
   * The call will delegate to Managed Node for NotificationHub to register a local listener to
   * listen for notification from the MBean
   * 
   * Moreover it will also add the client to local listener list by adding to the contained emitter.
   * 
   * @param proxy the proxy object
   * @param method method to be invoked
   * @param args method arguments
   * @return result value if any
   * @throws Exception
   */
private Object invokeBroadcasterMethod(Object proxy, Method method, Object[] args) throws Throwable {
    final String methodName = method.getName();
    final int nargs = (args == null) ? 0 : args.length;
    final Class[] paramTypes = method.getParameterTypes();
    final String[] signature = new String[paramTypes.length];
    if (methodName.equals("addNotificationListener")) {
        if (nargs != 3) {
            final String msg = "Bad arg count to addNotificationListener: " + nargs;
            throw new IllegalArgumentException(msg);
        }
        /*
       * Other inconsistencies will produce ClassCastException below.
       */
        NotificationListener listener = (NotificationListener) args[0];
        NotificationFilter filter = (NotificationFilter) args[1];
        Object handback = args[2];
        emitter.addNotificationListener(listener, filter, handback);
        delegateToFucntionService(objectName, methodName, null, signature);
        return null;
    } else if (methodName.equals("removeNotificationListener")) {
        /*
       * NullPointerException if method with no args, but that shouldn't happen because removeNL
       * does have args.
       */
        NotificationListener listener = (NotificationListener) args[0];
        switch(nargs) {
            case 1:
                emitter.removeNotificationListener(listener);
                /**
           * No need to send listener and filter details to other members. We only need to send a
           * message saying remove the listner registered for this object on your side. Fixes Bug[
           * #47075 ]
           */
                delegateToFucntionService(objectName, methodName, null, signature);
                return null;
            case 3:
                NotificationFilter filter = (NotificationFilter) args[1];
                Object handback = args[2];
                emitter.removeNotificationListener(listener, filter, handback);
                delegateToFucntionService(objectName, methodName, null, signature);
                return null;
            default:
                final String msg = "Bad arg count to removeNotificationListener: " + nargs;
                throw new IllegalArgumentException(msg);
        }
    } else if (methodName.equals("getNotificationInfo")) {
        if (args != null) {
            throw new IllegalArgumentException("getNotificationInfo has " + "args");
        }
        if (!MBeanJMXAdapter.mbeanServer.isRegistered(objectName)) {
            return new MBeanNotificationInfo[0];
        }
        /**
       * MBean info is delegated to function service as intention is to get the info of the actual
       * mbean rather than the proxy
       */
        Object obj = delegateToFucntionService(objectName, methodName, args, signature);
        if (obj instanceof String) {
            return new MBeanNotificationInfo[0];
        }
        MBeanInfo info = (MBeanInfo) obj;
        return info.getNotifications();
    } else {
        throw new IllegalArgumentException("Bad method name: " + methodName);
    }
}
Also used : MBeanNotificationInfo(javax.management.MBeanNotificationInfo) MBeanInfo(javax.management.MBeanInfo) NotificationFilter(javax.management.NotificationFilter) NotificationListener(javax.management.NotificationListener)

Example 39 with MBeanInfo

use of javax.management.MBeanInfo in project wildfly by wildfly.

the class JMXFilterTestCase method testFilter.

@Test
public void testFilter() throws Exception {
    Set<ObjectName> names = connection.queryNames(new ObjectName("*:name=test-sar-1234567890,*"), null);
    Assert.assertEquals(1, names.size());
    Assert.assertTrue(names.contains(new ObjectName("jboss:name=test-sar-1234567890,type=jmx-sar")));
    names = connection.queryNames(new ObjectName("*:subsystem=jsr77,*"), null);
    Assert.assertTrue(names.toString(), names.size() == 4);
    Assert.assertTrue(names.contains(new ObjectName("jboss.as.expr:subsystem=jsr77")));
    Assert.assertTrue(names.contains(new ObjectName("jboss.as:subsystem=jsr77")));
    Assert.assertTrue(names.contains(new ObjectName("jboss.as.expr:extension=org.jboss.as.jsr77,subsystem=jsr77")));
    Assert.assertTrue(names.contains(new ObjectName("jboss.as:extension=org.jboss.as.jsr77,subsystem=jsr77")));
    names = connection.queryNames(new ObjectName("*:j2eeType=J2EEServer,*"), null);
    Assert.assertEquals(1, names.size());
    final ObjectName name = new ObjectName("jboss.jsr77:j2eeType=J2EEServer,name=default");
    Assert.assertTrue(names.contains(name));
    MBeanInfo info = connection.getMBeanInfo(name);
    Assert.assertNotNull(info);
}
Also used : MBeanInfo(javax.management.MBeanInfo) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 40 with MBeanInfo

use of javax.management.MBeanInfo 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)

Aggregations

MBeanInfo (javax.management.MBeanInfo)154 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)87 ObjectName (javax.management.ObjectName)79 MBeanOperationInfo (javax.management.MBeanOperationInfo)38 MBeanServer (javax.management.MBeanServer)27 Test (org.junit.Test)27 Attribute (javax.management.Attribute)19 ArrayList (java.util.ArrayList)17 IntrospectionException (javax.management.IntrospectionException)16 ReflectionException (javax.management.ReflectionException)16 HashMap (java.util.HashMap)15 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 IOException (java.io.IOException)12 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)12 MBeanParameterInfo (javax.management.MBeanParameterInfo)12 MBeanServerConnection (javax.management.MBeanServerConnection)10 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 AttributeList (javax.management.AttributeList)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)9 Descriptor (javax.management.Descriptor)8