Search in sources :

Example 1 with ObjectNameBuilder

use of org.apache.openejb.monitoring.ObjectNameBuilder in project tomee by apache.

the class GeronimoTransactionManagerFactory method create.

public static // Deprecated, use defaultTransactionTimeout
GeronimoTransactionManager create(// Deprecated, use defaultTransactionTimeout
Integer defaultTransactionTimeoutSeconds, final Duration defaultTransactionTimeout, final boolean txRecovery, final byte[] tmId, final String bufferClassName, final int bufferSizeKb, final boolean checksumEnabled, final boolean adler32Checksum, // Deprecated, use flushSleepTime
Integer flushSleepTimeMilliseconds, final Duration flushSleepTime, final String logFileDir, final String logFileExt, final String logFileName, final int maxBlocksPerFile, final int maxBuffers, final int maxLogFiles, final int minBuffers, final int threadsWaitingForceThreshold) throws Exception {
    if (flushSleepTime.getUnit() == null) {
        flushSleepTime.setUnit(TimeUnit.MILLISECONDS);
    }
    if (flushSleepTimeMilliseconds == null) {
        flushSleepTimeMilliseconds = (int) TimeUnit.MILLISECONDS.convert(flushSleepTime.getTime(), flushSleepTime.getUnit());
    }
    if (defaultTransactionTimeout.getUnit() == null) {
        defaultTransactionTimeout.setUnit(TimeUnit.SECONDS);
    }
    if (defaultTransactionTimeoutSeconds == null) {
        defaultTransactionTimeoutSeconds = (int) TimeUnit.SECONDS.convert(defaultTransactionTimeout.getTime(), defaultTransactionTimeout.getUnit());
    }
    XidFactory xidFactory = null;
    TransactionLog txLog = null;
    if (txRecovery) {
        SystemInstance.get().setComponent(XAResourceWrapper.class, new GeronimoXAResourceWrapper());
        xidFactory = new XidFactoryImpl(tmId == null ? DEFAULT_TM_ID : tmId);
        txLog = new HOWLLog(bufferClassName == null ? "org.objectweb.howl.log.BlockLogBuffer" : bufferClassName, bufferSizeKb == 0 ? DEFAULT_BUFFER_SIZE : bufferSizeKb, checksumEnabled, adler32Checksum, flushSleepTimeMilliseconds, logFileDir, logFileExt, logFileName, maxBlocksPerFile, maxBuffers, maxLogFiles, minBuffers, threadsWaitingForceThreshold, xidFactory, SystemInstance.get().getBase().getDirectory("."));
        ((HOWLLog) txLog).doStart();
    }
    final GeronimoTransactionManager geronimoTransactionManager = new DestroyableTransactionManager(defaultTransactionTimeoutSeconds, xidFactory, txLog);
    final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management").set("j2eeType", "TransactionManager");
    LocalMBeanServer.registerDynamicWrapperSilently(new TransactionManagerMBean(geronimoTransactionManager, defaultTransactionTimeout, txLog), jmxName.build());
    return geronimoTransactionManager;
}
Also used : ObjectNameBuilder(org.apache.openejb.monitoring.ObjectNameBuilder) TransactionLog(org.apache.geronimo.transaction.manager.TransactionLog) XidFactoryImpl(org.apache.geronimo.transaction.manager.XidFactoryImpl) HOWLLog(org.apache.geronimo.transaction.log.HOWLLog) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) XidFactory(org.apache.geronimo.transaction.manager.XidFactory)

Example 2 with ObjectNameBuilder

use of org.apache.openejb.monitoring.ObjectNameBuilder 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);
        }
    }
}
Also used : MBean(org.apache.openejb.api.jmx.MBean) Dependent(javax.enterprise.context.Dependent) InvalidObjectException(java.io.InvalidObjectException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ObjectStreamException(java.io.ObjectStreamException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) UndeployException(org.apache.openejb.UndeployException) DefinitionException(javax.enterprise.inject.spi.DefinitionException) ConstructionException(org.apache.xbean.recipe.ConstructionException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(javax.validation.ValidationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) DuplicateDeploymentIdException(org.apache.openejb.DuplicateDeploymentIdException) TimeoutException(java.util.concurrent.TimeoutException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) DeploymentException(javax.enterprise.inject.spi.DeploymentException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) MalformedURLException(java.net.MalformedURLException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) ResourceBean(org.apache.webbeans.component.ResourceBean) MBean(org.apache.openejb.api.jmx.MBean) Bean(javax.enterprise.inject.spi.Bean) ObjectName(javax.management.ObjectName) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) CreationalContext(javax.enterprise.context.spi.CreationalContext) ObjectNameBuilder(org.apache.openejb.monitoring.ObjectNameBuilder) DynamicMBeanWrapper(org.apache.openejb.monitoring.DynamicMBeanWrapper) BeanManager(javax.enterprise.inject.spi.BeanManager) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer) MBeanServer(javax.management.MBeanServer)

Example 3 with ObjectNameBuilder

use of org.apache.openejb.monitoring.ObjectNameBuilder in project tomee by apache.

the class ReloadableEntityManagerFactory method generateObjectName.

private ObjectName generateObjectName() {
    final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
    jmxName.set("ObjectType", "persistence-unit");
    jmxName.set("PersistenceUnit", getPUname());
    objectName = jmxName.build();
    final MBeanServer server = LocalMBeanServer.get();
    if (server.isRegistered(objectName)) {
        // if 2 pu have the same name...a bit uglier but unique
        jmxName.set("PersistenceUnit", getPUname() + "(" + getId() + ")");
        objectName = jmxName.build();
    }
    return objectName;
}
Also used : ObjectNameBuilder(org.apache.openejb.monitoring.ObjectNameBuilder) MBeanServer(javax.management.MBeanServer) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer)

Example 4 with ObjectNameBuilder

use of org.apache.openejb.monitoring.ObjectNameBuilder 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);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) WebServiceContext(javax.xml.ws.WebServiceContext) Context(javax.naming.Context) EJBContext(javax.ejb.EJBContext) InstanceContext(org.apache.openejb.core.InstanceContext) ThreadContext(org.apache.openejb.core.ThreadContext) ObjectNameBuilder(org.apache.openejb.monitoring.ObjectNameBuilder) TimerServiceWrapper(org.apache.openejb.core.timer.TimerServiceWrapper) OpenEJBException(org.apache.openejb.OpenEJBException) StatsInterceptor(org.apache.openejb.monitoring.StatsInterceptor) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) NamingException(javax.naming.NamingException) ManagedMBean(org.apache.openejb.monitoring.ManagedMBean) NoSuchEJBException(javax.ejb.NoSuchEJBException) NamingException(javax.naming.NamingException) ApplicationException(org.apache.openejb.ApplicationException) OpenEJBException(org.apache.openejb.OpenEJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException) MBeanServer(javax.management.MBeanServer) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer) ObjectName(javax.management.ObjectName)

Example 5 with ObjectNameBuilder

use of org.apache.openejb.monitoring.ObjectNameBuilder 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<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("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);
}
Also used : SessionContext(javax.ejb.SessionContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) EJBContext(javax.ejb.EJBContext) InstanceContext(org.apache.openejb.core.InstanceContext) ThreadContext(org.apache.openejb.core.ThreadContext) OpenEJBException(org.apache.openejb.OpenEJBException) StatsInterceptor(org.apache.openejb.monitoring.StatsInterceptor) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) Method(java.lang.reflect.Method) NamingException(javax.naming.NamingException) InvalidateReferenceException(org.apache.openejb.InvalidateReferenceException) EJBAccessException(javax.ejb.EJBAccessException) RemoveException(javax.ejb.RemoveException) OpenEJBException(org.apache.openejb.OpenEJBException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) SystemException(org.apache.openejb.SystemException) NoSuchObjectException(java.rmi.NoSuchObjectException) EntityManagerAlreadyRegisteredException(org.apache.openejb.persistence.EntityManagerAlreadyRegisteredException) ApplicationException(org.apache.openejb.ApplicationException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) ObjectName(javax.management.ObjectName) ObjectNameBuilder(org.apache.openejb.monitoring.ObjectNameBuilder) NamingException(javax.naming.NamingException) ManagedMBean(org.apache.openejb.monitoring.ManagedMBean) MBeanServer(javax.management.MBeanServer) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer)

Aggregations

ObjectNameBuilder (org.apache.openejb.monitoring.ObjectNameBuilder)16 ObjectName (javax.management.ObjectName)10 MBeanServer (javax.management.MBeanServer)8 LocalMBeanServer (org.apache.openejb.monitoring.LocalMBeanServer)8 NamingException (javax.naming.NamingException)6 OpenEJBException (org.apache.openejb.OpenEJBException)6 ApplicationException (org.apache.openejb.ApplicationException)5 ManagedMBean (org.apache.openejb.monitoring.ManagedMBean)5 StatsInterceptor (org.apache.openejb.monitoring.StatsInterceptor)5 IOException (java.io.IOException)4 EJBContext (javax.ejb.EJBContext)4 Context (javax.naming.Context)4 BeanContext (org.apache.openejb.BeanContext)4 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)4 SystemException (org.apache.openejb.SystemException)4 InstanceContext (org.apache.openejb.core.InstanceContext)4 ThreadContext (org.apache.openejb.core.ThreadContext)4 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 RemoteException (java.rmi.RemoteException)3