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 2011/05/02 07:51:07 UTC

svn commit: r1098485 - in /sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl: QuartzScheduler.java WebConsolePrinter.java

Author: cziegeler
Date: Mon May  2 05:51:06 2011
New Revision: 1098485

URL: http://svn.apache.org/viewvc?rev=1098485&view=rev
Log:
SLING-2064 : Scheduled jobs with a negative period or zero should be ignored

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

Modified: sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java?rev=1098485&r1=1098484&r2=1098485&view=diff
==============================================================================
--- sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java (original)
+++ sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java Mon May  2 05:51:06 2011
@@ -505,7 +505,7 @@ public class QuartzScheduler implements 
      * @param type The type (job or task)
      * @param ref The service reference
      */
-    private void register(String type, ServiceReference ref) {
+    private void register(final String type, final ServiceReference ref) {
         // we called from bind, it might be that deactivate has been
         // called in the meantime
         final ComponentContext ctx = this.context;
@@ -522,13 +522,21 @@ public class QuartzScheduler implements 
                     } else {
                         final Long period = (Long)ref.getProperty(Scheduler.PROPERTY_SCHEDULER_PERIOD);
                         if ( period != null ) {
-                            this.addPeriodicJob(name, job, null, period, (concurrent != null ? concurrent : true));
+                            if ( period < 1 ) {
+                                this.logger.debug("Ignoring service {} : scheduler period is less than 1.", ref);
+                            } else {
+                                this.addPeriodicJob(name, job, null, period, (concurrent != null ? concurrent : true));
+                            }
+                        } else {
+                            this.logger.debug("Ignoring servce {} : no scheduling property found.", ref);
                         }
                     }
-                } catch (IllegalStateException e) {
-                    // this can happen if deactivate has been called - therefore ignoring
-                } catch (SchedulerException e) {
-                    // this can happen if deactivate has been called - therefore ignoring
+                } catch (final IllegalStateException e) {
+                    // this can happen if deactivate has been called or the scheduling expression is invalid
+                    this.logger.warn("Ignoring servce " + ref + " : exception occurred during registering.", e);
+                } catch (final SchedulerException e) {
+                    // this can happen if deactivate has been called or the scheduling expression is invalid
+                    this.logger.warn("Ignoring servce " + ref + " : exception occurred during registering.", e);
                 }
             }
         }
@@ -538,7 +546,7 @@ public class QuartzScheduler implements 
      * Unregister a service.
      * @param ref The service reference.
      */
-    private void unregister(ServiceReference ref) {
+    private void unregister(final ServiceReference ref) {
         try {
             final String name = getServiceIdentifier(ref);
             this.removeJob(name);
@@ -552,7 +560,7 @@ public class QuartzScheduler implements 
      * @param ref
      * @throws Exception
      */
-    protected void bindJob(ServiceReference ref) {
+    protected void bindJob(final ServiceReference ref) {
         if ( this.scheduler != null ) {
             this.register(Registration.JOB, ref);
         } else {
@@ -566,7 +574,7 @@ public class QuartzScheduler implements 
      * Unbind a job.
      * @param ref
      */
-    protected void unbindJob(ServiceReference ref) {
+    protected void unbindJob(final ServiceReference ref) {
         if ( this.scheduler != null ) {
             this.unregister(ref);
         } else {
@@ -581,7 +589,7 @@ public class QuartzScheduler implements 
      * @param ref
      * @throws Exception
      */
-    protected void bindTask(ServiceReference ref) {
+    protected void bindTask(final ServiceReference ref) {
         if ( this.scheduler != null ) {
             this.register(Registration.TASK, ref);
         } else {
@@ -595,7 +603,7 @@ public class QuartzScheduler implements 
      * Unbind a task.
      * @param ref
      */
-    protected void unbindTask(ServiceReference ref) {
+    protected void unbindTask(final ServiceReference ref) {
         if ( this.scheduler != null ) {
             this.unregister(ref);
         } else {

Modified: sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/WebConsolePrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/WebConsolePrinter.java?rev=1098485&r1=1098484&r2=1098485&view=diff
==============================================================================
--- sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/WebConsolePrinter.java (original)
+++ sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/WebConsolePrinter.java Mon May  2 05:51:06 2011
@@ -91,6 +91,7 @@ public class WebConsolePrinter {
                     pw.print  ("Group ");
                     pw.println(group);
                     pw.println("---------------------------------------------------------------------------");
+                    @SuppressWarnings("unchecked")
                     final Set<JobKey> keys = s.getJobKeys(GroupMatcher.groupEquals(group));
                     for(final JobKey key : keys) {
                         final JobDetail detail = s.getJobDetail(key);