incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r708122 - /incubator/sling/trunk/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java
Date Mon, 27 Oct 2008 09:59:31 GMT
Author: cziegeler
Date: Mon Oct 27 02:59:30 2008
New Revision: 708122

URL: http://svn.apache.org/viewvc?rev=708122&view=rev
Log:
SLING-710 : Append service id to unique job identifier to correctly handle bind/unbind.

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

Modified: incubator/sling/trunk/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java?rev=708122&r1=708121&r2=708122&view=diff
==============================================================================
--- incubator/sling/trunk/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java
(original)
+++ incubator/sling/trunk/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java
Mon Oct 27 02:59:30 2008
@@ -312,45 +312,53 @@
     public void removeJob(String name) throws NoSuchElementException {
         try {
             this.scheduler.deleteJob(name, DEFAULT_QUARTZ_JOB_GROUP);
+            this.logger.debug("Unscheduling job with name {}", name);
         } catch (final SchedulerException se) {
             throw new NoSuchElementException(se.getMessage());
         }
     }
 
-    protected void register(String type, ServiceReference ref)
+    /**
+     * Create unique identifier
+     * @param type
+     * @param ref
+     * @throws Exception
+     */
+    private String getServiceIdentifier(final ServiceReference ref) {
+        String name = (String)ref.getProperty(Scheduler.PROPERTY_SCHEDULER_NAME);
+        if ( name == null ) {
+            name = (String)ref.getProperty(Constants.SERVICE_PID);
+            if ( name == null ) {
+                name = "Registered Service";
+            }
+        }
+        // now append service id to create a unique identifer
+        name = name + "." + ref.getProperty(Constants.SERVICE_ID);
+        return name;
+    }
+
+    private void register(String type, ServiceReference ref)
     throws Exception {
         final Object job = this.context.locateService(type, ref);
         if ( ref != null ) {
             this.checkJob(job);
-            String name = (String)ref.getProperty(Scheduler.PROPERTY_SCHEDULER_NAME);
-            if ( name == null ) {
-                name = (String)ref.getProperty(Constants.SERVICE_PID);
-            }
-            if ( name != null ) {
-                final Boolean concurrent = (Boolean)ref.getProperty(Scheduler.PROPERTY_SCHEDULER_CONCURRENT);
-                final String expression = (String)ref.getProperty(Scheduler.PROPERTY_SCHEDULER_EXPRESSION);
-                if ( expression != null ) {
-                    this.addJob(name, job, null, expression, (concurrent != null ? concurrent
: true));
-                } else {
-                    final Long period = (Long)ref.getProperty(Scheduler.PROPERTY_SCHEDULER_PERIOD);
-                    if ( period != null ) {
-                        this.addPeriodicJob(name, job, null, period, (concurrent != null
? concurrent : true));
-                    }
-                }
+            final String name = getServiceIdentifier(ref);
+            final Boolean concurrent = (Boolean)ref.getProperty(Scheduler.PROPERTY_SCHEDULER_CONCURRENT);
+            final String expression = (String)ref.getProperty(Scheduler.PROPERTY_SCHEDULER_EXPRESSION);
+            if ( expression != null ) {
+                this.addJob(name, job, null, expression, (concurrent != null ? concurrent
: true));
             } else {
-                throw new Exception("Job service must either have a PID or a configured property
'scheduler.name'.");
+                final Long period = (Long)ref.getProperty(Scheduler.PROPERTY_SCHEDULER_PERIOD);
+                if ( period != null ) {
+                    this.addPeriodicJob(name, job, null, period, (concurrent != null ? concurrent
: true));
+                }
             }
         }
     }
 
-    protected void unregister(ServiceReference ref) {
-        String name = (String)ref.getProperty(Scheduler.PROPERTY_SCHEDULER_NAME);
-        if ( name == null ) {
-            name = (String)ref.getProperty(Constants.SERVICE_PID);
-        }
-        if ( name != null ) {
-            this.removeJob(name);
-        }
+    private void unregister(ServiceReference ref) {
+        final String name = getServiceIdentifier(ref);
+        this.removeJob(name);
     }
 
     /**



Mime
View raw message