Search in sources :

Example 6 with MBeanException

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

the class MBeanUtils method createMBean.

/**
     * Create, register, and return an MBean for this
     * <code>UserDatabase</code> object.
     *
     * @param userDatabase The UserDatabase to be managed
     * @return a new MBean
     * @exception Exception if an MBean cannot be created or registered
     */
static DynamicMBean createMBean(UserDatabase userDatabase) throws Exception {
    String mname = createManagedName(userDatabase);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(userDatabase);
    ObjectName oname = createObjectName(domain, userDatabase);
    if (mserver.isRegistered(oname)) {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);
}
Also used : DynamicMBean(javax.management.DynamicMBean) MBeanException(javax.management.MBeanException) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 7 with MBeanException

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

the class MBeanUtils method createMBean.

/**
     * Create, register, and return an MBean for this
     * <code>ContextResourceLink</code> object.
     *
     * @param resourceLink The ContextResourceLink to be managed
     * @return a new MBean
     * @exception Exception if an MBean cannot be created or registered
     */
public static DynamicMBean createMBean(ContextResourceLink resourceLink) throws Exception {
    String mname = createManagedName(resourceLink);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(resourceLink);
    ObjectName oname = createObjectName(domain, resourceLink);
    if (mserver.isRegistered(oname)) {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);
}
Also used : DynamicMBean(javax.management.DynamicMBean) MBeanException(javax.management.MBeanException) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 8 with MBeanException

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

the class MBeanUtils method createMBean.

/**
     * Create, register, and return an MBean for this
     * <code>User</code> object.
     *
     * @param user The User to be managed
     * @return a new MBean
     * @exception Exception if an MBean cannot be created or registered
     */
static DynamicMBean createMBean(User user) throws Exception {
    String mname = createManagedName(user);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with " + mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(user);
    ObjectName oname = createObjectName(domain, user);
    if (mserver.isRegistered(oname)) {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);
}
Also used : DynamicMBean(javax.management.DynamicMBean) MBeanException(javax.management.MBeanException) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 9 with MBeanException

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

the class ContainerMBean method addChild.

/**
     * Add a new child Container to those associated with this Container,
     * if supported. Won't start the child yet. Has to be started with a call to
     * Start method after necessary configurations are done.
     *
     * @param type ClassName of the child to be added
     * @param name Name of the child to be added
     *
     * @exception MBeanException if the child cannot be added
     */
public void addChild(String type, String name) throws MBeanException {
    Container contained = (Container) newInstance(type);
    contained.setName(name);
    if (contained instanceof StandardHost) {
        HostConfig config = new HostConfig();
        contained.addLifecycleListener(config);
    } else if (contained instanceof StandardContext) {
        ContextConfig config = new ContextConfig();
        contained.addLifecycleListener(config);
    }
    boolean oldValue = true;
    ContainerBase container = doGetManagedResource();
    try {
        oldValue = container.getStartChildren();
        container.setStartChildren(false);
        container.addChild(contained);
        contained.init();
    } catch (LifecycleException e) {
        throw new MBeanException(e);
    } finally {
        if (container != null) {
            container.setStartChildren(oldValue);
        }
    }
}
Also used : ContextConfig(org.apache.catalina.startup.ContextConfig) ContainerBase(org.apache.catalina.core.ContainerBase) Container(org.apache.catalina.Container) LifecycleException(org.apache.catalina.LifecycleException) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) HostConfig(org.apache.catalina.startup.HostConfig) MBeanException(javax.management.MBeanException)

Example 10 with MBeanException

use of javax.management.MBeanException 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)

Aggregations

MBeanException (javax.management.MBeanException)101 ReflectionException (javax.management.ReflectionException)47 InstanceNotFoundException (javax.management.InstanceNotFoundException)39 AttributeNotFoundException (javax.management.AttributeNotFoundException)32 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)31 ObjectName (javax.management.ObjectName)31 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)25 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 MalformedObjectNameException (javax.management.MalformedObjectNameException)17 RuntimeOperationsException (javax.management.RuntimeOperationsException)17 ServiceNotFoundException (javax.management.ServiceNotFoundException)17 RuntimeErrorException (javax.management.RuntimeErrorException)14 Attribute (javax.management.Attribute)12 Method (java.lang.reflect.Method)10 DynamicMBean (javax.management.DynamicMBean)10 ListenerNotFoundException (javax.management.ListenerNotFoundException)10 Descriptor (javax.management.Descriptor)9 MalformedURLException (java.net.MalformedURLException)7 MBeanRegistrationException (javax.management.MBeanRegistrationException)7 MBeanServer (javax.management.MBeanServer)7