本文整理汇总了Java中javax.management.ReflectionException类的典型用法代码示例。如果您正苦于以下问题:Java ReflectionException类的具体用法?Java ReflectionException怎么用?Java ReflectionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReflectionException类属于javax.management包,在下文中一共展示了ReflectionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProcessCpuLoad
import javax.management.ReflectionException; //导入依赖的package包/类
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;
}
示例2: testNoAccessWithWhoever
import javax.management.ReflectionException; //导入依赖的package包/类
/**
* 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);
}
示例3: getProcessCpuLoad
import javax.management.ReflectionException; //导入依赖的package包/类
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);
}
示例4: loadClass
import javax.management.ReflectionException; //导入依赖的package包/类
/**
* 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;
}
示例5: invoke
import javax.management.ReflectionException; //导入依赖的package包/类
/**
* 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");
}
示例6: createMBean
import javax.management.ReflectionException; //导入依赖的package包/类
/**
* 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);
}
}
示例7: setAttributes
import javax.management.ReflectionException; //导入依赖的package包/类
@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;
}
示例8: findClass
import javax.management.ReflectionException; //导入依赖的package包/类
/**
* 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);
}
示例9: setAttribute
import javax.management.ReflectionException; //导入依赖的package包/类
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);
}
示例10: invokeOperationInternal
import javax.management.ReflectionException; //导入依赖的package包/类
/**
* 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);
}
示例11: getAttribute
import javax.management.ReflectionException; //导入依赖的package包/类
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
try {
return mbsc.getAttribute(objectName, attribute);
} catch (Exception ex) {
throw new MBeanException(ex);
}
}
示例12: getAttribute
import javax.management.ReflectionException; //导入依赖的package包/类
@Override
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
try {
return folder.getProperty(attribute).getValue();
} catch (IntrospectionException ex) {
throw new MBeanException(ex);
}
}
示例13: setAttribute
import javax.management.ReflectionException; //导入依赖的package包/类
@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);
}
}
示例14: createMBean
import javax.management.ReflectionException; //导入依赖的package包/类
@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...");
}
示例15: createMBean
import javax.management.ReflectionException; //导入依赖的package包/类
/**
* 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);
}
}