use of javax.management.RuntimeOperationsException in project jdk8u_jdk by JetBrains.
the class MBeanInstantiator method deserialize.
/**
* De-serializes a byte array in the context of a given MBean class loader.
* <P>The class loader is the one that loaded the class with name
* "className".
* <P>The name of the class loader to be used for loading the specified
* class is specified. If null, a default one has to be provided (for a
* MBean Server, its own class loader will be used).
*
* @param className The name of the class whose class loader should
* be used for the de-serialization.
* @param data The byte array to be de-sererialized.
* @param loaderName The name of the class loader to be used for loading
* the specified class. If null, a default one has to be provided (for a
* MBean Server, its own class loader will be used).
*
* @return The de-serialized object stream.
*
* @exception InstanceNotFoundException The specified class loader MBean is
* not found.
* @exception OperationsException Any of the usual Input/Output related
* exceptions.
* @exception ReflectionException The specified class could not be loaded
* by the specified class loader.
*/
public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] data, ClassLoader loader) throws InstanceNotFoundException, OperationsException, ReflectionException {
// Check parameter validity
if (data == null) {
throw new RuntimeOperationsException(new IllegalArgumentException(), "Null data passed in parameter");
}
if (data.length == 0) {
throw new RuntimeOperationsException(new IllegalArgumentException(), "Empty data passed in parameter");
}
if (className == null) {
throw new RuntimeOperationsException(new IllegalArgumentException(), "Null className passed in parameter");
}
ReflectUtil.checkPackageAccess(className);
Class<?> theClass;
if (loaderName == null) {
// Load the class using the agent class loader
theClass = findClass(className, loader);
} else {
// Get the class loader MBean
try {
ClassLoader instance = null;
instance = getClassLoader(loaderName);
if (instance == null)
throw new ClassNotFoundException(className);
theClass = Class.forName(className, false, instance);
} catch (ClassNotFoundException e) {
throw new ReflectionException(e, "The MBean class could not be loaded by the " + loaderName.toString() + " class loader");
}
}
// Object deserialization
ByteArrayInputStream bIn;
ObjectInputStream objIn;
bIn = new ByteArrayInputStream(data);
try {
objIn = new ObjectInputStreamWithLoader(bIn, theClass.getClassLoader());
} catch (IOException e) {
throw new OperationsException("An IOException occurred trying to de-serialize the data");
}
return objIn;
}
use of javax.management.RuntimeOperationsException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method addNotificationListener.
public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException {
// ------------------------------
// ------------------------------
// ----------------
// Get listener object
// ----------------
DynamicMBean instance = getMBean(listener);
Object resource = getResource(instance);
if (!(resource instanceof NotificationListener)) {
throw new RuntimeOperationsException(new IllegalArgumentException(listener.getCanonicalName()), "The MBean " + listener.getCanonicalName() + "does not implement the NotificationListener interface");
}
// ----------------
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name + ", Listener = " + listener);
}
server.addNotificationListener(name, (NotificationListener) resource, filter, handback);
}
use of javax.management.RuntimeOperationsException in project tomcat by apache.
the class BaseModelMBean method invoke.
/**
* Invoke a particular method on this MBean, and return any returned
* value.
*
* <p><strong>IMPLEMENTATION NOTE</strong> - This implementation will
* attempt to invoke this method on the MBean itself, or (if not
* available) on the managed resource object associated with this
* MBean.</p>
*
* @param name Name of the operation to be invoked
* @param params Array containing the method parameters of this operation
* @param signature Array containing the class names representing
* the signature of this operation
*
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking a method
*/
@Override
public Object invoke(String name, Object[] params, String[] signature) throws MBeanException, ReflectionException {
if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
return ((DynamicMBean) resource).invoke(name, params, signature);
}
// Validate the input parameters
if (name == null)
throw new RuntimeOperationsException(new IllegalArgumentException("Method name is null"), "Method name is null");
if (log.isDebugEnabled())
log.debug("Invoke " + name);
Method method = managedBean.getInvoke(name, params, signature, this, resource);
// Invoke the selected method on the appropriate object
Object result = null;
try {
if (method.getDeclaringClass().isAssignableFrom(this.getClass())) {
result = method.invoke(this, params);
} else {
result = method.invoke(resource, params);
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
log.error("Exception invoking method " + name, t);
if (t == null)
t = e;
if (t instanceof RuntimeException)
throw new RuntimeOperationsException((RuntimeException) t, "Exception invoking method " + name);
else if (t instanceof Error)
throw new RuntimeErrorException((Error) t, "Error invoking method " + name);
else
throw new MBeanException((Exception) t, "Exception invoking method " + name);
} catch (Exception e) {
log.error("Exception invoking method " + name, e);
throw new MBeanException(e, "Exception invoking method " + name);
}
// FIXME - should we validate the return type?
return (result);
}
use of javax.management.RuntimeOperationsException in project tomcat by apache.
the class BaseModelMBean method setManagedResource.
/**
* Set the instance handle of the object against which we will execute
* all methods in this ModelMBean management interface.
*
* The caller can provide the mbean instance or the object name to
* the resource, if needed.
*
* @param resource The resource object to be managed
* @param type The type of reference for the managed resource
* ("ObjectReference", "Handle", "IOR", "EJBHandle", or
* "RMIReference")
*
* @exception InstanceNotFoundException if the managed resource object
* cannot be found
* @exception MBeanException if the initializer of the object throws
* an exception
* @exception RuntimeOperationsException if the managed resource or the
* resource type is <code>null</code> or invalid
*/
public void setManagedResource(Object resource, String type) throws InstanceNotFoundException, MBeanException, RuntimeOperationsException {
if (resource == null)
throw new RuntimeOperationsException(new IllegalArgumentException("Managed resource is null"), "Managed resource is null");
// if (!"objectreference".equalsIgnoreCase(type))
// throw new InvalidTargetObjectTypeException(type);
this.resource = resource;
this.resourceType = resource.getClass().getName();
// // Make the resource aware of the model mbean.
// try {
// Method m=resource.getClass().getMethod("setModelMBean",
// new Class[] {ModelMBean.class});
// if( m!= null ) {
// m.invoke(resource, new Object[] {this});
// }
// } catch( NoSuchMethodException t ) {
// // ignore
// } catch( Throwable t ) {
// log.error( "Can't set model mbean ", t );
// }
}
use of javax.management.RuntimeOperationsException in project tomcat by apache.
the class ManagedBean method getInvoke.
public Method getInvoke(String aname, Object[] params, String[] signature, BaseModelMBean bean, Object resource) throws MBeanException, ReflectionException {
Method method = null;
if (params == null)
params = new Object[0];
if (signature == null)
signature = new String[0];
if (params.length != signature.length)
throw new RuntimeOperationsException(new IllegalArgumentException("Inconsistent arguments and signature"), "Inconsistent arguments and signature");
// Acquire the ModelMBeanOperationInfo information for
// the requested operation
OperationInfo opInfo = operations.get(createOperationKey(aname, signature));
if (opInfo == null)
throw new MBeanException(new ServiceNotFoundException("Cannot find operation " + aname), "Cannot find operation " + aname);
// Prepare the signature required by Java reflection APIs
// FIXME - should we use the signature from opInfo?
Class<?>[] types = new Class[signature.length];
for (int i = 0; i < signature.length; i++) {
types[i] = BaseModelMBean.getAttributeClass(signature[i]);
}
// Locate the method to be invoked, either in this MBean itself
// or in the corresponding managed resource
// FIXME - Accessible methods in superinterfaces?
Object object = null;
Exception exception = null;
try {
object = bean;
method = object.getClass().getMethod(aname, types);
} catch (NoSuchMethodException e) {
exception = e;
}
try {
if ((method == null) && (resource != null)) {
object = resource;
method = object.getClass().getMethod(aname, types);
}
} catch (NoSuchMethodException e) {
exception = e;
}
if (method == null) {
throw new ReflectionException(exception, "Cannot find method " + aname + " with this signature");
}
return method;
}
Aggregations