Search in sources :

Example 21 with AttributeList

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

the class JMXDataUpdater method initGatewayReceiver.

/**
   * function used to get attribute values of Gateway Receiver and map them to GatewayReceiver inner
   * class object
   * 
   * @return GatewayReceiver object
   */
private Cluster.GatewayReceiver initGatewayReceiver(ObjectName mbeanName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException, AttributeNotFoundException, MBeanException {
    Cluster.GatewayReceiver gatewayReceiver = new Cluster.GatewayReceiver();
    AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.GATEWAY_MBEAN_ATTRIBUTES);
    for (int i = 0; i < attributeList.size(); i++) {
        Attribute attribute = (Attribute) attributeList.get(i);
        if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PORT)) {
            gatewayReceiver.setListeningPort(getIntegerAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_EVENTRECEIVEDDATE)) {
            gatewayReceiver.setLinkThroughput(getDoubleAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVEARGEBATCHPROCESSINGTIME)) {
            gatewayReceiver.setAvgBatchProcessingTime(getLongAttribute(attribute.getValue(), attribute.getName()));
        } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_RUNNING)) {
            gatewayReceiver.setStatus(getBooleanAttribute(attribute.getValue(), attribute.getName()));
        }
    }
    return gatewayReceiver;
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList)

Example 22 with AttributeList

use of javax.management.AttributeList in project jackrabbit-oak by apache.

the class OakOSGiRepositoryFactory method registerMBeanServer.

/**
     * Registers the Platform MBeanServer as OSGi service. This would enable
     * Aries JMX Whitboard support to then register the JMX MBean which are registered as OSGi service
     * to be registered against the MBean server
     */
private static void registerMBeanServer(PojoServiceRegistry registry) {
    MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    Hashtable<String, Object> mbeanProps = new Hashtable<String, Object>();
    try {
        ObjectName beanName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
        AttributeList attrs = platformMBeanServer.getAttributes(beanName, new String[] { "MBeanServerId", "SpecificationName", "SpecificationVersion", "SpecificationVendor", "ImplementationName", "ImplementationVersion", "ImplementationVendor" });
        for (Object object : attrs) {
            Attribute attr = (Attribute) object;
            if (attr.getValue() != null) {
                mbeanProps.put(attr.getName(), attr.getValue().toString());
            }
        }
    } catch (Exception je) {
        log.info("Cannot set service properties of Platform MBeanServer service, registering without", je);
    }
    registry.registerService(MBeanServer.class.getName(), platformMBeanServer, mbeanProps);
}
Also used : Attribute(javax.management.Attribute) Hashtable(java.util.Hashtable) AttributeList(javax.management.AttributeList) TimeoutException(java.util.concurrent.TimeoutException) RepositoryException(javax.jcr.RepositoryException) BundleException(org.osgi.framework.BundleException) ExecutionException(java.util.concurrent.ExecutionException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 23 with AttributeList

use of javax.management.AttributeList in project sling by apache.

the class HealthCheckMBean method getAttribute.

@Override
public Object getAttribute(final String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    // we should call getAttributes - and not vice versa to have the result
    // of a single check call - and not do a check call for each attribute
    final AttributeList result = this.getAttributes(new String[] { attribute });
    if (result.size() == 0) {
        throw new AttributeNotFoundException(attribute);
    }
    final Attribute attr = (Attribute) result.get(0);
    return attr.getValue();
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList)

Example 24 with AttributeList

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

the class LogStoreParticipantRefreshHandler method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    MBeanServer mbs = TransactionExtension.getMBeanServer(context);
    final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    try {
        final ObjectName on = LogStoreResource.getObjectName(resource);
        final ModelNode model = resource.getModel().clone();
        AttributeList attributes = mbs.getAttributes(on, LogStoreConstants.PARTICIPANT_JMX_NAMES);
        for (javax.management.Attribute attribute : attributes.asList()) {
            String modelName = LogStoreConstants.jmxNameToModelName(LogStoreConstants.MODEL_TO_JMX_PARTICIPANT_NAMES, attribute.getName());
            if (modelName != null) {
                ModelNode aNode = model.get(modelName);
                Object value = attribute.getValue();
                if (aNode != null)
                    aNode.set(value == null ? "" : value.toString());
            }
        }
        // Replace the model
        resource.writeModel(model);
    } catch (Exception e) {
        throw new OperationFailedException("JMX error: " + e.getMessage());
    }
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : AttributeList(javax.management.AttributeList) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 25 with AttributeList

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

Aggregations

AttributeList (javax.management.AttributeList)56 Attribute (javax.management.Attribute)46 ReflectionException (javax.management.ReflectionException)22 AttributeNotFoundException (javax.management.AttributeNotFoundException)16 InstanceNotFoundException (javax.management.InstanceNotFoundException)16 MBeanException (javax.management.MBeanException)15 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)14 ObjectName (javax.management.ObjectName)14 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)10 MBeanServer (javax.management.MBeanServer)8 IOException (java.io.IOException)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 MBeanInfo (javax.management.MBeanInfo)7 RuntimeOperationsException (javax.management.RuntimeOperationsException)7 HashMap (java.util.HashMap)6 MalformedObjectNameException (javax.management.MalformedObjectNameException)6 ListenerNotFoundException (javax.management.ListenerNotFoundException)5 MBeanRegistrationException (javax.management.MBeanRegistrationException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)4