Search in sources :

Example 11 with SystemInstance

use of org.apache.openejb.loader.SystemInstance in project tomee by apache.

the class Server method init.

// TODO: Remove it once init() suits our (initialisation) needs
@Override
public void init(final Properties props) throws Exception {
    this.props = props;
    final SystemInstance system = SystemInstance.get();
    final File home = system.getHome().getDirectory();
    system.setProperty(DeploymentFilterable.CLASSPATH_INCLUDE, system.getProperty(DeploymentFilterable.CLASSPATH_INCLUDE, ".*/" + home.getName() + "/lib/.*"));
    system.setProperty(DeploymentFilterable.CLASSPATH_REQUIRE_DESCRIPTOR, system.getProperty(DeploymentFilterable.CLASSPATH_REQUIRE_DESCRIPTOR, "true"));
    system.setProperty(DeploymentFilterable.CLASSPATH_FILTER_SYSTEMAPPS, system.getProperty(DeploymentFilterable.CLASSPATH_FILTER_SYSTEMAPPS, "false"));
    OpenEJB.init(props, new ServerFederation());
    if (SystemInstance.get().getOptions().get("openejb.nobanner", (String) null) == null) {
        System.out.println("[init] OpenEJB Remote Server");
    }
    if (manager == null) {
        manager = ServiceManager.getManager();
    }
    manager.init();
}
Also used : ServerFederation(org.apache.openejb.core.ServerFederation) SystemInstance(org.apache.openejb.loader.SystemInstance) File(java.io.File)

Example 12 with SystemInstance

use of org.apache.openejb.loader.SystemInstance in project tomee by apache.

the class TomeeJaxRsService method init.

@Override
public void init(final Properties props) throws Exception {
    final SystemInstance system = SystemInstance.get();
    TomcatRsRegistry tomcatRestHandler = (TomcatRsRegistry) system.getComponent(RsRegistry.class);
    if (tomcatRestHandler == null) {
        tomcatRestHandler = new TomcatRsRegistry();
        system.setComponent(RsRegistry.class, tomcatRestHandler);
    }
    system.addObserver(this);
}
Also used : RsRegistry(org.apache.openejb.server.rest.RsRegistry) SystemInstance(org.apache.openejb.loader.SystemInstance)

Example 13 with SystemInstance

use of org.apache.openejb.loader.SystemInstance in project tomee by apache.

the class TransactionSynchronizationRegistryWrapper method getRegistry.

public TransactionSynchronizationRegistry getRegistry() {
    final SystemInstance system = SystemInstance.get();
    if (system != this.system) {
        this.registry = system.getComponent(TransactionSynchronizationRegistry.class);
        this.system = system;
    }
    return registry;
}
Also used : SystemInstance(org.apache.openejb.loader.SystemInstance) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry)

Example 14 with SystemInstance

use of org.apache.openejb.loader.SystemInstance in project tomee by apache.

the class Assembler method destroy.

@Override
public void destroy() {
    final ReentrantLock l = lock;
    l.lock();
    try {
        final SystemInstance systemInstance = SystemInstance.get();
        systemInstance.fireEvent(new ContainerSystemPreDestroy());
        try {
            EjbTimerServiceImpl.shutdown();
        } catch (final Exception e) {
            logger.warning("Unable to shutdown scheduler", e);
        } catch (final NoClassDefFoundError ncdfe) {
        // no-op
        }
        logger.debug("Undeploying Applications");
        final Assembler assembler = this;
        final List<AppInfo> deployedApps = new ArrayList<>(assembler.getDeployedApplications());
        // if an app relies on the previous one it surely relies on it too at undeploy time
        Collections.reverse(deployedApps);
        for (final AppInfo appInfo : deployedApps) {
            try {
                assembler.destroyApplication(appInfo.path);
            } catch (final UndeployException e) {
                logger.error("Undeployment failed: " + appInfo.path, e);
            } catch (final NoSuchApplicationException e) {
            // Ignore
            }
        }
        final Iterator<ObjectName> it = containerObjectNames.iterator();
        final MBeanServer server = LocalMBeanServer.get();
        while (it.hasNext()) {
            try {
                server.unregisterMBean(it.next());
            } catch (final Exception ignored) {
            // no-op
            }
            it.remove();
        }
        try {
            remoteResourceMonitor.unregister();
        } catch (final Exception ignored) {
        // no-op
        }
        NamingEnumeration<Binding> namingEnumeration = null;
        try {
            namingEnumeration = containerSystem.getJNDIContext().listBindings("openejb/Resource");
        } catch (final NamingException ignored) {
        // no resource adapters were created
        }
        destroyResourceTree("", namingEnumeration);
        try {
            containerSystem.getJNDIContext().unbind("java:global");
        } catch (final NamingException ignored) {
        // no-op
        }
        systemInstance.removeComponent(OpenEjbConfiguration.class);
        systemInstance.removeComponent(JtaEntityManagerRegistry.class);
        systemInstance.removeComponent(TransactionSynchronizationRegistry.class);
        systemInstance.removeComponent(EjbResolver.class);
        systemInstance.removeComponent(ThreadSingletonService.class);
        systemInstance.fireEvent(new AssemblerDestroyed());
        systemInstance.removeObservers();
        if (DestroyableResource.class.isInstance(this.securityService)) {
            DestroyableResource.class.cast(this.securityService).destroyResource();
        }
        if (DestroyableResource.class.isInstance(this.transactionManager)) {
            DestroyableResource.class.cast(this.transactionManager).destroyResource();
        }
        for (final Container c : this.containerSystem.containers()) {
            if (DestroyableResource.class.isInstance(c)) {
                // TODO: should we use auto closeable there?
                DestroyableResource.class.cast(c).destroyResource();
            }
        }
        SystemInstance.reset();
    } finally {
        l.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Binding(javax.naming.Binding) DestroyableResource(org.apache.openejb.api.resource.DestroyableResource) ArrayList(java.util.ArrayList) 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) ObjectName(javax.management.ObjectName) JMXContainer(org.apache.openejb.assembler.monitoring.JMXContainer) Container(org.apache.openejb.Container) SystemInstance(org.apache.openejb.loader.SystemInstance) ContainerSystemPreDestroy(org.apache.openejb.assembler.classic.event.ContainerSystemPreDestroy) NamingException(javax.naming.NamingException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) UndeployException(org.apache.openejb.UndeployException) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer) MBeanServer(javax.management.MBeanServer) AssemblerDestroyed(org.apache.openejb.assembler.classic.event.AssemblerDestroyed)

Example 15 with SystemInstance

use of org.apache.openejb.loader.SystemInstance in project tomee by apache.

the class BaseEjbProxyHandler method getLiveHandleRegistry.

public ConcurrentMap getLiveHandleRegistry() {
    final BeanContext beanContext = getBeanContext();
    final ThreadContext tc = ThreadContext.getThreadContext();
    if (tc != null && tc.getBeanContext() != beanContext && /* parent bean */
    tc.getCurrentOperation() == Operation.BUSINESS) {
        ProxyRegistry registry = tc.get(ProxyRegistry.class);
        if (registry == null) {
            registry = new ProxyRegistry();
            tc.set(ProxyRegistry.class, registry);
        }
        return registry.liveHandleRegistry;
    } else {
        // use the tx if there
        final SystemInstance systemInstance = SystemInstance.get();
        final TransactionManager txMgr = systemInstance.getComponent(TransactionManager.class);
        try {
            final Transaction tx = txMgr.getTransaction();
            if (tx != null && tx.getStatus() == Status.STATUS_ACTIVE) {
                final TransactionSynchronizationRegistry registry = systemInstance.getComponent(TransactionSynchronizationRegistry.class);
                final String resourceKey = ProxyRegistry.class.getName();
                ConcurrentMap map = ConcurrentMap.class.cast(registry.getResource(resourceKey));
                if (map == null) {
                    map = new ConcurrentHashMap();
                    registry.putResource(resourceKey, map);
                    try {
                        final ConcurrentMap tmp = map;
                        tx.registerSynchronization(new Synchronization() {

                            @Override
                            public void beforeCompletion() {
                            // no-op
                            }

                            @Override
                            public void afterCompletion(final int status) {
                                tmp.clear();
                            }
                        });
                    } catch (final RollbackException e) {
                    // not really possible since we check the status
                    // let it go to default
                    }
                }
                return map;
            }
        } catch (final SystemException e) {
        // let it go to default
        }
        // back to default but it doesnt release the memory
        ProxyRegistry proxyRegistry = beanContext.get(ProxyRegistry.class);
        if (proxyRegistry == null) {
            proxyRegistry = new ProxyRegistry();
            beanContext.set(ProxyRegistry.class, proxyRegistry);
        }
        return proxyRegistry.liveHandleRegistry;
    }
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) ConcurrentMap(java.util.concurrent.ConcurrentMap) Synchronization(javax.transaction.Synchronization) RollbackException(javax.transaction.RollbackException) BeanContext(org.apache.openejb.BeanContext) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) SystemInstance(org.apache.openejb.loader.SystemInstance) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

SystemInstance (org.apache.openejb.loader.SystemInstance)26 File (java.io.File)7 IOException (java.io.IOException)7 Properties (java.util.Properties)7 OpenEJBException (org.apache.openejb.OpenEJBException)7 MalformedURLException (java.net.MalformedURLException)5 ArrayList (java.util.ArrayList)5 URL (java.net.URL)4 NamingException (javax.naming.NamingException)4 BeanContext (org.apache.openejb.BeanContext)4 NoSuchApplicationException (org.apache.openejb.NoSuchApplicationException)4 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)4 UndeployException (org.apache.openejb.UndeployException)4 InvalidObjectException (java.io.InvalidObjectException)3 ObjectStreamException (java.io.ObjectStreamException)3 URISyntaxException (java.net.URISyntaxException)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 DefinitionException (javax.enterprise.inject.spi.DefinitionException)3 DeploymentException (javax.enterprise.inject.spi.DeploymentException)3