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);
}
}
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);
}
}
}
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);
}
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());
}
}
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);
}
}
}
Aggregations