Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
Improve the kernel life cycle and reuse the PortalContainer.getInstan…
Browse files Browse the repository at this point in the history
…ce() API
  • Loading branch information
vietj committed Jun 25, 2013
1 parent 8786276 commit bcf49c5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public class KernelLifeCycle implements Filter {
/** . */
private static final ThreadLocal<PortalContainer> current = new ThreadLocal<PortalContainer>();

static PortalContainer getCurrentContainer() {
return current.get();
}

@Override
public void init(FilterConfig filterConfig) throws ServletException {
RootContainer.PortalContainerPostCreateTask task = new RootContainer.PortalContainerPostCreateTask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ public class KernelProviderFactory implements ProviderFactory {

@Override
public <T> Provider<? extends T> getProvider(final Class<T> implementationType) throws Exception {



final PortalContainer container = KernelLifeCycle.getCurrentContainer();
final PortalContainer container = PortalContainer.getInstance();
if (container == null) {
throw new IllegalStateException("Not running in the context of a portal container");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,23 @@ public static WebArchive getDeployment() {
}

/** . */
public static PortalContainer container;
public static PortalContainer container1;

/** . */
public static PortalContainer container2;

@ArquillianResource
URL deploymentURL;

@Test
@RunAsClient
public void testContainer() throws Exception {
container = null;
container1 = null;
HttpURLConnection conn = (HttpURLConnection) deploymentURL.openConnection();
conn.connect();
assertEquals(200, conn.getResponseCode());
assertNotNull(container);
assertNotNull(container1);
assertNotNull(container2);
assertSame(container1, container2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.gatein.portal.common.kernel;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
Expand All @@ -34,9 +36,23 @@ public class ServletImpl extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
KernelLifeCycleTestCase.container = KernelLifeCycle.getCurrentContainer();
resp.setStatus(200);
resp.setContentType("text/plain");
resp.getWriter().append("done").close();
KernelLifeCycleTestCase.container1 = PortalContainer.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
Runnable task = KernelLifeCycle.wrap(new Runnable() {
@Override
public void run() {
KernelLifeCycleTestCase.container2 = PortalContainer.getInstance();
latch.countDown();
}
});
new Thread(task).start();
try {
latch.await(10, TimeUnit.SECONDS);
resp.setStatus(200);
resp.setContentType("text/plain");
resp.getWriter().append("done").close();
} catch (InterruptedException e) {
resp.setStatus(500);
}
}
}

0 comments on commit bcf49c5

Please sign in to comment.