deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ch...@apache.org
Subject git commit: DELTASPIKE-409 Servlet module events should be deactivatable
Date Tue, 03 Sep 2013 07:13:10 GMT
Updated Branches:
  refs/heads/master 28169465d -> 502fecd7a


DELTASPIKE-409 Servlet module events should be deactivatable


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/502fecd7
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/502fecd7
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/502fecd7

Branch: refs/heads/master
Commit: 502fecd7a66950665ee6dda1d13d1043f7d81a20
Parents: 2816946
Author: Christian Kaltepoth <christian@kaltepoth.de>
Authored: Tue Sep 3 09:12:29 2013 +0200
Committer: Christian Kaltepoth <christian@kaltepoth.de>
Committed: Tue Sep 3 09:12:29 2013 +0200

----------------------------------------------------------------------
 .../impl/event/EventBridgeContextListener.java  | 21 +++++++++++++---
 .../servlet/impl/event/EventBridgeFilter.java   | 25 ++++++++++++++++----
 .../impl/event/EventBridgeSessionListener.java  | 21 +++++++++++++---
 3 files changed, 56 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/502fecd7/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeContextListener.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeContextListener.java
b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeContextListener.java
index 2f7cd7c..c80d92e 100644
--- a/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeContextListener.java
+++ b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeContextListener.java
@@ -21,25 +21,40 @@ package org.apache.deltaspike.servlet.impl.event;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.util.ClassDeactivationUtils;
 import org.apache.deltaspike.servlet.api.literal.DestroyedLiteral;
 import org.apache.deltaspike.servlet.api.literal.InitializedLiteral;
 
 /**
  * This class listens for servlet context events and forwards them to the CDI event bus.
  */
-public class EventBridgeContextListener extends EventEmitter implements ServletContextListener
+public class EventBridgeContextListener extends EventEmitter implements ServletContextListener,
Deactivatable
 {
 
+    private final boolean activated;
+
+    public EventBridgeContextListener()
+    {
+        this.activated = ClassDeactivationUtils.isActivated(getClass());
+    }
+
     @Override
     public void contextInitialized(ServletContextEvent sce)
     {
-        fireEvent(sce.getServletContext(), InitializedLiteral.INSTANCE);
+        if (activated)
+        {
+            fireEvent(sce.getServletContext(), InitializedLiteral.INSTANCE);
+        }
     }
 
     @Override
     public void contextDestroyed(ServletContextEvent sce)
     {
-        fireEvent(sce.getServletContext(), DestroyedLiteral.INSTANCE);
+        if (activated)
+        {
+            fireEvent(sce.getServletContext(), DestroyedLiteral.INSTANCE);
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/502fecd7/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeFilter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeFilter.java
b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeFilter.java
index 529d4c7..ce1f279 100644
--- a/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeFilter.java
+++ b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeFilter.java
@@ -27,15 +27,24 @@ import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.util.ClassDeactivationUtils;
 import org.apache.deltaspike.servlet.api.literal.DestroyedLiteral;
 import org.apache.deltaspike.servlet.api.literal.InitializedLiteral;
 
 /**
  * This filter sends events to the CDI event bus when requests and responses get created
and destroyed.
  */
-public class EventBridgeFilter extends EventEmitter implements Filter
+public class EventBridgeFilter extends EventEmitter implements Filter, Deactivatable
 {
 
+    private final boolean activated;
+
+    public EventBridgeFilter()
+    {
+        this.activated = ClassDeactivationUtils.isActivated(getClass());
+    }
+
     @Override
     public void init(FilterConfig config) throws ServletException
     {
@@ -48,8 +57,11 @@ public class EventBridgeFilter extends EventEmitter implements Filter
     {
 
         // fire @Initialized events
-        fireEvent(request, InitializedLiteral.INSTANCE);
-        fireEvent(response, InitializedLiteral.INSTANCE);
+        if (activated)
+        {
+            fireEvent(request, InitializedLiteral.INSTANCE);
+            fireEvent(response, InitializedLiteral.INSTANCE);
+        }
 
         try
         {
@@ -58,8 +70,11 @@ public class EventBridgeFilter extends EventEmitter implements Filter
         finally
         {
             // fire @Destroyed events
-            fireEvent(request, DestroyedLiteral.INSTANCE);
-            fireEvent(response, DestroyedLiteral.INSTANCE);
+            if (activated)
+            {
+                fireEvent(request, DestroyedLiteral.INSTANCE);
+                fireEvent(response, DestroyedLiteral.INSTANCE);
+            }
         }
 
     }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/502fecd7/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeSessionListener.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeSessionListener.java
b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeSessionListener.java
index c923ec5..73f14c3 100644
--- a/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeSessionListener.java
+++ b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventBridgeSessionListener.java
@@ -21,24 +21,39 @@ package org.apache.deltaspike.servlet.impl.event;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionListener;
 
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.util.ClassDeactivationUtils;
 import org.apache.deltaspike.servlet.api.literal.DestroyedLiteral;
 import org.apache.deltaspike.servlet.api.literal.InitializedLiteral;
 
 /**
  * This class listens for HTTP session events and forwards them to the CDI event bus.
  */
-public class EventBridgeSessionListener extends EventEmitter implements HttpSessionListener
+public class EventBridgeSessionListener extends EventEmitter implements HttpSessionListener,
Deactivatable
 {
 
+    private final boolean activated;
+
+    public EventBridgeSessionListener()
+    {
+        this.activated = ClassDeactivationUtils.isActivated(getClass());
+    }
+
     @Override
     public void sessionCreated(HttpSessionEvent se)
     {
-        fireEvent(se.getSession(), InitializedLiteral.INSTANCE);
+        if (activated)
+        {
+            fireEvent(se.getSession(), InitializedLiteral.INSTANCE);
+        }
     }
 
     @Override
     public void sessionDestroyed(HttpSessionEvent se)
     {
-        fireEvent(se.getSession(), DestroyedLiteral.INSTANCE);
+        if (activated)
+        {
+            fireEvent(se.getSession(), DestroyedLiteral.INSTANCE);
+        }
     }
 }


Mime
View raw message