Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0571910DDA for ; Fri, 17 Jan 2014 11:06:29 +0000 (UTC) Received: (qmail 20089 invoked by uid 500); 17 Jan 2014 11:06:27 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 19700 invoked by uid 500); 17 Jan 2014 11:06:27 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 19660 invoked by uid 99); 17 Jan 2014 11:06:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Jan 2014 11:06:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Jan 2014 11:06:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9876C23889FA for ; Fri, 17 Jan 2014 11:06:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r894500 - in /websites/staging/sling/trunk/content: ./ documentation/bundles/scheduler-service-commons-scheduler.html site/.htaccess Date: Fri, 17 Jan 2014 11:06:01 -0000 To: commits@sling.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140117110601.9876C23889FA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: buildbot Date: Fri Jan 17 11:06:01 2014 New Revision: 894500 Log: Staging update by buildbot for sling Modified: websites/staging/sling/trunk/content/ (props changed) websites/staging/sling/trunk/content/documentation/bundles/scheduler-service-commons-scheduler.html websites/staging/sling/trunk/content/site/.htaccess Propchange: websites/staging/sling/trunk/content/ ------------------------------------------------------------------------------ --- cms:source-revision (original) +++ cms:source-revision Fri Jan 17 11:06:01 2014 @@ -1 +1 @@ -1558023 +1559070 Modified: websites/staging/sling/trunk/content/documentation/bundles/scheduler-service-commons-scheduler.html ============================================================================== --- websites/staging/sling/trunk/content/documentation/bundles/scheduler-service-commons-scheduler.html (original) +++ websites/staging/sling/trunk/content/documentation/bundles/scheduler-service-commons-scheduler.html Fri Jan 17 11:06:01 2014 @@ -83,15 +83,70 @@ -
- This page is a translated version of /site/scheduler-service-commons-scheduler.html. In case of - doubt you might want to refer to the old page. -
-

Scheduler Service (commons scheduler)

-

The scheduler is a service for scheduling other services/jobs (it uses the open source Quartz library). The scheduler can be used in two ways, by registering the job through the scheduler API and by leveraging the whiteboard pattern that is supported by the scheduler.

-

The Scheduler API

+

The scheduler is a service for scheduling other services/jobs (it uses the open source Quartz library). The scheduler can be used in two ways, by registering the job through the scheduler API and by leveraging the whiteboard pattern that is supported by the scheduler. In most cases the whiteboard pattern is preferred

+

Examples of jobs that are scheduled by leveraging the whiteboard pattern

+

The following examples show you how to define and schedule a job by leveraging the whiteboard pattern.

+

Scheduling with a cron expression

+

The following job is executed every minute by setting scheduler.expression to the cron expression "0 * * ?":

+
package sling.docu.examples;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.Property;
+
+@Component
+@Service(value = Runnable.class)
+@Property( name = "scheduler.expression", value = "0 * * * * ?")
+public class ScheduledCronJob implements Runnable {
+
+    /** Default log. */
+    protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+    public void run() {
+        log.info("Executing a cron job (job#1) through the whiteboard pattern");
+    }
+//
+}
+
+ + +

Scheduling at periodic times

+

The following job is executed every ten seconds by setting scheduler.period to 10:

+
package sling.docu.examples;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.Property;
+
+@Component
+@Service(value = Runnable.class)
+@Property( name = "scheduler.period", longValue = 10)
+public class ScheduledPeriodicJob implements Runnable {
+
+    /** Default log. */
+    protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+    public void run() {
+        log.info("Executing a perodic job (job#2) through the whiteboard pattern");
+    }
+//
+}
+
+ + +

Preventing concurrent execution

+

By default, jobs can be concurrently executed. To prevent this, set the scheduler.concurrent property to false:

+
@Property(name="scheduler.concurrent", boolValue=false)
+## The Scheduler API
+
+ +

The scheduler has methods to execute jobs periodically, based on a cron expression or at a given time. For more details please refer to the javadocs.

Examples of scheduled jobs registered through the scheduler API

The following examples show you how to define and schedule a job that is registered through the scheduler api.

@@ -105,7 +160,7 @@ -

Scheduling with a cron expression

+

Scheduling with a cron expression

To execute the job as defined above at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday, you can use the addJob() method with the following parameters:

String schedulingExpression = "0 15 10 ? * MON-FRI";
 this.scheduler.addJob("myJob", job, null, schedulingExpression, true);
@@ -114,7 +169,7 @@
 
 

Refer to http://www.docjar.com/docs/api/org/quartz/CronTrigger.html to define more scheduling expressions.

-

Scheduling at periodic times

+

Scheduling at periodic times

To execute the job as defined above every 3 minutes (180 seconds), you can use the addPeriodicJob() method with the following parameters:

long period = 3*60; //the period is expressed in seconds
 this.scheduler.addPeriodicJob("myJob", job, null, period, true);
@@ -143,20 +198,21 @@
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
 
 /**
  *  This service executes scheduled jobs
  *  
- *  @scr.component immediate="true" metatype="false"
- *
  */
+@Component
 public class HelloWorldScheduledService {
 
     /** Default log. */
     protected final Logger log = LoggerFactory.getLogger(this.getClass());
 
-    /** The scheduler for rescheduling jobs.
-     * @scr.reference */
+    /** The scheduler for rescheduling jobs. */
+    @Reference
     private Scheduler scheduler;
 
 
@@ -216,66 +272,8 @@
 
 }
 
- - -

Examples of jobs that are scheduled by leveraging the whiteboard pattern

-

The following examples show you how to define and schedule a job by leveraging the whiteboard pattern.

-

Scheduling with a cron expression

-

The following job is executed every minute by setting scheduler.expression to the cron expression "0 * * ?":

-
package sling.docu.examples;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @scr.component
- * @scr.service interface="java.lang.Runnable"
- * @scr.property name="scheduler.expression" value="0 * * * * ?"
- */
-public class ScheduledCronJob implements Runnable {
-
-    /** Default log. */
-    protected final Logger log = LoggerFactory.getLogger(this.getClass());
-
-    public void run() {
-        log.info("Executing a cron job (job#1) through the whiteboard pattern");
-    }
-//
-}
-
- - -

Scheduling at periodic times

-

The following job is executed every ten seconds by setting scheduler.period to 10:

-
package sling.docu.examples;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @scr.component
- * @scr.service interface="java.lang.Runnable"
- * @scr.property name="scheduler.period" value="10" type="Long"
- */
-public class ScheduledPeriodicJob implements Runnable {
-
-    /** Default log. */
-    protected final Logger log = LoggerFactory.getLogger(this.getClass());
-
-    public void run() {
-        log.info("Executing a perodic job (job#2) through the whiteboard pattern");
-    }
-//
-}
-
- - -

Preventing concurrent execution

-

By default, jobs can be concurrently executed. To prevent this, set the scheduler.concurrent property to false:

-
@scr.property name="scheduler.concurrent" value="false" type="Boolean"
-
- Rev. 1499238 by fmeschbe on Wed, 3 Jul 2013 07:39:54 +0000 + Rev. 1559070 by cziegeler on Fri, 17 Jan 2014 11:05:50 +0000
Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project Modified: websites/staging/sling/trunk/content/site/.htaccess ============================================================================== --- websites/staging/sling/trunk/content/site/.htaccess (original) +++ websites/staging/sling/trunk/content/site/.htaccess Fri Jan 17 11:06:01 2014 @@ -73,3 +73,4 @@ Redirect Permanent /site/links.html /lin Redirect Permanent /site/contributing.html /contributing.html Redirect Permanent /site/project-information.html /project-information.html Redirect Permanent /site/release-management.html /documentation/development/release-management.html +Redirect Permanent /site/scheduler-service-commons-scheduler.htm /documentation/bundles/scheduler-service-commons-scheduler.html