use of javax.management.DynamicMBean in project tomcat70 by apache.
the class MBeanUtils method createMBean.
/**
* Create, register, and return an MBean for this
* <code>ContextResource</code> object.
*
* @param resource The ContextResource to be managed
*
* @exception Exception if an MBean cannot be created or registered
*/
public static DynamicMBean createMBean(ContextResource resource) throws Exception {
String mname = createManagedName(resource);
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(resource);
ObjectName oname = createObjectName(domain, resource);
if (mserver.isRegistered(oname)) {
mserver.unregisterMBean(oname);
}
mserver.registerMBean(mbean, oname);
return (mbean);
}
use of javax.management.DynamicMBean in project tomcat70 by apache.
the class MBeanUtils method createMBean.
/**
* Create, register, and return an MBean for this
* <code>Loader</code> object.
*
* @param loader The Loader to be managed
*
* @exception Exception if an MBean cannot be created or registered
*
* @deprecated Unused. Will be removed in Tomcat 8.0.x
*/
@Deprecated
static DynamicMBean createMBean(Loader loader) throws Exception {
String mname = createManagedName(loader);
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(loader);
ObjectName oname = createObjectName(domain, loader);
if (mserver.isRegistered(oname)) {
// side effect: stop it
mserver.unregisterMBean(oname);
}
mserver.registerMBean(mbean, oname);
return (mbean);
}
use of javax.management.DynamicMBean in project tomcat70 by apache.
the class MBeanUtils method createMBean.
/**
* Create, register, and return an MBean for this
* <code>MBeanFactory</code> object.
*
* @param factory The MBeanFactory to be managed
*
* @exception Exception if an MBean cannot be created or registered
*
* @deprecated Unused. Will be removed in Tomcat 8.0.x
*/
@Deprecated
static DynamicMBean createMBean(MBeanFactory factory) throws Exception {
String mname = createManagedName(factory);
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(factory);
ObjectName oname = createObjectName(domain, factory);
if (mserver.isRegistered(oname)) {
mserver.unregisterMBean(oname);
}
mserver.registerMBean(mbean, oname);
return (mbean);
}
use of javax.management.DynamicMBean in project tomcat70 by apache.
the class Registry method registerComponent.
/**
* Register a component
* XXX make it private
*
* @param bean
* @param oname
* @param type
* @throws Exception
*/
public void registerComponent(Object bean, ObjectName oname, String type) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Managed= " + oname);
}
if (bean == null) {
log.error("Null component " + oname);
return;
}
try {
if (type == null) {
type = bean.getClass().getName();
}
ManagedBean managed = findManagedBean(bean.getClass(), type);
// The real mbean is created and registered
DynamicMBean mbean = managed.createMBean(bean);
if (getMBeanServer().isRegistered(oname)) {
if (log.isDebugEnabled()) {
log.debug("Unregistering existing component " + oname);
}
getMBeanServer().unregisterMBean(oname);
}
getMBeanServer().registerMBean(mbean, oname);
} catch (Exception ex) {
log.error("Error registering " + oname, ex);
throw ex;
}
}
use of javax.management.DynamicMBean in project tomcat70 by apache.
the class BaseModelMBean method getAttribute.
// key: operation val: invoke method
// private Hashtable invokeAttMap=new Hashtable();
/**
* 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");
if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
return ((DynamicMBean) resource).getAttribute(name);
}
Method m = managedBean.getGetter(name, this, resource);
Object result = null;
try {
Class<?> declaring = m.getDeclaringClass();
// but this is the catalina class.
if (declaring.isAssignableFrom(this.getClass())) {
result = m.invoke(this, NO_ARGS_PARAM);
} else {
result = m.invoke(resource, NO_ARGS_PARAM);
}
} 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) {
throw new MBeanException(e, "Exception invoking method " + name);
}
// FIXME - should we validate the return type?
return (result);
}
Aggregations