deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject [1/2] git commit: DELTASPIKE-656 fixed scope handling
Date Fri, 04 Jul 2014 10:15:24 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 0584be0cf -> 5aaff2bfd


DELTASPIKE-656 fixed scope handling


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

Branch: refs/heads/master
Commit: 31d0266b2789e55107959a78972bad827c667dce
Parents: 0584be0
Author: gpetracek <gpetracek@apache.org>
Authored: Fri Jul 4 11:44:29 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Fri Jul 4 11:44:29 2014 +0200

----------------------------------------------------------------------
 .../scheduler/impl/QuartzScheduler.java         | 51 ++++++++++++++------
 1 file changed, 37 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/31d0266b/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java
b/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java
index 7bba1a5..fe02e69 100644
--- a/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java
+++ b/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java
@@ -61,6 +61,8 @@ public class QuartzScheduler implements Scheduler<Job>
     private static final Logger LOG = Logger.getLogger(QuartzScheduler.class.getName());
     private static final Scheduled DEFAULT_SCHEDULED_LITERAL = AnnotationInstanceProvider.of(Scheduled.class);
 
+    private static ThreadLocal<JobListenerContext> currentJobListenerContext = new
ThreadLocal<JobListenerContext>();
+
     protected org.quartz.Scheduler scheduler;
 
     @Override
@@ -346,9 +348,6 @@ public class QuartzScheduler implements Scheduler<Job>
 
     private class InjectionAwareJobListener implements JobListener
     {
-        private Stack<Class<? extends Annotation>> scopes = new Stack<Class<?
extends Annotation>>();
-        private ContextControl contextControl;
-
         @Override
         public String getName()
         {
@@ -367,17 +366,9 @@ public class QuartzScheduler implements Scheduler<Job>
                 scheduled = DEFAULT_SCHEDULED_LITERAL;
             }
 
-            Collections.addAll(this.scopes, scheduled.startScopes());
-
-            if (!this.scopes.isEmpty())
-            {
-                this.contextControl = BeanProvider.getContextualReference(ContextControl.class);
-
-                for (Class<? extends Annotation> scopeAnnotation : this.scopes)
-                {
-                    contextControl.startContext(scopeAnnotation);
-                }
-            }
+            JobListenerContext jobListenerContext = new JobListenerContext();
+            currentJobListenerContext.set(jobListenerContext);
+            jobListenerContext.startContexts(scheduled);
 
             boolean jobInstanceIsBean;
 
@@ -411,6 +402,38 @@ public class QuartzScheduler implements Scheduler<Job>
 
         private void stopStartedScopes()
         {
+            JobListenerContext jobListenerContext = currentJobListenerContext.get();
+            if (jobListenerContext != null)
+            {
+                jobListenerContext.stopStartedScopes();
+                currentJobListenerContext.set(null);
+                currentJobListenerContext.remove();
+            }
+        }
+    }
+
+    private class JobListenerContext
+    {
+        private Stack<Class<? extends Annotation>> scopes = new Stack<Class<?
extends Annotation>>();
+        private ContextControl contextControl;
+
+        public void startContexts(Scheduled scheduled)
+        {
+            Collections.addAll(this.scopes, scheduled.startScopes());
+
+            if (!this.scopes.isEmpty())
+            {
+                this.contextControl = BeanProvider.getContextualReference(ContextControl.class);
+
+                for (Class<? extends Annotation> scopeAnnotation : this.scopes)
+                {
+                    contextControl.startContext(scopeAnnotation);
+                }
+            }
+        }
+
+        private void stopStartedScopes()
+        {
             while (!this.scopes.empty())
             {
                 this.contextControl.stopContext(this.scopes.pop());


Mime
View raw message