Search in sources :

Example 21 with ReflectionException

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

the class JMXDataUpdater method updateMemberRegion.

/**
   * function used to get attribute values of Member Region and map them to Member vo
   * 
   * @param mbeanName Member Region MBean
   */
private void updateMemberRegion(ObjectName mbeanName) throws IOException {
    try {
        String memberName = mbeanName.getKeyProperty(PulseConstants.MBEAN_KEY_PROPERTY_MEMBER);
        Cluster.Member member = cluster.getMembersHMap().get(memberName);
        // Following attributes are not present in 9.0
        // "Members"
        // "EmptyNodes"
        // "SystemRegionEntryCount"
        // "MemberCount"
        AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.REGION_MBEAN_ATTRIBUTES);
        // retrieve the full path of the region
        String regionFullPathKey = null;
        for (int i = 0; i < attributeList.size(); i++) {
            Attribute attribute = (Attribute) attributeList.get(i);
            if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_FULLPATH)) {
                regionFullPathKey = getStringAttribute(attribute.getValue(), attribute.getName());
                break;
            }
        }
        // if member does not exists defined for this region then create a member
        if (null == member) {
            member = new Cluster.Member();
            member.setName(memberName);
            cluster.getMembersHMap().put(memberName, member);
        }
        // if region with given path exists then update same else add new region
        Cluster.Region region = member.getMemberRegions().get(regionFullPathKey);
        if (null == region) {
            region = new Cluster.Region();
            member.getMemberRegions().put(regionFullPathKey, region);
            member.setTotalRegionCount(member.getTotalRegionCount() + 1);
        }
        // use already retrieved values
        region.setFullPath(regionFullPathKey);
        // update the existing or new 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_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_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_MEMBERCOUNT:
                    region.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE:
                    region.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_ENTRYCOUNT:
                    region.setSystemRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NAME:
                    region.setName(getStringAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_PERSISTENTENABLED:
                    region.setPersistentEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_GATEWAYENABLED:
                    region.setWanEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
                    break;
            }
        }
    /*
       * GemfireXD related code try{// Added for Rolling upgrade changes. Needs to removed once
       * Rolling upgrade handled gracefully CompositeData compositeData = (CompositeData)
       * (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_LISTREGIONATTRIBUTES, null,
       * null));
       * 
       * if (compositeData != null) { if
       * (compositeData.containsKey(PulseConstants.COMPOSITE_DATA_KEY_SCOPE)) {
       * region.setScope((String) compositeData .get(PulseConstants.COMPOSITE_DATA_KEY_SCOPE)); }
       * else if (compositeData .containsKey(PulseConstants.COMPOSITE_DATA_KEY_DISKSTORENAME)) {
       * region.setDiskStoreName((String) compositeData
       * .get(PulseConstants.COMPOSITE_DATA_KEY_DISKSTORENAME)); } else if (compositeData
       * .containsKey(PulseConstants.COMPOSITE_DATA_KEY_DISKSYNCHRONOUS)) {
       * region.setDiskSynchronous((Boolean) compositeData
       * .get(PulseConstants.COMPOSITE_DATA_KEY_DISKSYNCHRONOUS)); } } }catch (MBeanException anfe)
       * { logger.warn(anfe); }catch (javax.management.RuntimeMBeanException anfe) {
       * region.setScope(""); region.setDiskStoreName(""); region.setDiskSynchronous(false);
       * //logger.
       * warning("Some of the Pulse elements are not available currently. There might be a GemFire upgrade going on."
       * ); }
       * 
       * 
       * // Remove deleted regions from member's regions list for (Iterator<String> it =
       * cluster.getDeletedRegions().iterator(); it .hasNext();) { String deletedRegion = it.next();
       * if (member.getMemberRegions().get(deletedRegion) != null) {
       * member.getMemberRegions().remove(deletedRegion); }
       * member.setTotalRegionCount(member.getMemberRegions().size()); }
       */
    } 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 22 with ReflectionException

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

the class JMXDataUpdater method updateClusterSystem.

/**
   * function used to get attribute values of Cluster System and map them to cluster vo
   * 
   * @param mbeanName Cluster System MBean
   */
private void updateClusterSystem(ObjectName mbeanName) throws IOException {
    try {
        if (!this.isAddedNotiListner) {
            this.mbs.addNotificationListener(mbeanName, this, null, new Object());
            this.isAddedNotiListner = true;
        }
        String[] serverCnt = (String[]) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_LISTSERVERS, null, null));
        cluster.setServerCount(serverCnt.length);
        TabularData table = (TabularData) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_VIEWREMOTECLUSTERSTATUS, null, null));
        Collection<CompositeData> rows = (Collection<CompositeData>) table.values();
        cluster.getWanInformationObject().clear();
        for (CompositeData row : rows) {
            final Object key = row.get("key");
            final Object value = row.get("value");
            cluster.getWanInformationObject().put((String) key, (Boolean) value);
        }
        AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.CLUSTER_MBEAN_ATTRIBUTES);
        for (int i = 0; i < attributeList.size(); i++) {
            Attribute attribute = (Attribute) attributeList.get(i);
            String name = attribute.getName();
            switch(name) {
                case PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT:
                    cluster.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMCLIENTS:
                    cluster.setClientConnectionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_DISTRIBUTEDSYSTEMID:
                    cluster.setClusterId(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_LOCATORCOUNT:
                    cluster.setLocatorCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMRUNNIGFUNCTION:
                    try {
                        cluster.setRunningFunctionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    } catch (Exception e) {
                        cluster.setRunningFunctionCount(0);
                        continue;
                    }
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_REGISTEREDCQCOUNT:
                    cluster.setRegisteredCQCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMSUBSCRIPTIONS:
                    cluster.setSubscriptionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNCOMMITTED:
                    cluster.setTxnCommittedCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNROLLBACK:
                    cluster.setTxnRollbackCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_TOTALHEAPSIZE:
                    cluster.setTotalHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_USEDHEAPSIZE:
                    try {
                        cluster.setUsedHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
                    } catch (Exception e) {
                        cluster.setUsedHeapSize((long) 0);
                        continue;
                    }
                    cluster.getMemoryUsageTrend().add(cluster.getUsedHeapSize());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONENTRYCOUNT:
                    cluster.setTotalRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_CURRENTENTRYCOUNT:
                    cluster.setCurrentQueryCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_TOTALDISKUSAGE:
                    try {
                        cluster.setTotalBytesOnDisk(getLongAttribute(attribute.getValue(), attribute.getName()));
                    } catch (Exception e) {
                        cluster.setTotalBytesOnDisk((long) 0);
                        continue;
                    }
                    cluster.getTotalBytesOnDiskTrend().add(cluster.getTotalBytesOnDisk());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE:
                    cluster.setDiskWritesRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    cluster.getThroughoutWritesTrend().add(cluster.getDiskWritesRate());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES:
                    try {
                        cluster.setWritePerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    } catch (Exception e) {
                        cluster.setWritePerSec(0);
                        continue;
                    }
                    cluster.getWritePerSecTrend().add(cluster.getWritePerSec());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS:
                    try {
                        cluster.setReadPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    } catch (Exception e) {
                        cluster.setReadPerSec(0);
                        continue;
                    }
                    cluster.getReadPerSecTrend().add(cluster.getReadPerSec());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_QUERYREQUESTRATE:
                    cluster.setQueriesPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    cluster.getQueriesPerSecTrend().add(cluster.getQueriesPerSec());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE:
                    cluster.setDiskReadsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                    cluster.getThroughoutReadsTrend().add(cluster.getDiskReadsRate());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_JVMPAUSES:
                    long trendVal = determineCurrentJVMPauses(PulseConstants.JVM_PAUSES_TYPE_CLUSTER, "", getLongAttribute(attribute.getValue(), attribute.getName()));
                    cluster.setGarbageCollectionCount(trendVal);
                    cluster.getGarbageCollectionTrend().add(cluster.getGarbageCollectionCount());
                    break;
                case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONCOUNT:
                    cluster.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                    break;
            }
        }
    } catch (InstanceNotFoundException | ReflectionException | MBeanException infe) {
        logger.warn(infe);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) CompositeData(javax.management.openmbean.CompositeData) InstanceNotFoundException(javax.management.InstanceNotFoundException) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) TabularData(javax.management.openmbean.TabularData) Collection(java.util.Collection) MBeanException(javax.management.MBeanException)

Example 23 with ReflectionException

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

the class JMXDataUpdater method updateRegionOnMembers.

/**
   * Add member specific region information on the region
   * 
   * @param regionObjectName: used to construct the jmx objectname. For region name that has special
   *        characters in, it will have double quotes around it.
   */
private void updateRegionOnMembers(String regionObjectName, String regionFullPath, Cluster.Region region) throws IOException {
    try {
        List<String> memberNamesTemp = region.getMemberName();
        ArrayList<String> memberNames = new ArrayList<String>(memberNamesTemp);
        List<Cluster.RegionOnMember> regionOnMemberList = new ArrayList<Cluster.RegionOnMember>();
        List<Cluster.RegionOnMember> regionOnMemberListNew = new ArrayList<Cluster.RegionOnMember>();
        Cluster.RegionOnMember[] regionOnMemberNames = region.getRegionOnMembers();
        if ((regionOnMemberNames != null) && (regionOnMemberNames.length > 0)) {
            regionOnMemberList = new ArrayList<Cluster.RegionOnMember>(Arrays.asList(regionOnMemberNames));
        }
        logger.debug("updateRegionOnMembers : # regionOnMembers objects in region = {}", regionOnMemberList.size());
        for (Cluster.RegionOnMember anRom : regionOnMemberList) {
            for (String memberName : memberNames) {
                if (anRom.getMemberName().equals(memberName)) {
                    // Add regionOnMember object in new list
                    regionOnMemberListNew.add(anRom);
                    logger.debug("updateRegionOnMembers : Processing existing Member name = {}", anRom.getMemberName());
                    String objectNameROM = PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_REGION + regionObjectName + PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_MEMBER + anRom.getMemberName();
                    ObjectName regionOnMemberMBean = new ObjectName(objectNameROM);
                    logger.debug("updateRegionOnMembers : Object name = {}", regionOnMemberMBean.getCanonicalName());
                    AttributeList attributeList = this.mbs.getAttributes(regionOnMemberMBean, PulseConstants.REGION_ON_MEMBER_MBEAN_ATTRIBUTES);
                    for (int i = 0; i < attributeList.size(); i++) {
                        Attribute attribute = (Attribute) attributeList.get(i);
                        String name = attribute.getName();
                        switch(name) {
                            case PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE:
                                anRom.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName()));
                                logger.debug("updateRegionOnMembers : anRom.getEntrySize() = {}", anRom.getEntrySize());
                                break;
                            case PulseConstants.MBEAN_ATTRIBUTE_ENTRYCOUNT:
                                anRom.setEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                                logger.debug("updateRegionOnMembers : anRom.getEntryCount() = {}", anRom.getEntryCount());
                                break;
                            case PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE:
                                anRom.setPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                                logger.debug("updateRegionOnMembers : anRom.getPutsRate() = {}", anRom.getPutsRate());
                                break;
                            case PulseConstants.MBEAN_ATTRIBUTE_GETSRATE:
                                anRom.setGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                                logger.debug("updateRegionOnMembers : anRom.getGetsRate() = {}", anRom.getGetsRate());
                                break;
                            case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE:
                                anRom.setDiskGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                                logger.debug("updateRegionOnMembers : anRom.getDiskGetsRate() = {}", anRom.getDiskGetsRate());
                                break;
                            case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE:
                                anRom.setDiskPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                                logger.debug("updateRegionOnMembers : anRom.getDiskPutsRate() = {}", anRom.getDiskPutsRate());
                                break;
                            case PulseConstants.MBEAN_ATTRIBUTE_LOCALMAXMEMORY:
                                anRom.setLocalMaxMemory(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                                logger.debug("updateRegionOnMembers : anRom.getLocalMaxMemory() = {}", anRom.getLocalMaxMemory());
                                break;
                        }
                    }
                    anRom.getGetsPerSecTrend().add(anRom.getGetsRate());
                    anRom.getPutsPerSecTrend().add(anRom.getPutsRate());
                    anRom.getDiskReadsPerSecTrend().add(anRom.getDiskGetsRate());
                    anRom.getDiskWritesPerSecTrend().add(anRom.getDiskPutsRate());
                    logger.debug("updateRegionOnMembers : Existing member on region : getGetsRate() = {}, getPutsRate() = {}, getDiskGetsRate() = {}, getDiskPutsRate() = {}", anRom.getGetsPerSecTrend().size(), anRom.getPutsPerSecTrend().size(), anRom.getDiskReadsPerSecTrend().size(), anRom.getDiskWritesPerSecTrend().size());
                    // remove existing member names from list so only new ones will remain
                    memberNames.remove(anRom.getMemberName());
                    break;
                }
            }
        }
        logger.debug("updateRegionOnMembers : Loop over remaining member names and adding new member in region. Existing count = {}", regionOnMemberList.size());
        logger.debug("updateRegionOnMembers : Remaining new members in this region = {}", memberNames.size());
        // loop over the remaining regions members and add new members for this region
        for (String memberName : memberNames) {
            String objectNameROM = PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_REGION + regionObjectName + PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_MEMBER + memberName;
            ObjectName regionOnMemberMBean = new ObjectName(objectNameROM);
            Cluster.RegionOnMember regionOnMember = new Cluster.RegionOnMember();
            regionOnMember.setMemberName(memberName);
            regionOnMember.setRegionFullPath(regionFullPath);
            AttributeList attributeList = this.mbs.getAttributes(regionOnMemberMBean, PulseConstants.REGION_ON_MEMBER_MBEAN_ATTRIBUTES);
            for (int i = 0; i < attributeList.size(); i++) {
                Attribute attribute = (Attribute) attributeList.get(i);
                String name = attribute.getName();
                switch(name) {
                    case PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE:
                        regionOnMember.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName()));
                        break;
                    case PulseConstants.MBEAN_ATTRIBUTE_ENTRYCOUNT:
                        regionOnMember.setEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                        break;
                    case PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE:
                        regionOnMember.setPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                        break;
                    case PulseConstants.MBEAN_ATTRIBUTE_GETSRATE:
                        regionOnMember.setGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                        break;
                    case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE:
                        regionOnMember.setDiskGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                        break;
                    case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE:
                        regionOnMember.setDiskPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                        break;
                    case PulseConstants.MBEAN_ATTRIBUTE_LOCALMAXMEMORY:
                        regionOnMember.setLocalMaxMemory(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                        break;
                }
            }
            regionOnMember.getGetsPerSecTrend().add(regionOnMember.getGetsRate());
            regionOnMember.getPutsPerSecTrend().add(regionOnMember.getPutsRate());
            regionOnMember.getDiskReadsPerSecTrend().add(regionOnMember.getDiskGetsRate());
            regionOnMember.getDiskWritesPerSecTrend().add(regionOnMember.getDiskPutsRate());
            logger.debug("updateRegionOnMembers : Adding New member on region : getGetsRate() = {}, getPutsRate() = {}, getDiskGetsRate() = {}, getDiskPutsRate() = {}", regionOnMember.getGetsRate(), regionOnMember.getPutsRate(), regionOnMember.getDiskGetsRate(), regionOnMember.getDiskPutsRate());
            regionOnMemberListNew.add(regionOnMember);
        }
        // set region on member
        region.setRegionOnMembers(regionOnMemberListNew);
        logger.debug("updateRegionOnMembers : Total regions on member in region after update = {}", region.getFullPath(), region.getRegionOnMembers().length);
    } catch (MalformedObjectNameException | InstanceNotFoundException | ReflectionException e) {
        logger.warn(e);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) InstanceNotFoundException(javax.management.InstanceNotFoundException) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName)

Example 24 with ReflectionException

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

the class MBeanInstantiator method instantiate.

/**
     * Instantiates an object given its class, the parameters and
     * signature of its constructor The call returns a reference to
     * the newly created object.
     */
public Object instantiate(Class<?> theClass, Object[] params, String[] signature, ClassLoader loader) throws ReflectionException, MBeanException {
    checkMBeanPermission(theClass, null, null, "instantiate");
    // Instantiate the new object
    // ------------------------------
    // ------------------------------
    final Class<?>[] tab;
    Object moi;
    try {
        // Build the signature of the method
        //
        ClassLoader aLoader = theClass.getClassLoader();
        // Build the signature of the method
        //
        tab = ((signature == null) ? null : findSignatureClasses(signature, aLoader));
    }// Exception IllegalArgumentException raised in Jdk1.1.8
     catch (IllegalArgumentException e) {
        throw new ReflectionException(e, "The constructor parameter classes could not be loaded");
    }
    // Query the metadata service to get the right constructor
    Constructor<?> cons = findConstructor(theClass, tab);
    if (cons == null) {
        throw new ReflectionException(new NoSuchMethodException("No such constructor"));
    }
    try {
        ReflectUtil.checkPackageAccess(theClass);
        ensureClassAccess(theClass);
        moi = cons.newInstance(params);
    } catch (NoSuchMethodError error) {
        throw new ReflectionException(new NoSuchMethodException("No such constructor found"), "No such constructor");
    } catch (InstantiationException e) {
        throw new ReflectionException(e, "Exception thrown trying to invoke the MBean's constructor");
    } catch (IllegalAccessException e) {
        throw new ReflectionException(e, "Exception thrown trying to invoke the MBean's constructor");
    } catch (InvocationTargetException e) {
        // Wrap the exception.
        Throwable th = e.getTargetException();
        if (th instanceof RuntimeException) {
            throw new RuntimeMBeanException((RuntimeException) th, "RuntimeException thrown in the MBean's constructor");
        } else if (th instanceof Error) {
            throw new RuntimeErrorException((Error) th, "Error thrown in the MBean's constructor");
        } else {
            throw new MBeanException((Exception) th, "Exception thrown in the MBean's constructor");
        }
    }
    return moi;
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) ReflectionException(javax.management.ReflectionException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanException(javax.management.MBeanException)

Example 25 with ReflectionException

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

the class MBeanInstantiator method instantiate.

/**
     * Instantiates an object given its class, using its empty constructor.
     * The call returns a reference to the newly created object.
     */
public Object instantiate(Class<?> theClass) throws ReflectionException, MBeanException {
    checkMBeanPermission(theClass, null, null, "instantiate");
    Object moi;
    // ------------------------------
    // ------------------------------
    Constructor<?> cons = findConstructor(theClass, null);
    if (cons == null) {
        throw new ReflectionException(new NoSuchMethodException("No such constructor"));
    }
    // Instantiate the new object
    try {
        ReflectUtil.checkPackageAccess(theClass);
        ensureClassAccess(theClass);
        moi = cons.newInstance();
    } catch (InvocationTargetException e) {
        // Wrap the exception.
        Throwable t = e.getTargetException();
        if (t instanceof RuntimeException) {
            throw new RuntimeMBeanException((RuntimeException) t, "RuntimeException thrown in the MBean's empty constructor");
        } else if (t instanceof Error) {
            throw new RuntimeErrorException((Error) t, "Error thrown in the MBean's empty constructor");
        } else {
            throw new MBeanException((Exception) t, "Exception thrown in the MBean's empty constructor");
        }
    } catch (NoSuchMethodError error) {
        throw new ReflectionException(new NoSuchMethodException("No constructor"), "No such constructor");
    } catch (InstantiationException e) {
        throw new ReflectionException(e, "Exception thrown trying to invoke the MBean's empty constructor");
    } catch (IllegalAccessException e) {
        throw new ReflectionException(e, "Exception thrown trying to invoke the MBean's empty constructor");
    } catch (IllegalArgumentException e) {
        throw new ReflectionException(e, "Exception thrown trying to invoke the MBean's empty constructor");
    }
    return moi;
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) ReflectionException(javax.management.ReflectionException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanException(javax.management.MBeanException)

Aggregations

ReflectionException (javax.management.ReflectionException)72 InstanceNotFoundException (javax.management.InstanceNotFoundException)50 MBeanException (javax.management.MBeanException)46 AttributeNotFoundException (javax.management.AttributeNotFoundException)31 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)23 ObjectName (javax.management.ObjectName)22 Attribute (javax.management.Attribute)19 RuntimeOperationsException (javax.management.RuntimeOperationsException)17 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 IntrospectionException (javax.management.IntrospectionException)13 Method (java.lang.reflect.Method)12 AttributeList (javax.management.AttributeList)12 ServiceNotFoundException (javax.management.ServiceNotFoundException)12 IOException (java.io.IOException)11 MBeanInfo (javax.management.MBeanInfo)11 RuntimeErrorException (javax.management.RuntimeErrorException)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 ListenerNotFoundException (javax.management.ListenerNotFoundException)9 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)9 MBeanRegistrationException (javax.management.MBeanRegistrationException)9