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);
}
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);
}
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);
}
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);
}
}
}
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);
// }
}
Aggregations