You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2020/02/11 13:15:48 UTC

[openwebbeans] branch master updated: OWB-1313 ensure RequestContextController impl is thread safe

This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new a99f560  OWB-1313 ensure RequestContextController impl is thread safe
a99f560 is described below

commit a99f5606590db09a9a083a5aaf690c6f1ad856e3
Author: Romain Manni-Bucau <rm...@gmail.com>
AuthorDate: Tue Feb 11 14:15:38 2020 +0100

    OWB-1313 ensure RequestContextController impl is thread safe
---
 .../control/OwbRequestContextController.java       | 25 ++++++++--------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/context/control/OwbRequestContextController.java b/webbeans-impl/src/main/java/org/apache/webbeans/context/control/OwbRequestContextController.java
index 5bc30b5..d48852b 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/context/control/OwbRequestContextController.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/context/control/OwbRequestContextController.java
@@ -20,6 +20,8 @@
 package org.apache.webbeans.context.control;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.intercept.RequestScopedBeanInterceptorHandler;
+import org.apache.webbeans.spi.ContextsService;
 
 import javax.enterprise.context.ContextNotActiveException;
 import javax.enterprise.context.RequestScoped;
@@ -28,26 +30,20 @@ import javax.enterprise.context.spi.Context;
 
 public class OwbRequestContextController implements RequestContextController
 {
-    private final WebBeansContext context;
-    private Object startParam = null;
+    private final ContextsService contextsService;
 
     OwbRequestContextController(WebBeansContext context)
     {
-        this.context = context;
+        this.contextsService = context.getContextsService();
     }
 
     @Override
     public boolean activate()
     {
-        if (startParam != null)
+        final Context ctx = contextsService.getCurrentContext(RequestScoped.class);
+        if (ctx == null || !ctx.isActive())
         {
-            return false;
-        }
-        Context ctx = context.getContextsService().getCurrentContext(RequestScoped.class);
-        if (ctx == null)
-        {
-            startParam = new Object();
-            context.getContextsService().startContext(RequestScoped.class, startParam);
+            contextsService.startContext(RequestScoped.class, null);
             return true;
         }
         return false;
@@ -56,10 +52,7 @@ public class OwbRequestContextController implements RequestContextController
     @Override
     public void deactivate() throws ContextNotActiveException
     {
-        if (startParam != null)
-        {
-            context.getContextsService().endContext(RequestScoped.class, startParam);
-            startParam = null;
-        }
+        contextsService.endContext(RequestScoped.class, null);
+        RequestScopedBeanInterceptorHandler.removeThreadLocals();
     }
 }