Search in sources :

Example 41 with RuntimeOperationsException

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;
}
Also used : ReflectionException(javax.management.ReflectionException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) RuntimeOperationsException(javax.management.RuntimeOperationsException) ObjectInputStream(java.io.ObjectInputStream) OperationsException(javax.management.OperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 42 with RuntimeOperationsException

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);
}
Also used : DynamicMBean(javax.management.DynamicMBean) NamedObject(com.sun.jmx.mbeanserver.NamedObject) NotificationListener(javax.management.NotificationListener) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 43 with RuntimeOperationsException

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);
}
Also used : DynamicMBean(javax.management.DynamicMBean) RuntimeErrorException(javax.management.RuntimeErrorException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 44 with RuntimeOperationsException

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 );
//        }
}
Also used : RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 45 with RuntimeOperationsException

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;
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) ReflectionException(javax.management.ReflectionException) Method(java.lang.reflect.Method) AttributeNotFoundException(javax.management.AttributeNotFoundException) ServiceNotFoundException(javax.management.ServiceNotFoundException) MBeanException(javax.management.MBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException) ServiceNotFoundException(javax.management.ServiceNotFoundException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

RuntimeOperationsException (javax.management.RuntimeOperationsException)68 AttributeNotFoundException (javax.management.AttributeNotFoundException)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)21 ReflectionException (javax.management.ReflectionException)20 MBeanException (javax.management.MBeanException)19 Descriptor (javax.management.Descriptor)17 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)16 ListenerNotFoundException (javax.management.ListenerNotFoundException)16 RuntimeErrorException (javax.management.RuntimeErrorException)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 ServiceNotFoundException (javax.management.ServiceNotFoundException)13 DynamicMBean (javax.management.DynamicMBean)10 FileLogger (mx4j.log.FileLogger)10 Logger (mx4j.log.Logger)10 MBeanLogger (mx4j.log.MBeanLogger)10 MBeanRegistrationException (javax.management.MBeanRegistrationException)9 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)9 JMRuntimeException (javax.management.JMRuntimeException)8 Attribute (javax.management.Attribute)7 MalformedObjectNameException (javax.management.MalformedObjectNameException)7