use of org.apache.openejb.monitoring.ManagedMBean in project tomee by apache.
the class ManagedContainer method deploy.
@Override
public synchronized void deploy(final BeanContext beanContext) throws OpenEJBException {
final Map<Method, MethodType> methods = getLifecycleMethodsOfInterface(beanContext);
deploymentsById.put(beanContext.getDeploymentID(), beanContext);
beanContext.setContainer(this);
final Data data = new Data(new Index<>(methods));
beanContext.setContainerData(data);
// Create stats interceptor
if (StatsInterceptor.isStatsActivated()) {
final StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
beanContext.addFirstSystemInterceptor(stats);
final MBeanServer server = LocalMBeanServer.get();
final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
jmxName.set("J2EEServer", "openejb");
jmxName.set("J2EEApplication", null);
jmxName.set("EJBModule", beanContext.getModuleID());
jmxName.set("StatelessSessionBean", beanContext.getEjbName());
jmxName.set("j2eeType", "");
jmxName.set("name", beanContext.getEjbName());
// register the invocation stats interceptor
try {
final ObjectName objectName = jmxName.set("j2eeType", "Invocations").build();
if (server.isRegistered(objectName)) {
server.unregisterMBean(objectName);
}
server.registerMBean(new ManagedMBean(stats), objectName);
data.jmxNames.add(objectName);
} catch (final Exception e) {
logger.error("Unable to register MBean ", e);
}
}
try {
final Context context = beanContext.getJndiEnc();
context.bind("comp/EJBContext", sessionContext);
} catch (final NamingException e) {
throw new OpenEJBException("Failed to bind EJBContext", e);
}
beanContext.set(EJBContext.class, this.sessionContext);
}
use of org.apache.openejb.monitoring.ManagedMBean in project tomee by apache.
the class MdbInstanceManager method deploy.
public void deploy(final BeanContext beanContext, final ActivationSpec activationSpec, final EndpointFactory endpointFactory) throws OpenEJBException {
if (inboundRecovery != null) {
inboundRecovery.recover(resourceAdapter, activationSpec, containerID.toString());
}
final ObjectRecipe recipe = PassthroughFactory.recipe(new Pool.Builder(poolBuilder));
recipe.allow(Option.CASE_INSENSITIVE_FACTORY);
recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
recipe.setAllProperties(beanContext.getProperties());
final Pool.Builder builder = (Pool.Builder) recipe.create();
setDefault(builder.getMaxAge(), TimeUnit.HOURS);
setDefault(builder.getIdleTimeout(), TimeUnit.MINUTES);
setDefault(builder.getInterval(), TimeUnit.MINUTES);
final InstanceSupplier supplier = new InstanceSupplier(beanContext);
builder.setSupplier(supplier);
builder.setExecutor(executor);
builder.setScheduledExecutor(scheduledExecutor);
final int min = builder.getMin();
final long maxAge = builder.getMaxAge().getTime(TimeUnit.MILLISECONDS);
final double maxAgeOffset = builder.getMaxAgeOffset();
final Data data = new Data(builder.build(), accessTimeout, closeTimeout);
MdbContext mdbContext = new MdbContext(securityService, data::flush);
try {
final Context context = beanContext.getJndiEnc();
context.bind("comp/EJBContext", mdbContext);
context.bind("comp/TimerService", new TimerServiceWrapper());
} catch (final NamingException e) {
throw new OpenEJBException("Failed to bind EJBContext/TimerService", e);
}
beanContext.set(EJBContext.class, mdbContext);
data.setBaseContext(mdbContext);
beanContext.setContainerData(data);
final MBeanServer server = LocalMBeanServer.get();
final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
jmxName.set("J2EEServer", "openejb");
jmxName.set("J2EEApplication", null);
jmxName.set("EJBModule", beanContext.getModuleID());
jmxName.set("MessageDrivenBean", beanContext.getEjbName());
jmxName.set("j2eeType", "");
jmxName.set("name", beanContext.getEjbName());
// Create stats interceptor
if (StatsInterceptor.isStatsActivated()) {
final StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
beanContext.addFirstSystemInterceptor(stats);
// register the invocation stats interceptor
try {
final ObjectName objectName = jmxName.set("j2eeType", "Invocations").build();
if (server.isRegistered(objectName)) {
server.unregisterMBean(objectName);
}
server.registerMBean(new ManagedMBean(stats), objectName);
jmxNames.add(objectName);
} catch (final Exception e) {
logger.error("Unable to register MBean ", e);
}
}
// activate the endpoint
try {
final MdbPoolContainer.MdbActivationContext activationContext = new MdbPoolContainer.MdbActivationContext(Thread.currentThread().getContextClassLoader(), beanContext, resourceAdapter, endpointFactory, activationSpec);
activationContexts.put(beanContext, activationContext);
boolean activeOnStartup = true;
String activeOnStartupSetting = beanContext.getActivationProperties().get("MdbActiveOnStartup");
if (activeOnStartupSetting == null) {
activeOnStartupSetting = beanContext.getActivationProperties().get("DeliveryActive");
}
if (activeOnStartupSetting != null) {
activeOnStartup = Boolean.parseBoolean(activeOnStartupSetting);
}
if (activeOnStartup) {
activationContext.start();
} else {
logger.info("Not auto-activating endpoint for " + beanContext.getDeploymentID());
}
String jmxControlName = beanContext.getActivationProperties().get("MdbJMXControl");
if (jmxControlName == null) {
jmxControlName = "true";
}
addJMxControl(beanContext, jmxControlName, activationContext);
} catch (final ResourceException e) {
throw new OpenEJBException(e);
}
final Options options = new Options(beanContext.getProperties());
// Finally, fill the pool and start it
if (!options.get("BackgroundStartup", false) && min > 0) {
final ExecutorService es = Executors.newFixedThreadPool(min);
for (int i = 0; i < min; i++) {
es.submit(new InstanceCreatorRunnable(maxAge, i, min, maxAgeOffset, data, supplier));
}
es.shutdown();
try {
es.awaitTermination(5, TimeUnit.MINUTES);
} catch (final InterruptedException e) {
logger.error("can't fill the message driven bean pool", e);
}
}
// register the pool
try {
final ObjectName objectName = jmxName.set("j2eeType", "Pool").build();
if (server.isRegistered(objectName)) {
server.unregisterMBean(objectName);
}
server.registerMBean(new ManagedMBean(data.pool), objectName);
data.add(objectName);
} catch (final Exception e) {
logger.error("Unable to register MBean ", e);
}
data.getPool().start();
}
use of org.apache.openejb.monitoring.ManagedMBean in project tomee by apache.
the class SingletonInstanceManager method deploy.
public void deploy(final BeanContext beanContext) throws OpenEJBException {
final Data data = new Data(beanContext);
beanContext.setContainerData(data);
beanContext.set(EJBContext.class, this.sessionContext);
// Create stats interceptor
if (StatsInterceptor.isStatsActivated()) {
final StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
beanContext.addFirstSystemInterceptor(stats);
final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
jmxName.set("J2EEServer", "openejb");
jmxName.set("J2EEApplication", null);
jmxName.set("EJBModule", beanContext.getModuleID());
jmxName.set("SingletonSessionBean", beanContext.getEjbName());
jmxName.set("name", beanContext.getEjbName());
jmxName.set("j2eeType", "Invocations");
// register the invocation stats interceptor
final MBeanServer server = LocalMBeanServer.get();
try {
final ObjectName objectName = jmxName.build();
if (server.isRegistered(objectName)) {
server.unregisterMBean(objectName);
}
server.registerMBean(new ManagedMBean(stats), objectName);
data.add(objectName);
} catch (final Exception e) {
logger.error("Unable to register MBean ", e);
}
}
try {
final Context context = beanContext.getJndiEnc();
context.bind("comp/EJBContext", sessionContext);
context.bind("comp/WebServiceContext", webServiceContext);
context.bind("comp/TimerService", new TimerServiceWrapper());
} catch (final NamingException e) {
throw new OpenEJBException("Failed to bind EJBContext/WebServiceContext/TimerService", e);
}
}
use of org.apache.openejb.monitoring.ManagedMBean in project tomee by apache.
the class ServiceManager method register.
public static void register(final String serviceName, final ServerService service, final MBeanServer server) {
try {
final ObjectName on = getObjectName(serviceName);
if (server.isRegistered(on)) {
server.unregisterMBean(on);
}
server.registerMBean(new ManagedMBean(service), on);
} catch (Exception e) {
logger.error("Unable to register MBean ", e);
}
}
use of org.apache.openejb.monitoring.ManagedMBean in project tomee by apache.
the class SimpleServiceManager method init.
@Override
public void init() throws Exception {
try {
ServiceLogger.MDCput("SERVER", "main");
final InetAddress localhost = InetAddress.getLocalHost();
ServiceLogger.MDCput("HOST", localhost.getHostName());
} catch (Throwable e) {
// Ignore
}
final DiscoveryRegistry registry = new DiscoveryRegistry();
// register the mbean
try {
LocalMBeanServer.get().registerMBean(new ManagedMBean(registry), getDiscoveryRegistryObjectName());
} catch (Throwable e) {
logger.error("Failed to register 'openejb' MBean", e);
}
SystemInstance.get().setComponent(DiscoveryRegistry.class, registry);
final Map<String, Properties> availableServices = this.serviceFinder.mapAvailableServices(ServerService.class);
final List<ServerService> enabledServers = initServers(availableServices);
daemons = enabledServers.toArray(new ServerService[enabledServers.size()]);
stopped = false;
}
Aggregations