This sample explains how to create a task that can be scheduled to run on WSO2 Governance Registry in few easy steps. Once successfully deployed this sample will print Hello World once every 10 seconds on the Command Prompt of the WSO2 Governance Registry. We will be reusing the code of the Handler Sample in this example. This sample requires Apache Maven. See System Requirements for links on how to install it.
1. Navigate to
samples/handler/src to find the source code of the Handler Sample.
2. Add the following dependency to your POM file:
Project Object Model (POM) is an XML representation of a Maven project held in a file named pom.xml. You should find POM file by the name pom.xml inside
3. Add a new Java Class named
GREG_HOME/samples/handler/src/src/main/java/org/wso2/carbon/registry/samples/task/SampleTask.java with the following source:
4. Compile the source code by running the following command inside
mvn clean install will trigger an Apache Maven Build in your command line. This requires you having installed Apache Maven. See System Requirements for links on how to install it.
A successful run of Apache Maven will generate a report similar to the following:
5. Copy the <
org.wso2.carbon.registry.samples.handler-5.4.0.jar file into the <
6. Edit the
registry.xml file which is in
GREG_HOME/repository/conf folder and add the following XML snippet.
See also Configuration for Scheduled Tasks.
7. Start the server and observe the command prompt. See Running the Product for more information.
You should find a line similar to the following printed on your command prompt, which indicates that you task has successfully deployed.
After the server has successfully started, you should see "Hello World" being printed once every 10 seconds.
Tasks can be used from very basic server-side operations to much advanced operations such as deployment scheduling. Within the Governance Registry product tasks are used to:
- Schedule the generation of reports. See Reports.
- Pre-fetching Governance Artifacts to a Global Cache to improve the speed of look-ups.