Search in sources :

Example 1 with RuntimeOperationsException

use of javax.management.RuntimeOperationsException in project tomcat by apache.

the class ContextResourceLinkMBean method setAttribute.

/**
     * Set the value of a specific attribute of this MBean.
     *
     * @param attribute The identification of the attribute to be set
     *  and the new value
     *
     * @exception AttributeNotFoundException if this attribute is not
     *  supported by this MBean
     * @exception MBeanException if the initializer of an object
     *  throws an exception
     * @exception ReflectionException if a Java reflection exception
     *  occurs when invoking the getter
     */
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    // Validate the input parameters
    if (attribute == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute is null"), "Attribute is null");
    }
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
    }
    ContextResourceLink crl = doGetManagedResource();
    if ("global".equals(name)) {
        crl.setGlobal((String) value);
    } else if ("description".equals(name)) {
        crl.setDescription((String) value);
    } else if ("name".equals(name)) {
        crl.setName((String) value);
    } else if ("type".equals(name)) {
        crl.setType((String) value);
    } else {
        crl.setProperty(name, "" + value);
    }
    // cannot use side-effects.  It's removed and added back each time
    // there is a modification in a resource.
    NamingResources nr = crl.getNamingResources();
    nr.removeResourceLink(crl.getName());
    nr.addResourceLink(crl);
}
Also used : ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) NamingResources(org.apache.tomcat.util.descriptor.web.NamingResources) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 2 with RuntimeOperationsException

use of javax.management.RuntimeOperationsException in project tomcat by apache.

the class ContextResourceMBean method setAttribute.

/**
     * Set the value of a specific attribute of this MBean.
     *
     * @param attribute The identification of the attribute to be set
     *  and the new value
     *
     * @exception AttributeNotFoundException if this attribute is not
     *  supported by this MBean
     * @exception MBeanException if the initializer of an object
     *  throws an exception
     * @exception ReflectionException if a Java reflection exception
     *  occurs when invoking the getter
     */
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    // Validate the input parameters
    if (attribute == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute is null"), "Attribute is null");
    }
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
    }
    ContextResource cr = doGetManagedResource();
    if ("auth".equals(name)) {
        cr.setAuth((String) value);
    } else if ("description".equals(name)) {
        cr.setDescription((String) value);
    } else if ("name".equals(name)) {
        cr.setName((String) value);
    } else if ("scope".equals(name)) {
        cr.setScope((String) value);
    } else if ("type".equals(name)) {
        cr.setType((String) value);
    } else {
        cr.setProperty(name, "" + value);
    }
    // cannot use side-effects.  It's removed and added back each time
    // there is a modification in a resource.
    NamingResources nr = cr.getNamingResources();
    nr.removeResource(cr.getName());
    nr.addResource(cr);
}
Also used : NamingResources(org.apache.tomcat.util.descriptor.web.NamingResources) RuntimeOperationsException(javax.management.RuntimeOperationsException) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Example 3 with RuntimeOperationsException

use of javax.management.RuntimeOperationsException in project tomcat by apache.

the class ContextResourceMBean method getAttribute.

/**
     * Obtain and return the value of a specific attribute of this MBean.
     *
     * @param name Name of the requested attribute
     *
     * @exception AttributeNotFoundException if this attribute is not
     *  supported by this MBean
     * @exception MBeanException if the initializer of an object
     *  throws an exception
     * @exception ReflectionException if a Java reflection exception
     *  occurs when invoking the getter
     */
@Override
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
    // Validate the input parameters
    if (name == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
    }
    ContextResource cr = doGetManagedResource();
    String value = null;
    if ("auth".equals(name)) {
        return (cr.getAuth());
    } else if ("description".equals(name)) {
        return (cr.getDescription());
    } else if ("name".equals(name)) {
        return (cr.getName());
    } else if ("scope".equals(name)) {
        return (cr.getScope());
    } else if ("type".equals(name)) {
        return (cr.getType());
    } else {
        value = (String) cr.getProperty(name);
        if (value == null) {
            throw new AttributeNotFoundException("Cannot find attribute [" + name + "]");
        }
    }
    return value;
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Example 4 with RuntimeOperationsException

use of javax.management.RuntimeOperationsException in project tomcat by apache.

the class BaseModelMBean method setAttribute.

/**
     * Set the value of a specific attribute of this MBean.
     *
     * @param attribute The identification of the attribute to be set
     *  and the new value
     *
     * @exception AttributeNotFoundException if this attribute is not
     *  supported by this MBean
     * @exception MBeanException if the initializer of an object
     *  throws an exception
     * @exception ReflectionException if a Java reflection exception
     *  occurs when invoking the getter
     */
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    if (log.isDebugEnabled())
        log.debug("Setting attribute " + this + " " + attribute);
    if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
        try {
            ((DynamicMBean) resource).setAttribute(attribute);
        } catch (InvalidAttributeValueException e) {
            throw new MBeanException(e);
        }
        return;
    }
    // Validate the input parameters
    if (attribute == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute is null"), "Attribute is null");
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
    Object oldValue = null;
    //if( getAttMap.get(name) != null )
    //    oldValue=getAttribute( name );
    Method m = managedBean.getSetter(name, this, resource);
    try {
        if (m.getDeclaringClass().isAssignableFrom(this.getClass())) {
            m.invoke(this, new Object[] { value });
        } else {
            m.invoke(resource, new Object[] { value });
        }
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        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(e, "Exception invoking method " + name);
    } catch (Exception e) {
        log.error("Exception invoking method " + name, e);
        throw new MBeanException(e, "Exception invoking method " + name);
    }
    try {
        sendAttributeChangeNotification(new Attribute(name, oldValue), attribute);
    } catch (Exception ex) {
        log.error("Error sending notification " + name, ex);
    }
//attributes.put( name, value );
//        if( source != null ) {
//            // this mbean is associated with a source - maybe we want to persist
//            source.updateField(oname, name, value);
//        }
}
Also used : DynamicMBean(javax.management.DynamicMBean) RuntimeErrorException(javax.management.RuntimeErrorException) Attribute(javax.management.Attribute) Method(java.lang.reflect.Method) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) 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 5 with RuntimeOperationsException

use of javax.management.RuntimeOperationsException in project tomcat by apache.

the class BaseModelMBean method sendNotification.

/**
     * Send a <code>Notification</code> which contains the specified string
     * as a <code>jmx.modelmbean.generic</code> notification.
     *
     * @param message The message string to be passed
     *
     * @exception MBeanException if an object initializer throws an
     *  exception
     * @exception RuntimeOperationsException wraps IllegalArgumentException
     *  when the specified notification is <code>null</code> or invalid
     */
@Override
public void sendNotification(String message) throws MBeanException, RuntimeOperationsException {
    if (message == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Message is null"), "Message is null");
    Notification notification = new Notification("jmx.modelmbean.generic", this, 1, message);
    sendNotification(notification);
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification) Notification(javax.management.Notification) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

RuntimeOperationsException (javax.management.RuntimeOperationsException)67 AttributeNotFoundException (javax.management.AttributeNotFoundException)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)20 ReflectionException (javax.management.ReflectionException)20 MBeanException (javax.management.MBeanException)18 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 JMRuntimeException (javax.management.JMRuntimeException)8 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)8 Attribute (javax.management.Attribute)7 Date (java.util.Date)6