Search in sources :

Example 11 with ExoContainer

use of org.exoplatform.container.ExoContainer in project kernel by exoplatform.

the class JobEnvironmentConfigListener method jobToBeExecuted.

public void jobToBeExecuted(JobExecutionContext context) {
    String containerName = extractContainerName(context);
    ExoContainer container = null;
    if (containerName != null) {
        if (containerName.equals(JobSchedulerServiceImpl.STANDALONE_CONTAINER_NAME)) {
            container = ExoContainerContext.getTopContainer();
        } else {
            RootContainer rootContainer = RootContainer.getInstance();
            container = (ExoContainer) rootContainer.getComponentInstance(containerName);
        }
    }
    if (container != null) {
        ExoContainerContext.setCurrentContainer(container);
        RequestLifeCycle.begin(container);
    }
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) RootContainer(org.exoplatform.container.RootContainer)

Example 12 with ExoContainer

use of org.exoplatform.container.ExoContainer in project kernel by exoplatform.

the class ContextManagerListener method requestDestroyed.

/**
 * {@inheritDoc}
 */
public void requestDestroyed(ServletRequestEvent event) {
    final ExoContainer oldContainer = ExoContainerContext.getCurrentContainerIfPresent();
    ExoContainer container = null;
    boolean hasBeenSet = false;
    try {
        container = getContainer(event);
        if (container == null)
            return;
        if (!container.equals(oldContainer)) {
            if (container instanceof PortalContainer) {
                PortalContainer.setInstance((PortalContainer) container);
            }
            ExoContainerContext.setCurrentContainer(container);
            hasBeenSet = true;
        }
        onRequestDestroyed(container, event);
    } finally {
        if (hasBeenSet) {
            if (container instanceof PortalContainer) {
                // Remove the current Portal Container and the current ExoContainer
                PortalContainer.setInstance(null);
            }
            // Re-set the old container
            ExoContainerContext.setCurrentContainer(oldContainer);
        }
    }
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) PortalContainer(org.exoplatform.container.PortalContainer)

Example 13 with ExoContainer

use of org.exoplatform.container.ExoContainer in project kernel by exoplatform.

the class TestSchedulerService method testMultiplePortalContainers.

public void testMultiplePortalContainers() throws Exception {
    ExoContainer oldContainer = ExoContainerContext.getCurrentContainerIfPresent();
    MyComponent component;
    PortalContainer container = null;
    MyComponent component2;
    PortalContainer container2 = null;
    String oldProfileList = System.getProperty(PropertyManager.RUNTIME_PROFILES);
    try {
        try {
            PropertyManager.setProperty(PropertyManager.RUNTIME_PROFILES, "MultiplePortalContainers");
            component = (MyComponent) (container = RootContainer.getInstance().getPortalContainer("portal-container")).getComponentInstanceOfType(MyComponent.class);
        } finally {
            ExoContainerContext.setCurrentContainer(oldContainer);
        }
        try {
            PropertyManager.setProperty(PropertyManager.RUNTIME_PROFILES, "MultiplePortalContainers,portal-container2");
            component2 = (MyComponent) (container2 = RootContainer.getInstance().getPortalContainer("portal-container2")).getComponentInstanceOfType(MyComponent.class);
            Thread.sleep(2000);
        } finally {
            ExoContainerContext.setCurrentContainer(oldContainer);
        }
    } finally {
        if (oldProfileList == null) {
            System.clearProperty(PropertyManager.RUNTIME_PROFILES);
        } else {
            System.setProperty(PropertyManager.RUNTIME_PROFILES, oldProfileList);
        }
        PropertyManager.refresh();
    }
    assertEquals("myJob1", component.name);
    assertEquals(container, component.container);
    assertTrue(component.endRequest > 0);
    assertFalse(component.endRequestFailed);
    assertEquals("myJob2", component2.name);
    assertEquals(container2, component2.container);
    assertTrue(component2.endRequest > 0);
    assertFalse(component2.endRequestFailed);
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) PortalContainer(org.exoplatform.container.PortalContainer)

Example 14 with ExoContainer

use of org.exoplatform.container.ExoContainer in project kernel by exoplatform.

the class ManageableComponentAdapterMT method destroy.

/**
 * {@inheritDoc}
 */
@Override
public void destroy(T instance, CreationalContext<T> creationalContext) {
    try {
        Container co = exocontainer;
        do {
            if (co instanceof ManageableContainer) {
                break;
            }
        } while ((co = co.getSuccessor()) != null);
        if (co instanceof ManageableContainer) {
            ManageableContainer container = (ManageableContainer) co;
            if (container.managementContext != null) {
                // UnRegister the instance against the management context
                if (LOG.isDebugEnabled())
                    LOG.debug("==> remove " + instance + " from a mbean server");
                container.managementContext.unregister(instance);
            }
        }
        creationalContext.release();
    } catch (Exception e) {
        LOG.error("Could not destroy the instance " + instance + ": " + e.getMessage());
    }
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) Container(org.exoplatform.container.spi.Container)

Example 15 with ExoContainer

use of org.exoplatform.container.ExoContainer in project kernel by exoplatform.

the class AbstractHttpServlet method service.

/**
 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
public final void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    final ExoContainer oldContainer = ExoContainerContext.getCurrentContainer();
    // Keep the old ClassLoader
    final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    ExoContainer container = null;
    boolean hasBeenSet = false;
    try {
        container = getContainer();
        if (!container.equals(oldContainer)) {
            if (container instanceof PortalContainer) {
                PortalContainer.setInstance((PortalContainer) container);
            }
            ExoContainerContext.setCurrentContainer(container);
            hasBeenSet = true;
        }
        if (requirePortalEnvironment()) {
            final String ctxName = ContainerUtil.getServletContextName(config.getServletContext());
            if (!PortalContainer.isPortalContainerNameDisabled(ctxName) && container instanceof PortalContainer) {
                if (PortalContainer.getInstanceIfPresent() == null) {
                    // The portal container has not been set
                    PortalContainer.setInstance((PortalContainer) container);
                    hasBeenSet = true;
                }
                // Set the full classloader of the portal container
                Thread.currentThread().setContextClassLoader(((PortalContainer) container).getPortalClassLoader());
            } else {
                onPortalEnvironmentError(req, res);
                return;
            }
        }
        onService(container, req, res);
    } finally {
        if (hasBeenSet) {
            if (container instanceof PortalContainer) {
                // Remove the current Portal Container and the current ExoContainer
                PortalContainer.setInstance(null);
            }
            // Re-set the old container
            ExoContainerContext.setCurrentContainer(oldContainer);
        }
        if (requirePortalEnvironment()) {
            // Re-set the old classloader
            Thread.currentThread().setContextClassLoader(currentClassLoader);
        }
    }
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) PortalContainer(org.exoplatform.container.PortalContainer)

Aggregations

ExoContainer (org.exoplatform.container.ExoContainer)18 PortalContainer (org.exoplatform.container.PortalContainer)7 RootContainer (org.exoplatform.container.RootContainer)4 ArrayList (java.util.ArrayList)3 ConcurrentContainer (org.exoplatform.container.ConcurrentContainer)2 Container (org.exoplatform.container.spi.Container)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Singleton (javax.inject.Singleton)1 MBeanServer (javax.management.MBeanServer)1 ObjectInstance (javax.management.ObjectInstance)1 CachingContainer (org.exoplatform.container.CachingContainer)1 ComponentTask (org.exoplatform.container.ComponentTask)1 ConcurrentContainerMT (org.exoplatform.container.ConcurrentContainerMT)1 CyclicDependencyException (org.exoplatform.container.CyclicDependencyException)1 Dependency (org.exoplatform.container.Dependency)1 ComponentLifecycle (org.exoplatform.container.component.ComponentLifecycle)1 ComponentRequestLifecycle (org.exoplatform.container.component.ComponentRequestLifecycle)1 ConfigurationManager (org.exoplatform.container.configuration.ConfigurationManager)1