Search in sources :

Example 51 with AttributeList

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

the class MX4JModelMBean method setAttributes.

public AttributeList setAttributes(AttributeList attributes) {
    if (attributes == null)
        throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_ATTRIBUTE_LIST_CANNOT_BE_NULL.toLocalizedString()));
    Logger logger = getLogger();
    AttributeList list = new AttributeList();
    for (Iterator i = attributes.iterator(); i.hasNext(); ) {
        Attribute attribute = (Attribute) i.next();
        String name = attribute.getName();
        try {
            setAttribute(attribute);
            list.add(attribute);
        } catch (Exception x) {
            if (logger.isEnabledFor(Logger.TRACE))
                logger.trace("setAttribute for attribute " + name + " failed", x);
        // And go on with the next one
        }
    }
    return list;
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) Iterator(java.util.Iterator) Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger) AttributeNotFoundException(javax.management.AttributeNotFoundException) ServiceNotFoundException(javax.management.ServiceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) ImplementationException(mx4j.ImplementationException) RuntimeOperationsException(javax.management.RuntimeOperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 52 with AttributeList

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

the class OffHeapManagementDUnitTest method setupOffHeapMonitor.

/**
   * Creates and adds a generic GaugeMonitor for an attribute of the MemberMXBean.
   *
   * @param attribute the attribute to monitor.
   * @param highThreshold the high threshold trigger.
   * @param lowThreshold the low threshold trigger.
   */
private void setupOffHeapMonitor(final String attribute, final long highThreshold, final long lowThreshold) throws JMException {
    ObjectName memberMBeanObjectName = MBeanJMXAdapter.getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember());
    assertNotNull(memberMBeanObjectName);
    ObjectName offHeapMonitorName = new ObjectName("monitors:type=Gauge,attr=" + attribute);
    mbeanServer.createMBean("javax.management.monitor.GaugeMonitor", offHeapMonitorName);
    AttributeList al = new AttributeList();
    al.add(new Attribute("ObservedObject", memberMBeanObjectName));
    al.add(new Attribute("GranularityPeriod", 500));
    al.add(new Attribute("ObservedAttribute", attribute));
    al.add(new Attribute("Notify", true));
    al.add(new Attribute("NotifyHigh", true));
    al.add(new Attribute("NotifyLow", true));
    al.add(new Attribute("HighTheshold", highThreshold));
    al.add(new Attribute("LowThreshold", lowThreshold));
    mbeanServer.setAttributes(offHeapMonitorName, al);
    mbeanServer.addNotificationListener(offHeapMonitorName, notificationListener, null, null);
    mbeanServer.invoke(offHeapMonitorName, "start", new Object[] {}, new String[] {});
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) ObjectName(javax.management.ObjectName)

Example 53 with AttributeList

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

the class JMXDataUpdater method updateClusterRegion.

/**
   * function used to get attribute values of Cluster Region and map them to cluster region vo
   * 
   * @param mbeanName Cluster Region MBean
   */
private void updateClusterRegion(ObjectName mbeanName) throws IOException {
    try {
        AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.REGION_MBEAN_ATTRIBUTES);
        // retrieve the full path of the region
        String regionObjectName = mbeanName.getKeyProperty("name");
        String regionFullPath = null;
        for (int i = 0; i < attributeList.size(); i++) {
            Attribute attribute = (Attribute) attributeList.get(i);
            if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_FULLPATH)) {
                regionFullPath = getStringAttribute(attribute.getValue(), attribute.getName());
                break;
            }
        }
        Cluster.Region region = cluster.getClusterRegions().get(regionFullPath);
        if (null == region) {
            region = new Cluster.Region();
        }
        for (int i = 0; i < attributeList.size(); i++) {
            Attribute attribute = (Attribute) attributeList.get(i);
            String name = attribute.getName();
            switch(name) {
                case PulseConstants.MBEAN_ATTRIBUTE_MEMBERS:
                    String[] memName = (String[]) attribute.getValue();
                    region.getMemberName().clear();
                    for (int k = 0; k < memName.length; k++) {
                        region.getMemberName().add(memName[k]);
                    }
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_FULLPATH:
                    region.setFullPath(getStringAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE:
                    region.setDiskReadsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE:
                    region.setDiskWritesRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_EMPTYNODES:
                    region.setEmptyNode(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_GETSRATE:
                    region.setGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_LRUEVICTIONRATE:
                    region.setLruEvictionRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE:
                    region.setPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_REGIONTYPE:
                    region.setRegionType(getStringAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE:
                    region.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_SYSTEMREGIONENTRYCOUNT:
                    region.setSystemRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT:
                    region.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_PERSISTENTENABLED:
                    region.setPersistentEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NAME:
                    region.setName(getStringAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_GATEWAYENABLED:
                    region.setWanEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_DISKUSAGE:
                    region.setDiskUsage(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
            }
        }
        // add for each member
        updateRegionOnMembers(regionObjectName, regionFullPath, region);
        cluster.addClusterRegion(regionFullPath, region);
        cluster.getDeletedRegions().remove(region.getFullPath());
        // Memory Reads and writes
        region.getPutsPerSecTrend().add(region.getPutsRate());
        region.getGetsPerSecTrend().add(region.getGetsRate());
        // Disk Reads and Writes
        region.getDiskReadsPerSecTrend().add(region.getDiskReadsRate());
        region.getDiskWritesPerSecTrend().add(region.getDiskWritesRate());
    } catch (InstanceNotFoundException | ReflectionException infe) {
        logger.warn(infe);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) InstanceNotFoundException(javax.management.InstanceNotFoundException)

Example 54 with AttributeList

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

the class Sling method startup.

// ---------- BundleActivator ----------------------------------------------
/**
     * Called when the OSGi framework is being started. This implementation
     * registers as a service listener for the
     * <code>javax.servlet.Servlet</code> class and calls the
     * {@link #doStartBundle()} method for implementations to execute more
     * startup tasks. Additionally the <code>context</code> URL protocol
     * handler is registered.
     *
     * @param bundleContext The <code>BundleContext</code> of the system
     *            bundle of the OSGi framework.
     * @throws BundleException May be thrown if the {@link #doStartBundle()} throws.
     */
private final void startup(BundleContext bundleContext) {
    // register the context URL handler
    Hashtable<String, Object> props = new Hashtable<String, Object>();
    props.put(URLConstants.URL_HANDLER_PROTOCOL, new String[] { "context" });
    ContextProtocolHandler contextHandler = new ContextProtocolHandler(this.resourceProvider);
    bundleContext.registerService(URLStreamHandlerService.class.getName(), contextHandler, props);
    // register the platform MBeanServer
    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) {
        logger.log(Logger.LOG_INFO, "start: Cannot set service properties of Platform MBeanServer service, registering without", je);
    }
    bundleContext.registerService(MBeanServer.class.getName(), platformMBeanServer, mbeanProps);
    bundleContext.registerService(LaunchpadContentProvider.class.getName(), resourceProvider, null);
}
Also used : URLStreamHandlerService(org.osgi.service.url.URLStreamHandlerService) LaunchpadContentProvider(org.apache.sling.launchpad.api.LaunchpadContentProvider) Attribute(javax.management.Attribute) Hashtable(java.util.Hashtable) AttributeList(javax.management.AttributeList) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 55 with AttributeList

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

the class JMXResourceProvider method getResource.

/**
     * @see org.apache.sling.api.resource.ResourceProvider#getResource(org.apache.sling.api.resource.ResourceResolver, java.lang.String)
     */
public Resource getResource(final ResourceResolver resourceResolver, final String path) {
    final PathInfo info = this.parse(path);
    if (info != null) {
        if (info.isRoot) {
            return new RootResource(resourceResolver, path);
        }
        if (info.mbeanInfo == null) {
            final Set<ObjectName> names = this.queryObjectNames(info.pathInfo);
            if (names.size() != 0) {
                return new RootResource(resourceResolver, path);
            }
        } else {
            if (info.pathInfo == null) {
                return new MBeanResource(this.mbeanServer, resourceResolver, this.convertObjectNameToResourcePath(info.objectName), path, info.mbeanInfo, info.objectName);
            }
            if (info.pathInfo.equals("mbean:attributes")) {
                final MBeanResource parent = (MBeanResource) this.getResource(resourceResolver, ResourceUtil.getParent(path));
                return new AttributesResource(resourceResolver, path, parent);
            }
            if (info.pathInfo.startsWith("mbean:attributes/")) {
                final Resource parentRsrc = this.getResource(resourceResolver, ResourceUtil.getParent(path));
                final AttributesResource parentAttributesResource;
                final MBeanResource parentMBeanResource;
                if (parentRsrc instanceof AttributesResource) {
                    parentAttributesResource = (AttributesResource) parentRsrc;
                    parentMBeanResource = (MBeanResource) parentRsrc.getParent();
                } else {
                    final AttributeResource parent;
                    if (parentRsrc instanceof AttributeResource) {
                        parent = (AttributeResource) parentRsrc;
                    } else {
                        parent = ((MapResource) parentRsrc).getAttributeResource();
                    }
                    parentAttributesResource = (AttributesResource) parent.getParent();
                    parentMBeanResource = (MBeanResource) parentAttributesResource.getParent();
                }
                final AttributeList result = parentMBeanResource.getAttributes();
                final String attrPath = info.pathInfo.substring("mbean:attributes/".length());
                final int pos = attrPath.indexOf('/');
                final String attrName;
                final String subPath;
                if (pos == -1) {
                    attrName = attrPath;
                    subPath = null;
                } else {
                    attrName = attrPath.substring(0, pos);
                    subPath = attrPath.substring(pos + 1);
                }
                for (final MBeanAttributeInfo mai : info.mbeanInfo.getAttributes()) {
                    if (mai.getName().equals(attrName)) {
                        final Iterator iter = result.iterator();
                        Object value = null;
                        while (iter.hasNext() && value == null) {
                            final Attribute a = (Attribute) iter.next();
                            if (a.getName().equals(attrName)) {
                                value = a.getValue();
                            }
                        }
                        final AttributeResource rsrc = new AttributeResource(resourceResolver, path, mai, value, parentAttributesResource);
                        if (subPath != null) {
                            return rsrc.getChildResource(subPath);
                        }
                        return rsrc;
                    }
                }
            }
        }
    }
    return null;
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) Resource(org.apache.sling.api.resource.Resource) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Iterator(java.util.Iterator)

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