This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Extending Task

Scheduled Tasks

Task is a one of the methods of automatic driving the mediation in the ESB. It is an implementation of ESB Startup which allows adding tasks, it should run at ESB startup. Task is a Startup and it is based on Quartz, an open source job scheduling system. Task can be used to create schedules:

  • Simple schedules - May be a schedule to run a task periodically.
  • Complex schedules - May be a schedule to run at specific time in the future. It can be specified using cron expressions.
<task class="string" name="string" [group="string"] [pinnedServers="(serverName)+"]>
       <property name="string" value="String"/>
       <property name="string"><somexml>config</somexml></property>
       <trigger ([[count="int"]? interval="int"] | [cron="string"] | [once=(true | false)])/>
</task>

A task is created and scheduled to run at specified time intervals or as specified by the cron expression. The Task class specifies the actual task implementation class (which must implement org.apache.synapse.task.Taskinterface) to be executed at the specified interval/s, and name specifies of an identifier for the scheduled task.

Tip

The current ESB has only one implementation - org.apache.synapse.startup.tasks.MessageInjector. It can be used to inject messages at ESB startup.

Fields in the task class can be set using properties provided as string literals or as XML fragments.

For example, if the task implementation class has a field named "version" with a corresponding setter method, the configuration value which will be assigned to this field before running the task can be specified using a property with the name "version."

There are three different trigger mechanisms to schedule tasks:

  • A simple trigger - Is specified by "count" and "interval", implying that the task will run a "count" number of times at specified intervals.
  • A cron trigger - May be specified using a cron expression.
  • A one-time trigger - Is specified using the once attribute as true in the definition and could be specified as true in this case this task will be executed only once just after the initialization of ESB.

See Adding and Scheduling Tasks.

You can give a list of Synapse server names where this task should be started using pinnedServers attribute.

Extending Task

A custom Task can be developed by writing a custom Java class that implements the org.apache.synapse.task.Task interface. Task interface is shown bellow.

package org.apache.synapse.task;

/*** Represents an executable Task*/

public interface Task {

   /*** Execute method will be invoked by the QuartzJOb.
   */
   public void execute();
}