java类javax.management.ReflectionException的实例源码

Utils.java 文件源码 项目:Shadbot 阅读 31 收藏 0 点赞 0 评论 0
public static double getProcessCpuLoad() {
    double cpuLoad;
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
        AttributeList list = mbs.getAttributes(name, new String[] { "ProcessCpuLoad" });

        if(list.isEmpty()) {
            return Double.NaN;
        }

        Attribute att = (Attribute) list.get(0);
        Double value = (Double) att.getValue();

        if(value == -1.0) {
            return Double.NaN;
        }

        cpuLoad = value * 100d;
    } catch (InstanceNotFoundException | ReflectionException | MalformedObjectNameException err) {
        cpuLoad = Double.NaN;
    }

    return cpuLoad;
}
MBeanSecurityJUnitTest.java 文件源码 项目:monarch 阅读 26 收藏 0 点赞 0 评论 0
/**
 * No user can call createBean or unregisterBean of GemFire Domain
 */
@Test
@ConnectionConfiguration(user = "super-user", password = "1234567")
public void testNoAccessWithWhoever() throws Exception {
  MBeanServerConnection con = connectionRule.getMBeanServerConnection();
  assertThatThrownBy(
      () -> con.createMBean("FakeClassName", new ObjectName("GemFire", "name", "foo")))
          .isInstanceOf(SecurityException.class);

  assertThatThrownBy(() -> con.unregisterMBean(new ObjectName("GemFire", "name", "foo")))
      .isInstanceOf(SecurityException.class);

  // user is allowed to create beans of other domains
  assertThatThrownBy(
      () -> con.createMBean("FakeClassName", new ObjectName("OtherDomain", "name", "foo")))
          .isInstanceOf(ReflectionException.class);
}
BrokerStatsRetriever.java 文件源码 项目:doctorkafka 阅读 27 收藏 0 点赞 0 评论 0
public static double getProcessCpuLoad(MBeanServerConnection mbs)
    throws MalformedObjectNameException, NullPointerException, InstanceNotFoundException,
           ReflectionException, IOException {
  ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
  AttributeList list = mbs.getAttributes(name, new String[]{"ProcessCpuLoad"});

  if (list.isEmpty()) {
    return 0.0;
  }

  Attribute att = (Attribute) list.get(0);
  Double value = (Double) att.getValue();

  // usually takes a couple of seconds before we get real values
  if (value == -1.0) {
    return 0.0;
  }
  // returns a percentage value with 1 decimal point precision
  return ((int) (value * 1000) / 10.0);
}
MBeanInstantiator.java 文件源码 项目:jdk8u-jdk 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Load a class with the specified loader, or with this object
 * class loader if the specified loader is null.
 **/
static Class<?> loadClass(String className, ClassLoader loader)
    throws ReflectionException {
    Class<?> theClass;
    if (className == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("The class name cannot be null"),
                          "Exception occurred during object instantiation");
    }
    ReflectUtil.checkPackageAccess(className);
    try {
        if (loader == null)
            loader = MBeanInstantiator.class.getClassLoader();
        if (loader != null) {
            theClass = Class.forName(className, false, loader);
        } else {
            theClass = Class.forName(className);
        }
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e,
        "The MBean class could not be loaded");
    }
    return theClass;
}
MBeanServerDelegateImpl.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Always fails since the MBeanServerDelegate MBean has no operation.
 *
 * @param actionName The name of the action to be invoked.
 * @param params An array containing the parameters to be set when the
 *        action is invoked.
 * @param signature An array containing the signature of the action.
 *
 * @return  The object returned by the action, which represents
 *          the result of invoking the action on the MBean specified.
 *
 * @exception MBeanException  Wraps a <CODE>java.lang.Exception</CODE>
 *         thrown by the MBean's invoked method.
 * @exception ReflectionException  Wraps a
 *      <CODE>java.lang.Exception</CODE> thrown while trying to invoke
 *      the method.
 */
public Object invoke(String actionName, Object params[],
                     String signature[])
    throws MBeanException, ReflectionException {
    // Check that operation name is not null.
    //
    if (actionName == null) {
        final RuntimeException r =
          new IllegalArgumentException("Operation name  cannot be null");
        throw new RuntimeOperationsException(r,
        "Exception occurred trying to invoke the operation on the MBean");
    }

    throw new ReflectionException(
                      new NoSuchMethodException(actionName),
                      "The operation with name " + actionName +
                      " could not be found");
}
MBeanServerAccessController.java 文件源码 项目:openjdk-jdk10 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name)
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name);
    }
}
DynamicWritableWrapper.java 文件源码 项目:hashsdn-controller 阅读 30 收藏 0 点赞 0 评论 0
@Override
public AttributeList setAttributes(final AttributeList attributes) {
    AttributeList result = new AttributeList();
    for (Object attributeObject : attributes) {
        Attribute attribute = (Attribute) attributeObject;
        try {
            setAttribute(attribute);
            result.add(attribute);
        } catch (final InvalidAttributeValueException | AttributeNotFoundException | MBeanException
                | ReflectionException e) {
            LOG.warn("Setting attribute {} failed on {}", attribute.getName(), moduleIdentifier, e);
            throw new IllegalArgumentException(
                    "Setting attribute failed - " + attribute.getName() + " on " + moduleIdentifier, e);
        }
    }
    return result;
}
MBeanInstantiator.java 文件源码 项目:OpenJSharp 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Gets the class for the specified class name using the specified
 * class loader
 */
public Class<?> findClass(String className, ObjectName aLoader)
    throws ReflectionException, InstanceNotFoundException  {

    if (aLoader == null)
        throw new RuntimeOperationsException(new
            IllegalArgumentException(), "Null loader passed in parameter");

    // Retrieve the class loader from the repository
    ClassLoader loader = null;
    synchronized (this) {
        loader = getClassLoader(aLoader);
    }
    if (loader == null) {
        throw new InstanceNotFoundException("The loader named " +
                   aLoader + " is not registered in the MBeanServer");
    }
    return findClass(className,loader);
}
PerInterface.java 文件源码 项目:OpenJSharp 阅读 26 收藏 0 点赞 0 评论 0
void setAttribute(Object resource, String attribute, Object value,
                  Object cookie)
        throws AttributeNotFoundException,
               InvalidAttributeValueException,
               MBeanException,
               ReflectionException {

    final M cm = setters.get(attribute);
    if (cm == null) {
        final String msg;
        if (getters.containsKey(attribute))
            msg = "Read-only attribute: " + attribute;
        else
            msg = "No such attribute: " + attribute;
        throw new AttributeNotFoundException(msg);
    }
    introspector.invokeSetter(attribute, cm, resource, value, cookie);
}
MBeanServerAccessController.java 文件源码 项目:OpenJSharp 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name)
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name);
    }
}
JMXProxyServlet.java 文件源码 项目:lazycat 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Invokes an operation on an MBean.
 * 
 * @param onameStr
 *            The name of the MBean.
 * @param operation
 *            The name of the operation to invoke.
 * @param parameters
 *            An array of Strings containing the parameters to the
 *            operation. They will be converted to the appropriate types to
 *            call the requested operation.
 * @return The value returned by the requested operation.
 */
private Object invokeOperationInternal(String onameStr, String operation, String[] parameters)
        throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname = new ObjectName(onameStr);
    MBeanOperationInfo methodInfo = registry.getMethodInfo(oname, operation);
    MBeanParameterInfo[] signature = methodInfo.getSignature();
    String[] signatureTypes = new String[signature.length];
    Object[] values = new Object[signature.length];
    for (int i = 0; i < signature.length; i++) {
        MBeanParameterInfo pi = signature[i];
        signatureTypes[i] = pi.getType();
        values[i] = registry.convertValue(pi.getType(), parameters[i]);
    }

    return mBeanServer.invoke(oname, operation, values, signatureTypes);
}
DynamicProxy.java 文件源码 项目:Pogamut3 阅读 38 收藏 0 点赞 0 评论 0
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    try {
        return mbsc.getAttribute(objectName, attribute);
    } catch (Exception ex) {
        throw new MBeanException(ex);
    }
}
FolderMBean.java 文件源码 项目:Pogamut3 阅读 25 收藏 0 点赞 0 评论 0
@Override
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    try {
        return folder.getProperty(attribute).getValue();
    } catch (IntrospectionException ex) {
        throw new MBeanException(ex);
    }
}
FolderMBean.java 文件源码 项目:Pogamut3 阅读 34 收藏 0 点赞 0 评论 0
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    try {
        folder.getProperty(attribute.getName()).setValue(attribute.getValue());
    } catch (IntrospectionException ex) {
        throw new MBeanException(ex);
    }
}
PogamutMBeanServer.java 文件源码 项目:Pogamut3 阅读 28 收藏 0 点赞 0 评论 0
@Override
public synchronized ObjectInstance createMBean(String className, ObjectName name,
        Object[] params, String[] signature) throws ReflectionException,
        InstanceAlreadyExistsException, MBeanRegistrationException,
        MBeanException, NotCompliantMBeanException {
    throw new UnsupportedOperationException("Not supported by PogamutMBeanServer yet...");
}
PogamutMBeanServer.java 文件源码 项目:Pogamut3 阅读 23 收藏 0 点赞 0 评论 0
@Override
public synchronized ObjectInstance createMBean(String className, ObjectName name,
        ObjectName loaderName, Object[] params, String[] signature)
        throws ReflectionException, InstanceAlreadyExistsException,
        MBeanRegistrationException, MBeanException,
        NotCompliantMBeanException, InstanceNotFoundException {
    throw new UnsupportedOperationException("Not supported by PogamutMBeanServer yet...");      
}
MBeanServerAccessController.java 文件源码 项目:jdk8u-jdk 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className,
                                  ObjectName name,
                                  ObjectName loaderName,
                                  Object params[],
                                  String signature[])
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException,
    InstanceNotFoundException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className,
                                                     loaderName,
                                                     params,
                                                     signature);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name, loaderName,
                                            params, signature);
    }
}
MBeanServerAccessController.java 文件源码 项目:jdk8u-jdk 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Call <code>checkWrite()</code>, then forward this method to the
 * wrapped object.
 */
public void setAttribute(ObjectName name, Attribute attribute)
    throws
    InstanceNotFoundException,
    AttributeNotFoundException,
    InvalidAttributeValueException,
    MBeanException,
    ReflectionException {
    checkWrite();
    getMBeanServer().setAttribute(name, attribute);
}
MBeanServerAccessController.java 文件源码 项目:OpenJSharp 阅读 32 收藏 0 点赞 0 评论 0
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public Object instantiate(String className, ObjectName loaderName,
                          Object params[], String signature[])
    throws ReflectionException, MBeanException, InstanceNotFoundException {
    checkCreate(className);
    return getMBeanServer().instantiate(className, loaderName,
                                        params, signature);
}
MBeanServerAccessController.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
@Deprecated
public ObjectInputStream deserialize(String className,
                                     ObjectName loaderName,
                                     byte[] data)
    throws
    InstanceNotFoundException,
    OperationsException,
    ReflectionException {
    checkRead();
    return getMBeanServer().deserialize(className, loaderName, data);
}
JMXProxyServlet.java 文件源码 项目:tomcat7 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Sets an MBean attribute's value.
 */
private void setAttributeInternal(String onameStr,
                                  String attributeName,
                                  String value)
    throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname=new ObjectName( onameStr );
    String type=registry.getType(oname, attributeName);
    Object valueObj=registry.convertValue(type, value );
    mBeanServer.setAttribute( oname, new Attribute(attributeName, valueObj));
}
NMSUtils.java 文件源码 项目:InventoryAPI 阅读 25 收藏 0 点赞 0 评论 0
public static Object getNMSPlayer( Player player ) throws ReflectionException
{
    try
    {
        Method method = player.getClass().getMethod( "getHandle" );
        return method.invoke( player );
    }
    catch ( NoSuchMethodException | IllegalAccessException | InvocationTargetException e )
    {
        throw new ReflectionException( e, "can't get EntityPlayer" );
    }
}
SpringModelMBean.java 文件源码 项目:lams 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Switches the {@link Thread#getContextClassLoader() context ClassLoader} for the
 * managed resources {@link ClassLoader} before allowing the invocation to occur.
 * @see javax.management.modelmbean.ModelMBean#invoke
 */
@Override
public Object invoke(String opName, Object[] opArgs, String[] sig)
        throws MBeanException, ReflectionException {

    ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(this.managedResourceClassLoader);
        return super.invoke(opName, opArgs, sig);
    }
    finally {
        Thread.currentThread().setContextClassLoader(currentClassLoader);
    }
}
MBeanServerAccessController.java 文件源码 项目:OpenJSharp 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Call <code>checkWrite()</code>, then forward this method to the
 * wrapped object.
 */
public Object invoke(ObjectName name, String operationName,
                     Object params[], String signature[])
    throws
    InstanceNotFoundException,
    MBeanException,
    ReflectionException {
    checkWrite();
    checkMLetMethods(name, operationName);
    return getMBeanServer().invoke(name, operationName, params, signature);
}
MetricsSourceAdapter.java 文件源码 项目:hadoop 阅读 96 收藏 0 点赞 0 评论 0
@Override
public Object getAttribute(String attribute)
    throws AttributeNotFoundException, MBeanException, ReflectionException {
  updateJmxCache();
  synchronized(this) {
    Attribute a = attrCache.get(attribute);
    if (a == null) {
      throw new AttributeNotFoundException(attribute +" not found");
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug(attribute +": "+ a);
    }
    return a.getValue();
  }
}
MBeanServerAccessController.java 文件源码 项目:OpenJSharp 阅读 32 收藏 0 点赞 0 评论 0
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public Object getAttribute(ObjectName name, String attribute)
    throws
    MBeanException,
    AttributeNotFoundException,
    InstanceNotFoundException,
    ReflectionException {
    checkRead();
    return getMBeanServer().getAttribute(name, attribute);
}
DynamicWritableWrapper.java 文件源码 项目:hashsdn-controller 阅读 27 收藏 0 点赞 0 评论 0
@SuppressWarnings("IllegalCatch")
@Override
public Object invoke(final String actionName, final Object[] params, final String[] signature)
        throws MBeanException, ReflectionException {
    if ("validate".equals(actionName) && (params == null || params.length == 0)
            && (signature == null || signature.length == 0)) {
        try {
            validate();
        } catch (final Exception e) {
            throw new MBeanException(ValidationException.createForSingleException(moduleIdentifier, e));
        }
        return Void.TYPE;
    }
    return super.invoke(actionName, params, signature);
}
DefaultMBeanServerInterceptor.java 文件源码 项目:OpenJSharp 阅读 36 收藏 0 点赞 0 评论 0
public ObjectInstance createMBean(String className, ObjectName name,
                                  ObjectName loaderName)
    throws ReflectionException, InstanceAlreadyExistsException,
           MBeanRegistrationException, MBeanException,
           NotCompliantMBeanException, InstanceNotFoundException {

    return createMBean(className, name, loaderName, (Object[]) null,
                       (String[]) null);
}
DefaultMBeanServerInterceptor.java 文件源码 项目:OpenJSharp 阅读 31 收藏 0 点赞 0 评论 0
public Object getAttribute(ObjectName name, String attribute)
    throws MBeanException, AttributeNotFoundException,
           InstanceNotFoundException, ReflectionException {

    if (name == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Object name cannot be null"),
            "Exception occurred trying to invoke the getter on the MBean");
    }
    if (attribute == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Attribute cannot be null"),
            "Exception occurred trying to invoke the getter on the MBean");
    }

    name = nonDefaultDomain(name);

    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER,
                DefaultMBeanServerInterceptor.class.getName(),
                "getAttribute",
                "Attribute = " + attribute + ", ObjectName = " + name);
    }

    final DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, attribute, name, "getAttribute");

    try {
        return instance.getAttribute(attribute);
    } catch (AttributeNotFoundException e) {
        throw e;
    } catch (Throwable t) {
        rethrowMaybeMBeanException(t);
        throw new AssertionError(); // not reached
    }
}
MBeanServerAccessController.java 文件源码 项目:openjdk-jdk10 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className,
                                  ObjectName name,
                                  ObjectName loaderName,
                                  Object params[],
                                  String signature[])
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException,
    InstanceNotFoundException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className,
                                                     loaderName,
                                                     params,
                                                     signature);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name, loaderName,
                                            params, signature);
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号