Search in sources :

Example 6 with ExoContainer

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

the class ManageableComponentAdapter 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 : ConcurrentContainer(org.exoplatform.container.ConcurrentContainer) ExoContainer(org.exoplatform.container.ExoContainer) Container(org.exoplatform.container.spi.Container)

Example 7 with ExoContainer

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

the class AbstractHttpSessionListener method sessionCreated.

/**
 * @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
 */
public final void sessionCreated(HttpSessionEvent event) {
    final ExoContainer oldContainer = ExoContainerContext.getCurrentContainerIfPresent();
    // Keep the old ClassLoader
    final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    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;
        }
        if (requirePortalEnvironment()) {
            final String ctxName = ContainerUtil.getServletContextName(event.getSession().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 {
                if (PropertyManager.isDevelopping()) {
                    LOG.info("The portal environment could not be set for the webapp '" + ctxName + "' because this servlet context has not been defined as a " + "dependency of any portal container or it is a disabled portal" + " container, the sessionCreated event will be ignored");
                }
                return;
            }
        }
        onSessionCreated(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);
        }
        if (requirePortalEnvironment()) {
            // Re-set the old classloader
            Thread.currentThread().setContextClassLoader(currentClassLoader);
        }
    }
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) PortalContainer(org.exoplatform.container.PortalContainer)

Example 8 with ExoContainer

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

the class TestKernelExtension method testInterceptorsInternal.

private void testInterceptorsInternal(ExoContainer parent) {
    MockInterceptor1 i1 = null;
    MockInterceptor2 i2 = null;
    MockInterceptor3 i3 = null;
    MockInterceptor4 i4 = null;
    MockInterceptor5 i5 = null;
    MockInterceptor6 i6 = null;
    MockInterceptor7 i7 = null;
    MockInterceptor8 i8 = null;
    MockInterceptor9 i9 = null;
    ExoContainer holder = new ExoContainer(parent);
    Container container = holder;
    while ((container = container.getSuccessor()) != null) {
        if (container instanceof MockInterceptor1) {
            i1 = (MockInterceptor1) container;
        } else if (container instanceof MockInterceptor2) {
            i2 = (MockInterceptor2) container;
        } else if (container instanceof MockInterceptor3) {
            i3 = (MockInterceptor3) container;
        } else if (container instanceof MockInterceptor4) {
            i4 = (MockInterceptor4) container;
        } else if (container instanceof MockInterceptor5) {
            i5 = (MockInterceptor5) container;
        } else if (container instanceof MockInterceptor6) {
            i6 = (MockInterceptor6) container;
        } else if (container instanceof MockInterceptor7) {
            i7 = (MockInterceptor7) container;
        } else if (container instanceof MockInterceptor8) {
            i8 = (MockInterceptor8) container;
        } else if (container instanceof MockInterceptor9) {
            i9 = (MockInterceptor9) container;
        }
    }
    assertNotNull(i1);
    assertNotNull(i1.getSuccessor());
    assertSame(parent, i1.getParent());
    assertSame(holder, i1.getHolder());
    assertEquals("MockInterceptor1", i1.getId());
    assertNotNull(i2);
    assertNotNull(i2.getSuccessor());
    assertSame(parent, i2.getParent());
    assertSame(holder, i2.getHolder());
    assertEquals("MockInterceptor2", i2.getId());
    assertNotNull(i3);
    assertNotNull(i3.getSuccessor());
    assertSame(parent, i3.getParent());
    assertSame(holder, i3.getHolder());
    assertEquals("MockInterceptor3", i3.getId());
    assertNotNull(i4);
    assertNotNull(i4.getSuccessor());
    assertSame(parent, i4.getParent());
    assertSame(holder, i4.getHolder());
    assertEquals("MockInterceptor4", i4.getId());
    assertNotNull(i5);
    assertNotNull(i5.getSuccessor());
    assertSame(parent, i5.getParent());
    assertSame(holder, i5.getHolder());
    assertEquals("MockInterceptor5", i5.getId());
    assertNotNull(i6);
    assertNotNull(i6.getSuccessor());
    assertSame(parent, i6.getParent());
    assertSame(holder, i6.getHolder());
    assertEquals("MockInterceptor6", i6.getId());
    assertNotNull(i7);
    assertNotNull(i7.getSuccessor());
    assertSame(parent, i7.getParent());
    assertSame(holder, i7.getHolder());
    assertEquals("MockInterceptor7", i7.getId());
    assertNotNull(i8);
    assertNull(i8.getSuccessor());
    assertSame(parent, i8.getParent());
    assertSame(holder, i8.getHolder());
    assertEquals("MockInterceptor8", i8.getId());
    assertNotNull(i9);
    assertNotNull(i9.getSuccessor());
    assertSame(i5, i9.getSuccessor());
    assertSame(parent, i9.getParent());
    assertSame(holder, i9.getHolder());
    assertEquals("MockInterceptor9", i9.getId());
    assertSame(i9, holder.getSuccessor());
    Test0 t0I = new Test0();
    Test1 t1I = new Test1();
    Test2 t2I = new Test2();
    Test3 t3I = new Test3();
    holder.registerComponentInstance(Test0.class, t0I);
    holder.registerComponentInstance(Test1.class, t1I);
    holder.registerComponentInstance(Test2.class, t2I);
    holder.registerComponentInstance(Test3.class, t3I);
    holder.registerComponentImplementation(Test5.class);
    assertSame(t0I, holder.getComponentInstanceOfType(Test0.class));
    Test1 t1FC = holder.getComponentInstanceOfType(Test1.class);
    assertNotSame(t1I, t1FC);
    // A new instance is created at each call so it must not be the same as before
    assertNotSame(t1FC, holder.getComponentInstanceOfType(Test1.class));
    Test2 t2FC = holder.getComponentInstanceOfType(Test2.class);
    assertNotSame(t2I, t2FC);
    // It comes from the cache so it must be the same than before
    assertSame(t2FC, holder.getComponentInstanceOfType(Test2.class));
    Test3 t3FC = holder.getComponentInstanceOfType(Test3.class);
    assertSame(MockInterceptor1.TEST, t3FC);
    Test5 t4FC = holder.getComponentInstanceOfType(Test5.class);
    assertSame(t0I, t4FC.t0);
    assertNotSame(t1I, t4FC.t1);
    assertNotSame(t2I, t4FC.t2);
    assertSame(t3FC, t4FC.t3);
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) ConcurrentContainer(org.exoplatform.container.ConcurrentContainer) CachingContainer(org.exoplatform.container.CachingContainer) ManageableContainer(org.exoplatform.container.management.ManageableContainer) ExoContainer(org.exoplatform.container.ExoContainer)

Example 9 with ExoContainer

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

the class TestKernelExtension method testFactory.

public void testFactory() {
    try {
        MockInterceptorChainFactory.mode = 1;
        ExoContainer container = new ExoContainer();
        assertTrue(container.getSuccessor() instanceof MockInterceptor);
    } finally {
        MockInterceptorChainFactory.mode = 0;
    }
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer)

Example 10 with ExoContainer

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

the class JobEnvironmentConfigListener method jobWasExecuted.

public void jobWasExecuted(JobExecutionContext context, JobExecutionException exception) {
    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) {
        List<ComponentRequestLifecycle> components = container.getComponentInstancesOfType(ComponentRequestLifecycle.class);
        for (ComponentRequestLifecycle component : components) {
            component.endRequest(container);
        }
        RequestLifeCycle.end();
        ExoContainerContext.setCurrentContainer(null);
    }
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) RootContainer(org.exoplatform.container.RootContainer) ComponentRequestLifecycle(org.exoplatform.container.component.ComponentRequestLifecycle)

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