You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2007/09/25 17:37:47 UTC

svn commit: r579300 - /incubator/sling/trunk/scheduler/src/main/java/org/apache/sling/scheduler/impl/QuartzScheduler.java

Author: cziegeler
Date: Tue Sep 25 08:37:46 2007
New Revision: 579300

URL: http://svn.apache.org/viewvc?rev=579300&view=rev
Log:
Fix registering of tasks and jobs.

Modified:
    incubator/sling/trunk/scheduler/src/main/java/org/apache/sling/scheduler/impl/QuartzScheduler.java

Modified: incubator/sling/trunk/scheduler/src/main/java/org/apache/sling/scheduler/impl/QuartzScheduler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scheduler/src/main/java/org/apache/sling/scheduler/impl/QuartzScheduler.java?rev=579300&r1=579299&r2=579300&view=diff
==============================================================================
--- incubator/sling/trunk/scheduler/src/main/java/org/apache/sling/scheduler/impl/QuartzScheduler.java (original)
+++ incubator/sling/trunk/scheduler/src/main/java/org/apache/sling/scheduler/impl/QuartzScheduler.java Tue Sep 25 08:37:46 2007
@@ -45,8 +45,8 @@
  *
  * @scr.component
  * @scr.service interface="org.apache.sling.scheduler.Scheduler"
- * @scr.reference name="job" interface="org.apache.sling.scheduler.Job" cardinality="0..n" policy="dynamic" bind="bindJob" unbind="unbindJob"
- * @scr.reference name="task" interface="java.lang.Runnable" cardinality="0..n" policy="dynamic" bind="bindJob" unbind="unbindJob"
+ * @scr.reference name="job" interface="org.apache.sling.scheduler.Job" cardinality="0..n" policy="dynamic"
+ * @scr.reference name="task" interface="java.lang.Runnable" cardinality="0..n" policy="dynamic"
  */
 public class QuartzScheduler implements Scheduler {
 
@@ -72,7 +72,7 @@
 
     protected org.quartz.Scheduler scheduler;
 
-    protected final List<ServiceReference> registeredJobs = new ArrayList<ServiceReference>();
+    protected final List<Object[]> registeredJobs = new ArrayList<Object[]>();
 
     protected ComponentContext context;
 
@@ -86,13 +86,13 @@
         this.context = ctx;
         synchronized ( this.registeredJobs ) {
             this.init();
-            for( ServiceReference ref : this.registeredJobs ) {
+            for( Object[] arr : this.registeredJobs ) {
                 try {
-                    this.register(ref);
+                    this.register((String)arr[0], (ServiceReference)arr[1]);
                 } catch (Exception e) {
                     // we don't want that one malicious service brings down the scheduler, so we just log
                     // the exception and continue
-                    this.logger.error("Exception during registering job service {}.", ref, e);
+                    this.logger.error("Exception during registering job service {}.", arr[1], e);
                 }
             }
             this.registeredJobs.clear();
@@ -293,10 +293,9 @@
         }
     }
 
-    protected void register(ServiceReference ref)
+    protected void register(String type, ServiceReference ref)
     throws Exception {
-        // get the job
-        final Object job = this.context.locateService("job", ref);
+        final Object job = this.context.locateService(type, ref);
         if ( ref != null ) {
             this.checkJob(job);
             String name = (String)ref.getProperty("scheduler.name");
@@ -339,9 +338,9 @@
     throws Exception {
         synchronized ( this.registeredJobs ) {
             if ( this.scheduler != null ) {
-                this.register(ref);
+                this.register("job", ref);
             } else {
-                this.registeredJobs.add(ref);
+                this.registeredJobs.add(new Object[] {"job", ref});
             }
         }
     }
@@ -351,6 +350,34 @@
      * @param ref
      */
     protected void unbindJob(ServiceReference ref) {
+        synchronized ( this.registeredJobs ) {
+            if ( this.scheduler != null ) {
+                this.unregister(ref);
+            }
+        }
+    }
+
+    /**
+     * Bind a new job.
+     * @param ref
+     * @throws Exception
+     */
+    protected void bindTask(ServiceReference ref)
+    throws Exception {
+        synchronized ( this.registeredJobs ) {
+            if ( this.scheduler != null ) {
+                this.register("task", ref);
+            } else {
+                this.registeredJobs.add(new Object[] {"task", ref});
+            }
+        }
+    }
+
+    /**
+     * Unbind a job.
+     * @param ref
+     */
+    protected void unbindTask(ServiceReference ref) {
         synchronized ( this.registeredJobs ) {
             if ( this.scheduler != null ) {
                 this.unregister(ref);