Search in sources :

Example 46 with MBeanAttributeInfo

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

the class LogStoreProbeHandler method getMBeanValues.

private Map<String, String> getMBeanValues(MBeanServerConnection cnx, ObjectName on, String... attributeNames) throws InstanceNotFoundException, IOException, ReflectionException, IntrospectionException {
    if (attributeNames == null) {
        MBeanInfo info = cnx.getMBeanInfo(on);
        MBeanAttributeInfo[] attributeArray = info.getAttributes();
        int i = 0;
        attributeNames = new String[attributeArray.length];
        for (MBeanAttributeInfo ai : attributeArray) attributeNames[i++] = ai.getName();
    }
    AttributeList attributes = cnx.getAttributes(on, attributeNames);
    Map<String, String> values = new HashMap<String, String>();
    for (javax.management.Attribute attribute : attributes.asList()) {
        Object value = attribute.getValue();
        values.put(attribute.getName(), value == null ? "" : value.toString());
    }
    return values;
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) AttributeList(javax.management.AttributeList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 47 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project jdk8u_jdk by JetBrains.

the class RequiredModelMBean method removeAttributeChangeNotificationListener.

public void removeAttributeChangeNotificationListener(NotificationListener inlistener, String inAttributeName) throws MBeanException, RuntimeOperationsException, ListenerNotFoundException {
    if (inlistener == null)
        throw new ListenerNotFoundException("Notification listener is null");
    final String mth = "removeAttributeChangeNotificationListener(" + "NotificationListener, String)";
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Entry");
    }
    if (attributeBroadcaster == null)
        throw new ListenerNotFoundException("No attribute change notification listeners registered");
    MBeanAttributeInfo[] attrInfo = modelMBeanInfo.getAttributes();
    boolean found = false;
    if ((attrInfo != null) && (attrInfo.length > 0)) {
        for (int i = 0; i < attrInfo.length; i++) {
            if (attrInfo[i].getName().equals(inAttributeName)) {
                found = true;
                break;
            }
        }
    }
    if ((!found) && (inAttributeName != null)) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Invalid attribute name"), "Exception occurred trying to remove " + "attribute change notification listener");
    }
    /* note: */
    /* this may be a problem if the same listener is registered for
           multiple attributes with multiple filters and/or handback
           objects.  It may remove all of them */
    attributeBroadcaster.removeNotificationListener(inlistener);
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Exit");
    }
}
Also used : ListenerNotFoundException(javax.management.ListenerNotFoundException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 48 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project jdk8u_jdk by JetBrains.

the class RequiredModelMBean method addAttributeChangeNotificationListener.

public void addAttributeChangeNotificationListener(NotificationListener inlistener, String inAttributeName, Object inhandback) throws MBeanException, RuntimeOperationsException, IllegalArgumentException {
    final String mth = "addAttributeChangeNotificationListener(" + "NotificationListener, String, Object)";
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Entry");
    }
    if (inlistener == null)
        throw new IllegalArgumentException("Listener to be registered must not be null");
    if (attributeBroadcaster == null)
        attributeBroadcaster = new NotificationBroadcasterSupport();
    AttributeChangeNotificationFilter currFilter = new AttributeChangeNotificationFilter();
    MBeanAttributeInfo[] attrInfo = modelMBeanInfo.getAttributes();
    boolean found = false;
    if (inAttributeName == null) {
        if ((attrInfo != null) && (attrInfo.length > 0)) {
            for (int i = 0; i < attrInfo.length; i++) {
                currFilter.enableAttribute(attrInfo[i].getName());
            }
        }
    } else {
        if ((attrInfo != null) && (attrInfo.length > 0)) {
            for (int i = 0; i < attrInfo.length; i++) {
                if (inAttributeName.equals(attrInfo[i].getName())) {
                    found = true;
                    currFilter.enableAttribute(inAttributeName);
                    break;
                }
            }
        }
        if (!found) {
            throw new RuntimeOperationsException(new IllegalArgumentException("The attribute name does not exist"), "Exception occurred trying to add an " + "AttributeChangeNotification listener");
        }
    }
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        Vector<String> enabledAttrs = currFilter.getEnabledAttributes();
        String s = (enabledAttrs.size() > 1) ? "[" + enabledAttrs.firstElement() + ", ...]" : enabledAttrs.toString();
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Set attribute change filter to " + s);
    }
    attributeBroadcaster.addNotificationListener(inlistener, currFilter, inhandback);
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Notification listener added for " + inAttributeName);
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Exit");
    }
}
Also used : AttributeChangeNotificationFilter(javax.management.AttributeChangeNotificationFilter) NotificationBroadcasterSupport(javax.management.NotificationBroadcasterSupport) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 49 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project jdk8u_jdk by JetBrains.

the class MXBeanIntrospector method getMBeanAttributeInfo.

@Override
MBeanAttributeInfo getMBeanAttributeInfo(String attributeName, ConvertingMethod getter, ConvertingMethod setter) {
    final boolean isReadable = (getter != null);
    final boolean isWritable = (setter != null);
    final boolean isIs = isReadable && getName(getter).startsWith("is");
    final String description = attributeName;
    final OpenType<?> openType;
    final Type originalType;
    if (isReadable) {
        openType = getter.getOpenReturnType();
        originalType = getter.getGenericReturnType();
    } else {
        openType = setter.getOpenParameterTypes()[0];
        originalType = setter.getGenericParameterTypes()[0];
    }
    Descriptor descriptor = typeDescriptor(openType, originalType);
    if (isReadable) {
        descriptor = ImmutableDescriptor.union(descriptor, getter.getDescriptor());
    }
    if (isWritable) {
        descriptor = ImmutableDescriptor.union(descriptor, setter.getDescriptor());
    }
    final MBeanAttributeInfo ai;
    if (canUseOpenInfo(originalType)) {
        ai = new OpenMBeanAttributeInfoSupport(attributeName, description, openType, isReadable, isWritable, isIs, descriptor);
    } else {
        ai = new MBeanAttributeInfo(attributeName, originalTypeString(originalType), description, isReadable, isWritable, isIs, descriptor);
    }
    return ai;
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) OpenType(javax.management.openmbean.OpenType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor) OpenMBeanAttributeInfoSupport(javax.management.openmbean.OpenMBeanAttributeInfoSupport) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 50 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project tomee by apache.

the class StatelessInvocationStatsTest method testInvocation.

/**
     * @throws Exception
     */
public void testInvocation() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, org.apache.openejb.core.LocalInitialContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("AccessTimeout", "0");
    statelessContainerInfo.properties.setProperty("MaxSize", "2");
    statelessContainerInfo.properties.setProperty("MinSize", "0");
    statelessContainerInfo.properties.setProperty("StrictPooling", "true");
    statelessContainerInfo.properties.setProperty("IdleTimeout", "0");
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    CounterBean.instances.set(0);
    final EjbJar ejbJar = new EjbJar("StatsInvocModule");
    ejbJar.addEnterpriseBean(new StatelessBean(CounterBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    final javax.naming.Context context = new InitialContext();
    final CounterBean bean = (CounterBean) context.lookup("CounterBeanLocalBean");
    //Invoke  
    bean.waitSecs();
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final ObjectName invocationsName = new ObjectName("openejb.management:J2EEServer=openejb,J2EEApplication=<empty>,EJBModule=StatsInvocModule,StatelessSessionBean=CounterBean,j2eeType=Invocations,name=CounterBean");
    // Grab the mbeanInfo and check the expected attributes exist and have the correct return types and parameters        
    final MBeanInfo invocationsMBeanInfo = server.getMBeanInfo(invocationsName);
    for (final MBeanAttributeInfo info : invocationsMBeanInfo.getAttributes()) {
        //            System.out.println("//" + info.getName() + " " + server.getAttribute(invocationsName, info.getName()));
        if (info.getName().equals("waitSecs().GeometricMean") || info.getName().equals("waitSecs().Max") || info.getName().equals("waitSecs().Mean") || info.getName().equals("waitSecs().Min") || info.getName().equals("waitSecs().Percentile01") || info.getName().equals("waitSecs().Percentile10") || info.getName().equals("waitSecs().Percentile25") || info.getName().equals("waitSecs().Percentile50") || info.getName().equals("waitSecs().Percentile75") || info.getName().equals("waitSecs().Percentile90") || info.getName().equals("waitSecs().Percentile99") || info.getName().equals("waitSecs().Sum")) {
            final Double actual = (Double) (server.getAttribute(invocationsName, info.getName()));
            assertTrue("Expected: " + actual + " >= 999", actual >= 999);
        }
    }
    ejbJar.removeEnterpriseBean("StatsInvocModule");
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) MBeanInfo(javax.management.MBeanInfo) InitialContext(javax.naming.InitialContext) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) MBeanServer(javax.management.MBeanServer) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer)

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