You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2017/06/12 08:32:07 UTC

karaf git commit: Add user guide section about Karaf Scheduler

Repository: karaf
Updated Branches:
  refs/heads/karaf-4.1.x 296193b34 -> 7a842870c


Add user guide section about Karaf Scheduler


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/7a842870
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/7a842870
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/7a842870

Branch: refs/heads/karaf-4.1.x
Commit: 7a842870c03abae5924c1a3078e956d3fa691e70
Parents: 296193b
Author: Toni Menzel <to...@rebaze.com>
Authored: Thu Jun 8 22:39:01 2017 +0200
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Mon Jun 12 10:31:59 2017 +0200

----------------------------------------------------------------------
 manual/src/main/asciidoc/index.adoc             |   2 +
 .../src/main/asciidoc/user-guide/scheduler.adoc | 157 +++++++++++++++++++
 2 files changed, 159 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/7a842870/manual/src/main/asciidoc/index.adoc
----------------------------------------------------------------------
diff --git a/manual/src/main/asciidoc/index.adoc b/manual/src/main/asciidoc/index.adoc
index 9348243..2bafd87 100644
--- a/manual/src/main/asciidoc/index.adoc
+++ b/manual/src/main/asciidoc/index.adoc
@@ -86,6 +86,8 @@ include::user-guide/monitoring.adoc[]
 
 include::user-guide/webconsole.adoc[]
 
+include::user-guide/scheduler.adoc[]
+
 include::user-guide/tuning.adoc[]
 
 == Developer Guide

http://git-wip-us.apache.org/repos/asf/karaf/blob/7a842870/manual/src/main/asciidoc/user-guide/scheduler.adoc
----------------------------------------------------------------------
diff --git a/manual/src/main/asciidoc/user-guide/scheduler.adoc b/manual/src/main/asciidoc/user-guide/scheduler.adoc
new file mode 100644
index 0000000..835d1fe
--- /dev/null
+++ b/manual/src/main/asciidoc/user-guide/scheduler.adoc
@@ -0,0 +1,157 @@
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+=== Scheduler
+
+Apache Karaf provides an optional Scheduler which provides a Service Listener which listens for Runnable Services and schedules their execution, based  on the service properties.
+
+This Scheduler implementation uses the Quartz Scheduler library to understand cron-like expressions.
+
+==== Installation
+
+To enable the Apache Karaf Scheduler, you just have to install the `scheduler` feature:
+
+----
+karaf@root()> feature:install scheduler
+----
+
+The `scheduler` feature automatically installs the `scheduler` Gogo command group, too:
+
+----
+scheduler:list
+scheduler:schedule
+scheduler:unschedule
+----
+
+==== Configuration
+
+All jobs allow configuration using service properties:
+
+.Scheduler properties
+[width="100%",cols="3,2,10",options="header"]
+|=========================================================
+|Property |Default |Description
+
+|Scheduler.PROPERTY_SCHEDULER_PERIOD | - |
+Defines the period for a job. The period is expressed in seconds. This property needs to be of type Long.
+
+|Scheduler.PROPERTY_SCHEDULER_IMMEDIATE |false |
+Define if a periodically job should be scheduled immediate.
+Default is to not startup immediate, the job is started the first time after the period has expired.
+This property needs to be of type Boolean.
+
+|Scheduler.PROPERTY_SCHEDULER_EXPRESSION | - |
+Define the cron expression for a job. Must be a Quartz compatible expression.
+
+|Scheduler.PROPERTY_SCHEDULER_CONCURRENT | - |
+Define if the job can be run concurrently.
+
+|Scheduler.PROPERTY_SCHEDULER_NAME |-  |
+Define the job name.
+
+|=========================================================
+
+
+==== Schedule a new Job using the Whitebox-Service paradigm (recommended)
+This example uses Declarative Services to register a Service of Type "org.apache.karaf.scheduler.Job" so that it is recognized by the Scheduler Service.
+
+Alternatively, jobs can be registered as type "Runnable" in a more API neutral way. In this case you won't get the "JobContext" information though.
+----
+@Component (immediate = true, property = {
+        Scheduler.PROPERTY_SCHEDULER_EXPRESSION + "=0 0/10 * * * ?",
+} )
+public class SchedulerPing implements Job {
+
+    @Override
+    public void execute(JobContext context) {
+        // ..
+    }
+}
+----
+
+This will register a Job with the WhiteboxHandler. You can verify that the job is registered:
+
+----
+karaf@root()> scheduler:list
+Name                   │ Schedule
+───────────────────────┼─────────────────────
+Registered Service.185 │ cron(0 0/10 * * * ?)
+----
+
+
+
+==== Schedule a new Job using the Gogo Shell
+----
+karaf@root()> scheduler:schedule --help
+DESCRIPTION
+        scheduler:schedule
+
+	Schedule a script execution
+
+SYNTAX
+        scheduler:schedule [options] script
+
+ARGUMENTS
+        script
+                The script to schedule
+
+OPTIONS
+        --at
+                Absolute date in ISO format (ex: 2014-05-13T13:56:45)
+        --concurrent
+                Should jobs run concurrently or not (defaults to false)
+        --period
+                Time during executions (in seconds)
+        --times
+                Number of times this job should be executed
+                (defaults to -1)
+        --cron
+                The cron expression
+        --help
+                Display this help message
+        --name
+                Name of this job
+
+----
+
+For example:
+----
+tbd
+----
+
+==== Schedule a new Job using the Scheduler Service
+
+Recommendation: Before using this low level api for registering jobs, consider using the whitebox approach instead.
+
+----
+..
+import org.apache.karaf.scheduler.Scheduler;
+
+@Component
+public class Demo {
+
+  @Reference Scheduler scheduler;
+
+  public void useScheduler()
+  {
+    schedule(new MyJob(), scheduler.EXPR("0 0/10 * * * ?"));
+  }
+
+  class MyJob implements Job {
+    ..
+  }
+
+}
+
+----