use of org.apache.openejb.monitoring.DynamicMBeanWrapper in project tomee by apache.
the class Assembler method deployMBean.
@SuppressWarnings("unchecked")
private void deployMBean(final WebBeansContext wc, final ClassLoader cl, final String mbeanClass, final Properties appMbeans, final String id) {
if (LocalMBeanServer.isJMXActive()) {
final Class<?> clazz;
try {
clazz = cl.loadClass(mbeanClass);
} catch (final ClassNotFoundException e) {
throw new OpenEJBRuntimeException(e);
}
// cdi can be off so init with null bean in this case
final Bean<?> bean;
final BeanManager bm;
if (wc == null) {
bm = null;
bean = null;
} else {
bm = wc.getBeanManagerImpl();
final Set<Bean<?>> beans = bm.getBeans(clazz);
bean = bm.resolve(beans);
}
// create the MBean instance with cdi if possible or manually otherwise
final Object instance;
final CreationalContext creationalContext;
if (bean == null) {
try {
instance = clazz.newInstance();
} catch (final InstantiationException e) {
logger.error("the mbean " + mbeanClass + " can't be registered because it can't be instantiated", e);
return;
} catch (final IllegalAccessException e) {
logger.error("the mbean " + mbeanClass + " can't be registered because it can't be accessed", e);
return;
}
creationalContext = null;
} else {
creationalContext = bm.createCreationalContext(bean);
instance = bm.getReference(bean, clazz, creationalContext);
}
final MBeanServer server = LocalMBeanServer.get();
try {
final MBean annotation = clazz.getAnnotation(MBean.class);
final ObjectName leaf = annotation == null || annotation.objectName().isEmpty() ? new ObjectNameBuilder("openejb.user.mbeans").set("application", id).set("group", clazz.getPackage().getName()).set("name", clazz.getSimpleName()).build() : new ObjectName(annotation.objectName());
server.registerMBean(new DynamicMBeanWrapper(wc, instance), leaf);
appMbeans.put(mbeanClass, leaf.getCanonicalName());
if (creationalContext != null && (bean.getScope() == null || Dependent.class.equals(bean.getScope()))) {
creationalContextForAppMbeans.put(leaf, creationalContext);
}
logger.info("Deployed MBean(" + leaf.getCanonicalName() + ")");
} catch (final Exception e) {
logger.error("the mbean " + mbeanClass + " can't be registered", e);
}
}
}
use of org.apache.openejb.monitoring.DynamicMBeanWrapper in project tomee by apache.
the class Assembler method createContainer.
public void createContainer(final ContainerInfo serviceInfo) throws OpenEJBException {
final ObjectRecipe serviceRecipe = createRecipe(Collections.<ServiceInfo>emptyList(), serviceInfo);
serviceRecipe.setProperty("id", serviceInfo.id);
serviceRecipe.setProperty("transactionManager", props.get(TransactionManager.class.getName()));
serviceRecipe.setProperty("securityService", props.get(SecurityService.class.getName()));
serviceRecipe.setProperty("properties", new UnsetPropertiesRecipe());
// MDB container has a resource adapter string name that
// must be replaced with the real resource adapter instance
replaceResourceAdapterProperty(serviceRecipe);
final Object service = serviceRecipe.create();
// we forced it
serviceRecipe.getUnsetProperties().remove("id");
// we forced it
serviceRecipe.getUnsetProperties().remove("securityService");
logUnusedProperties(serviceRecipe, serviceInfo);
final Class interfce = serviceInterfaces.get(serviceInfo.service);
checkImplementation(interfce, service.getClass(), serviceInfo.service, serviceInfo.id);
bindService(serviceInfo, service);
setSystemInstanceComponent(interfce, service);
props.put(interfce.getName(), service);
props.put(serviceInfo.service, service);
props.put(serviceInfo.id, service);
containerSystem.addContainer(serviceInfo.id, (Container) service);
// Update the config tree
config.containerSystem.containers.add(serviceInfo);
logger.getChildLogger("service").debug("createService.success", serviceInfo.service, serviceInfo.id, serviceInfo.className);
if (Container.class.isInstance(service) && LocalMBeanServer.isJMXActive()) {
final ObjectName objectName = ObjectNameBuilder.uniqueName("containers", serviceInfo.id, service);
try {
LocalMBeanServer.get().registerMBean(new DynamicMBeanWrapper(new JMXContainer(serviceInfo, (Container) service)), objectName);
containerObjectNames.add(objectName);
} catch (final Exception | NoClassDefFoundError e) {
// no-op
}
}
}
use of org.apache.openejb.monitoring.DynamicMBeanWrapper in project tomee by apache.
the class SimpleRouter method JMXOn.
public void JMXOn(final String name) {
final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
jmxName.set("J2EEServer", "Router");
jmxName.set("J2EEApplication", name);
jmxName.set("Type", "SimpleRouter");
objectName = jmxName.build();
try {
LocalMBeanServer.get().registerMBean(new DynamicMBeanWrapper(this), objectName);
} catch (final Exception e) {
objectName = null;
}
}
Aggregations