use of org.apache.openejb.monitoring.ObjectNameBuilder in project tomee by apache.
the class CxfRsHttpListener method logEndpoints.
private void logEndpoints(final Application application, final String prefix, final Map<String, EJBRestServiceInfo> restEjbs, final JAXRSServerFactoryBean factory, final String base) {
final List<Logs.LogResourceEndpointInfo> resourcesToLog = new ArrayList<>();
int classSize = 0;
int addressSize = 0;
final JAXRSServiceImpl service = (JAXRSServiceImpl) factory.getServiceFactory().getService();
final List<ClassResourceInfo> resources = service.getClassResourceInfos();
for (final ClassResourceInfo info : resources) {
if (info.getResourceClass() == null) {
// possible?
continue;
}
final String address = Logs.singleSlash(base, info.getURITemplate().getValue());
final String clazz = info.getResourceClass().getName();
final String type;
if (restEjbs.containsKey(clazz)) {
type = "EJB";
} else {
type = "Pojo";
}
classSize = Math.max(classSize, clazz.length());
addressSize = Math.max(addressSize, address.length());
int methodSize = 7;
int methodStrSize = 0;
final List<Logs.LogOperationEndpointInfo> toLog = new ArrayList<>();
final MethodDispatcher md = info.getMethodDispatcher();
for (final OperationResourceInfo ori : md.getOperationResourceInfos()) {
final String httpMethod = ori.getHttpMethod();
final String currentAddress = Logs.singleSlash(address, ori.getURITemplate().getValue());
final String methodToStr = Logs.toSimpleString(ori.getMethodToInvoke());
toLog.add(new Logs.LogOperationEndpointInfo(httpMethod, currentAddress, methodToStr));
if (httpMethod != null) {
methodSize = Math.max(methodSize, httpMethod.length());
}
addressSize = Math.max(addressSize, currentAddress.length());
methodStrSize = Math.max(methodStrSize, methodToStr.length());
}
Collections.sort(toLog);
resourcesToLog.add(new Logs.LogResourceEndpointInfo(type, address, clazz, toLog, methodSize, methodStrSize));
}
// effective logging
LOGGER.info("REST Application: " + Logs.forceLength(prefix, addressSize, true) + " -> " + (InternalApplication.class.isInstance(application) && InternalApplication.class.cast(application).getOriginal() != null ? InternalApplication.class.cast(application).getOriginal() : application));
Collections.sort(resourcesToLog);
for (final Logs.LogResourceEndpointInfo resource : resourcesToLog) {
// Init and register MBeans
final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management").set("j2eeType", "JAX-RS").set("J2EEServer", "openejb").set("J2EEApplication", base).set("EndpointType", resource.type).set("name", resource.classname);
final ObjectName jmxObjectName = jmxName.build();
LocalMBeanServer.registerDynamicWrapperSilently(new RestServiceMBean(resource), jmxObjectName);
jmxNames.add(jmxObjectName);
LOGGER.info(" Service URI: " + Logs.forceLength(resource.address, addressSize, true) + " -> " + Logs.forceLength(resource.type, 4, false) + " " + Logs.forceLength(resource.classname, classSize, true));
for (final Logs.LogOperationEndpointInfo log : resource.operations) {
LOGGER.info(" " + Logs.forceLength(log.http, resource.methodSize, false) + " " + Logs.forceLength(log.address, addressSize, true) + " -> " + Logs.forceLength(log.method, resource.methodStrSize, true));
}
resource.operations.clear();
}
resourcesToLog.clear();
}
use of org.apache.openejb.monitoring.ObjectNameBuilder in project tomee by apache.
the class StatefulContainer 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<Method, MethodType>(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("StatefulSessionBean", 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.ObjectNameBuilder in project tomee by apache.
the class StatelessInstanceManager method deploy.
@SuppressWarnings("unchecked")
public void deploy(final BeanContext beanContext) throws OpenEJBException {
final Options options = new Options(beanContext.getProperties());
final Duration accessTimeout = getDuration(options, "AccessTimeout", // default timeout
getDuration(options, "Timeout", this.accessTimeout, TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS);
final Duration closeTimeout = getDuration(options, "CloseTimeout", this.closeTimeout, TimeUnit.MINUTES);
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 StatelessSupplier supplier = new StatelessSupplier(beanContext);
builder.setSupplier(supplier);
builder.setExecutor(executor);
builder.setScheduledExecutor(scheduledExecutor);
final Data data = new Data(builder.build(), accessTimeout, closeTimeout);
beanContext.setContainerData(data);
beanContext.set(EJBContext.class, data.sessionContext);
try {
final Context context = beanContext.getJndiEnc();
context.bind("comp/EJBContext", data.sessionContext);
context.bind("comp/WebServiceContext", new EjbWsContext(data.sessionContext));
context.bind("comp/TimerService", new TimerServiceWrapper());
} catch (final NamingException e) {
throw new OpenEJBException("Failed to bind EJBContext/WebServiceContext/TimerService", e);
}
final int min = builder.getMin();
final long maxAge = builder.getMaxAge().getTime(TimeUnit.MILLISECONDS);
final double maxAgeOffset = builder.getMaxAgeOffset();
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("name", beanContext.getEjbName());
final MBeanServer server = LocalMBeanServer.get();
// Create stats interceptor
if (StatsInterceptor.isStatsActivated()) {
StatsInterceptor stats = null;
for (final InterceptorInstance interceptor : beanContext.getUserAndSystemInterceptors()) {
if (interceptor.getInterceptor() instanceof StatsInterceptor) {
stats = (StatsInterceptor) interceptor.getInterceptor();
}
}
if (stats == null) {
// normally useless
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);
data.add(objectName);
} catch (final Exception e) {
logger.error("Unable to register MBean ", 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);
}
// 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 stateless pool", e);
}
}
data.getPool().start();
}
use of org.apache.openejb.monitoring.ObjectNameBuilder in project tomee by apache.
the class EjbWsContainer method registerMBean.
protected ObjectName registerMBean() {
final ObjectName name = new ObjectNameBuilder("openejb.management").set("j2eeType", "JAX-WS").set("J2EEServer", "openejb").set("J2EEApplication", null).set("EndpointType", "EJB").set("name", beanContext.getEjbName()).build();
mbean = new WsServiceMBean(beanContext, port);
LocalMBeanServer.registerDynamicWrapperSilently(mbean, name);
return name;
}
use of org.apache.openejb.monitoring.ObjectNameBuilder in project tomee by apache.
the class PojoWsContainer method registerMBean.
@Override
protected ObjectName registerMBean() {
final ObjectName name = new ObjectNameBuilder("openejb.management").set("j2eeType", "JAX-WS").set("J2EEServer", "openejb").set("J2EEApplication", null).set("EndpointType", "POJO").set("name", target.getSimpleName()).build();
mbean = new WsServiceMBean(context, target, port);
LocalMBeanServer.registerDynamicWrapperSilently(mbean, name);
return name;
}
Aggregations