Search in sources :

Example 46 with MBeanInfo

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

the class MBeanIntrospector method getMBeanInfo.

/**
     * Return the MBeanInfo for the given resource, based on the given
     * per-interface data.
     */
final MBeanInfo getMBeanInfo(Object resource, PerInterface<M> perInterface) {
    MBeanInfo mbi = getClassMBeanInfo(resource.getClass(), perInterface);
    MBeanNotificationInfo[] notifs = findNotifications(resource);
    if (notifs == null || notifs.length == 0)
        return mbi;
    else {
        return new MBeanInfo(mbi.getClassName(), mbi.getDescription(), mbi.getAttributes(), mbi.getConstructors(), mbi.getOperations(), notifs, mbi.getDescriptor());
    }
}
Also used : MBeanNotificationInfo(javax.management.MBeanNotificationInfo) MBeanInfo(javax.management.MBeanInfo)

Example 47 with MBeanInfo

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

the class JMXResourceProvider method parse.

/**
     * Parse the path
     */
private PathInfo parse(final String path) {
    for (final String root : this.rootsWithSlash) {
        if (path.startsWith(root)) {
            final String subPath = path.substring(root.length());
            if (subPath.length() == 0) {
                return new PathInfo(true);
            }
            // MBean name / path
            String checkPath = subPath;
            String pathInfo = null;
            ObjectName objectName = null;
            MBeanInfo mbi = null;
            while (checkPath.length() > 0 && mbi == null) {
                try {
                    objectName = this.convertResourcePathToObjectName(checkPath);
                    if (objectName != null) {
                        mbi = this.mbeanServer.getMBeanInfo(objectName);
                    }
                } catch (final IntrospectionException e) {
                // ignore
                } catch (final InstanceNotFoundException e) {
                // ignore
                } catch (final ReflectionException e) {
                // ignore
                }
                if (mbi == null) {
                    final int sep = checkPath.lastIndexOf('/');
                    if (sep == -1) {
                        checkPath = "";
                        pathInfo = subPath;
                    } else {
                        checkPath = checkPath.substring(0, sep);
                        pathInfo = subPath.substring(sep + 1);
                    }
                }
            }
            final PathInfo info = new PathInfo(pathInfo);
            if (mbi != null) {
                info.objectName = objectName;
                info.mbeanInfo = mbi;
            }
            return info;
        }
    }
    for (final String root : this.roots) {
        if (path.equals(root)) {
            return new PathInfo(true);
        }
    }
    return null;
}
Also used : ReflectionException(javax.management.ReflectionException) MBeanInfo(javax.management.MBeanInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) ObjectName(javax.management.ObjectName)

Example 48 with MBeanInfo

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

the class JMXResourceProvider method listChildren.

/**
     * @see org.apache.sling.api.resource.ResourceProvider#listChildren(org.apache.sling.api.resource.Resource)
     */
public Iterator<Resource> listChildren(final Resource parent) {
    final PathInfo info = this.parse(parent.getPath());
    if (info != null) {
        if (info.isRoot || info.mbeanInfo == null) {
            // list all MBeans
            final Set<ObjectName> names = this.queryObjectNames(info.isRoot ? null : info.pathInfo);
            final Set<String> filteredNames = new HashSet<String>();
            final String prefix = (info.isRoot ? null : info.pathInfo + "/");
            for (final ObjectName name : names) {
                final String path = this.convertObjectNameToResourcePath(name);
                final String testName = (info.isRoot ? path : path.substring(prefix.length()));
                final int sep = testName.indexOf('/');
                if (sep == -1) {
                    filteredNames.add(":" + name.getCanonicalName());
                } else {
                    filteredNames.add(testName.substring(0, sep));
                }
            }
            final List<String> sortedNames = new ArrayList<String>(filteredNames);
            Collections.sort(sortedNames);
            final Iterator<String> iter = sortedNames.iterator();
            return new Iterator<Resource>() {

                private Resource next;

                {
                    seek();
                }

                private void seek() {
                    while (iter.hasNext() && this.next == null) {
                        final String name = iter.next();
                        if (name.startsWith(":")) {
                            try {
                                final ObjectName on = new ObjectName(name.substring(1));
                                final MBeanInfo info = mbeanServer.getMBeanInfo(on);
                                final String path = convertObjectNameToResourcePath(on);
                                final int sep = path.lastIndexOf('/');
                                this.next = new MBeanResource(mbeanServer, parent.getResourceResolver(), path, parent.getPath() + "/" + path.substring(sep + 1), info, on);
                            } catch (final IntrospectionException e) {
                            // ignore
                            } catch (final InstanceNotFoundException e) {
                            // ignore
                            } catch (final ReflectionException e) {
                            // ignore
                            } catch (final MalformedObjectNameException e) {
                            // ignore
                            }
                        } else {
                            this.next = new RootResource(parent.getResourceResolver(), parent.getPath() + '/' + name);
                        }
                    }
                }

                public boolean hasNext() {
                    return next != null;
                }

                public Resource next() {
                    if (next != null) {
                        final Resource rsrc = next;
                        this.next = null;
                        seek();
                        return rsrc;
                    }
                    throw new NoSuchElementException();
                }

                public void remove() {
                    throw new UnsupportedOperationException("remove");
                }
            };
        } else {
            if (info.pathInfo == null) {
                final MBeanResource parentResource;
                if (parent instanceof MBeanResource) {
                    parentResource = (MBeanResource) parent;
                } else {
                    parentResource = (MBeanResource) this.getResource(parent.getResourceResolver(), parent.getPath());
                }
                final List<Resource> list = new ArrayList<Resource>();
                list.add(new AttributesResource(parent.getResourceResolver(), parent.getPath() + "/mbean:attributes", parentResource));
                return list.iterator();
            } else if (info.pathInfo.equals("mbean:attributes")) {
                final AttributesResource parentResource;
                if (parent instanceof AttributesResource) {
                    parentResource = (AttributesResource) parent;
                } else {
                    parentResource = (AttributesResource) this.getResource(parent.getResourceResolver(), parent.getPath());
                }
                final MBeanResource parentMBeanResource = (MBeanResource) parentResource.getParent();
                final AttributeList result = parentMBeanResource.getAttributes();
                final MBeanAttributeInfo[] infos = info.mbeanInfo.getAttributes();
                final Map<String, MBeanAttributeInfo> infoMap = new HashMap<String, MBeanAttributeInfo>();
                for (final MBeanAttributeInfo i : infos) {
                    infoMap.put(i.getName(), i);
                }
                final Iterator iter = result.iterator();
                return new Iterator<Resource>() {

                    public void remove() {
                        throw new UnsupportedOperationException("remove");
                    }

                    public Resource next() {
                        final Attribute attr = (Attribute) iter.next();
                        return new AttributeResource(parent.getResourceResolver(), parent.getPath() + "/" + attr.getName(), infoMap.get(attr.getName()), attr.getValue(), parentResource);
                    }

                    public boolean hasNext() {
                        return iter.hasNext();
                    }
                };
            } else if (info.pathInfo.startsWith("mbean:attributes/")) {
                Resource checkParentResource = parent;
                if (!(checkParentResource instanceof AttributeResource) && !(checkParentResource instanceof MapResource)) {
                    checkParentResource = this.getResource(parent.getResourceResolver(), parent.getPath());
                }
                final AttributeResource parentResource;
                if (checkParentResource instanceof AttributeResource) {
                    parentResource = (AttributeResource) checkParentResource;
                } else {
                    parentResource = ((MapResource) checkParentResource).getAttributeResource();
                }
                final String attrPath = info.pathInfo.substring("mbean:attributes/".length());
                final int pos = attrPath.indexOf('/');
                final String subPath;
                if (pos == -1) {
                    subPath = null;
                } else {
                    subPath = attrPath.substring(pos + 1);
                }
                return parentResource.getChildren(parent.getPath(), subPath);
            }
        }
    }
    return null;
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) ArrayList(java.util.ArrayList) IntrospectionException(javax.management.IntrospectionException) Iterator(java.util.Iterator) HashSet(java.util.HashSet) ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) Resource(org.apache.sling.api.resource.Resource) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) NoSuchElementException(java.util.NoSuchElementException)

Example 49 with MBeanInfo

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

the class MBeanInfoInteropTest method init.

private static void init() throws Exception {
    mbai = new MBeanAttributeInfo("name", "type", "descr", true, false, false);
    mbpi = new MBeanParameterInfo("name", "type", "descr");
    MBeanParameterInfo[] params = new MBeanParameterInfo[] { mbpi };
    mbci1 = new MBeanConstructorInfo("name", "descr", null);
    mbci2 = new MBeanConstructorInfo("name", "descr", params);
    mbni1 = new MBeanNotificationInfo(null, "name", "descr");
    mbni2 = new MBeanNotificationInfo(new String[] { "type" }, "name", "descr");
    mboi1 = new MBeanOperationInfo("name", "descr", null, "type", ACTION);
    mboi2 = new MBeanOperationInfo("name", "descr", params, "type", INFO);
    mbi1 = new MBeanInfo("class", "descr", null, null, null, null);
    mbi2 = new MBeanInfo("class", "descr", new MBeanAttributeInfo[] { mbai }, new MBeanConstructorInfo[] { mbci1, mbci2 }, new MBeanOperationInfo[] { mboi1, mboi2 }, new MBeanNotificationInfo[] { mbni1, mbni2 });
    ombai1 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false);
    ombai2 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false, 5);
    ombai3 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false, 5, 1, 6);
    ombai4 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false, 5, new Integer[] { 2, 3, 5, 7 });
    ombpi1 = new OpenMBeanParameterInfoSupport("name1", "descr", INTEGER);
    ombpi2 = new OpenMBeanParameterInfoSupport("name2", "descr", INTEGER, 5);
    ombpi3 = new OpenMBeanParameterInfoSupport("name3", "descr", INTEGER, 5, 1, 6);
    ombpi4 = new OpenMBeanParameterInfoSupport("name4", "descr", INTEGER, 5, new Integer[] { 2, 3, 5, 7 });
    OpenMBeanParameterInfo[] oparams = { ombpi1, ombpi2, ombpi3, ombpi4 };
    ombci1 = new OpenMBeanConstructorInfoSupport("name", "descr", null);
    ombci2 = new OpenMBeanConstructorInfoSupport("name", "descr", oparams);
    omboi1 = new OpenMBeanOperationInfoSupport("name", "descr", null, INTEGER, ACTION);
    omboi2 = new OpenMBeanOperationInfoSupport("name", "descr", oparams, INTEGER, ACTION);
    ombi1 = new OpenMBeanInfoSupport("class", "descr", null, null, null, null);
    ombi2 = new OpenMBeanInfoSupport("class", "descr", new OpenMBeanAttributeInfo[] { ombai1, ombai2, ombai3, ombai4 }, new OpenMBeanConstructorInfo[] { ombci1, ombci2 }, new OpenMBeanOperationInfo[] { omboi1, omboi2 }, new MBeanNotificationInfo[] { mbni1, mbni2 });
    Descriptor attrd = new DescriptorSupport(new String[] { "name=name", "descriptorType=attribute" });
    mmbai1 = new ModelMBeanAttributeInfo("name", "type", "descr", true, false, false);
    mmbai2 = new ModelMBeanAttributeInfo("name", "type", "descr", true, false, false, attrd);
    Descriptor constrd = new DescriptorSupport(new String[] { "name=name", "descriptorType=operation", "role=constructor" });
    mmbci1 = new ModelMBeanConstructorInfo("name", "descr", null);
    mmbci2 = new ModelMBeanConstructorInfo("name", "descr", null, constrd);
    mmbci3 = new ModelMBeanConstructorInfo("name", "descr", params);
    mmbci4 = new ModelMBeanConstructorInfo("name", "descr", params, constrd);
    Descriptor operd = new DescriptorSupport(new String[] { "name=name", "descriptorType=operation" });
    mmboi1 = new ModelMBeanOperationInfo("name", "descr", null, "type", ACTION);
    mmboi2 = new ModelMBeanOperationInfo("name", "descr", null, "type", ACTION, operd);
    mmboi3 = new ModelMBeanOperationInfo("name", "descr", params, "type", ACTION);
    mmboi4 = new ModelMBeanOperationInfo("name", "descr", params, "type", ACTION, operd);
    Descriptor notifd = new DescriptorSupport(new String[] { "name=name", "descriptorType=notification" });
    mmbni1 = new ModelMBeanNotificationInfo(null, "name", "descr");
    mmbni2 = new ModelMBeanNotificationInfo(null, "name", "descr", notifd);
    mmbni3 = new ModelMBeanNotificationInfo(new String[] { "type" }, "name", "descr");
    mmbni4 = new ModelMBeanNotificationInfo(new String[] { "type" }, "name", "descr", notifd);
    Descriptor mbeand = new DescriptorSupport(new String[] { "name=name", "descriptorType=mbean" });
    mmbi1 = new ModelMBeanInfoSupport("class", "descr", null, null, null, null);
    mmbi2 = new ModelMBeanInfoSupport("class", "descr", null, null, null, null, mbeand);
    mmbi3 = new ModelMBeanInfoSupport("class", "descr", new ModelMBeanAttributeInfo[] { mmbai1, mmbai2 }, new ModelMBeanConstructorInfo[] { mmbci1, mmbci2, mmbci3, mmbci4 }, new ModelMBeanOperationInfo[] { mmboi1, mmboi2, mmboi3, mmboi4 }, new ModelMBeanNotificationInfo[] { mmbni1, mmbni2, mmbni3, mmbni4 });
    mmbi4 = new ModelMBeanInfoSupport("class", "descr", new ModelMBeanAttributeInfo[] { mmbai1, mmbai2 }, new ModelMBeanConstructorInfo[] { mmbci1, mmbci2, mmbci3, mmbci4 }, new ModelMBeanOperationInfo[] { mmboi1, mmboi2, mmboi3, mmboi4 }, new ModelMBeanNotificationInfo[] { mmbni1, mmbni2, mmbni3, mmbni4 }, mbeand);
    objects = new Serializable[] { mbai, mbpi, mbci1, mbci2, mbni1, mbni2, mboi1, mboi2, mbi1, mbi2, ombai1, ombai2, ombai3, ombai4, ombpi1, ombpi2, ombpi3, ombpi4, ombci1, ombci2, omboi1, omboi2, ombi1, ombi2, mmbai1, mmbai2, mmbci1, mmbci2, mmbci3, mmbci4, mmboi1, mmboi2, mmboi3, mmboi4, mmbni1, mmbni2, mmbni3, mmbni4 };
}
Also used : ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) MBeanInfo(javax.management.MBeanInfo) OpenMBeanInfoSupport(javax.management.openmbean.OpenMBeanInfoSupport) OpenMBeanParameterInfoSupport(javax.management.openmbean.OpenMBeanParameterInfoSupport) ModelMBeanConstructorInfo(javax.management.modelmbean.ModelMBeanConstructorInfo) MBeanConstructorInfo(javax.management.MBeanConstructorInfo) OpenMBeanConstructorInfo(javax.management.openmbean.OpenMBeanConstructorInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) OpenMBeanAttributeInfo(javax.management.openmbean.OpenMBeanAttributeInfo) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport) OpenMBeanOperationInfoSupport(javax.management.openmbean.OpenMBeanOperationInfoSupport) OpenMBeanParameterInfo(javax.management.openmbean.OpenMBeanParameterInfo) ModelMBeanNotificationInfo(javax.management.modelmbean.ModelMBeanNotificationInfo) ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) OpenMBeanOperationInfo(javax.management.openmbean.OpenMBeanOperationInfo) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) ModelMBeanConstructorInfo(javax.management.modelmbean.ModelMBeanConstructorInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) OpenMBeanAttributeInfo(javax.management.openmbean.OpenMBeanAttributeInfo) OpenMBeanConstructorInfo(javax.management.openmbean.OpenMBeanConstructorInfo) ModelMBeanNotificationInfo(javax.management.modelmbean.ModelMBeanNotificationInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) OpenMBeanConstructorInfoSupport(javax.management.openmbean.OpenMBeanConstructorInfoSupport) Descriptor(javax.management.Descriptor) OpenMBeanAttributeInfoSupport(javax.management.openmbean.OpenMBeanAttributeInfoSupport) OpenMBeanOperationInfo(javax.management.openmbean.OpenMBeanOperationInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo) OpenMBeanParameterInfo(javax.management.openmbean.OpenMBeanParameterInfo)

Example 50 with MBeanInfo

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

the class MustBeValidCommand method main.

public static void main(String[] args) throws Exception {
    // Instantiate the MBean server
    //
    final MBeanAttributeInfo[] atts = makeAttInfos(attributes);
    final MBeanConstructorInfo[] ctors = makeCtorInfos(constructors);
    final MBeanOperationInfo[] ops = makeOpInfos(operations);
    final MBeanNotificationInfo[] notifs = makeNotifInfos(notificationclasses);
    for (int i = 0; i < mbeanclasses.length; i++) {
        System.out.println("Create an MBeanInfo: " + mbeanclasses[i][0]);
        final MBeanInfo mbi = new MBeanInfo(mbeanclasses[i][1], mbeanclasses[i][0], atts, ctors, ops, notifs);
    }
    // Test OK!
    //
    System.out.println("All MBeanInfo successfuly created!");
    System.out.println("Bye! Bye!");
}
Also used : MBeanConstructorInfo(javax.management.MBeanConstructorInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

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