Implementing a Java class for custom jobs

A custom job is a user-defined job that performs a function. It is implement as a Java™ class that can be executed manually or on a schedule.

Custom jobs must be deployed to each OpenPages® application server and are dynamically loaded during startup.

To implement a custom job, complete the following tasks:
  • Create a custom job Java class by extending the following abstract implementation:
    com.ibm.openpages.api.scheduler.AbstractScheduledProcess
  • Add the class to a JAR file. Use the JAR file for all of your custom code. Deploy the JAR file to each OpenPages application server in the <OP_HOME>/aurora/op-ext-lib directory.
  • Restart the OpenPages application servers so that the custom job can be picked up by the dynamic class loader.
  • Use the Scheduler to add a custom job that uses the Java class. Set any property values or fields that the custom job requires as inputs. For more information, see Defining a custom job.

Providing configuration information to a custom job

For a custom job to be useful, it might require configuration information. For example, if it needs to connect to another service, it may need to know the API key. These values are defined as configuration items in the custom job in the Scheduler and passed into the custom job at run time.

Configuration items are string name-value pairs that you define.

The custom job needs to validate that the properties that it expects to be passed in have been passed in and that they have valid values.

Authoring the custom job Java class

The only requirement of a custom job Java class is that it extends com.ibm.openpages.api.scheduler.AbstractScheduledProcess. This requirement is validated when the custom job is defined in the Scheduler.

A single abstract API from AbstractScheduledProcess called execute must be implemented in your derived Java class, as follows:
void execute(){
//add your custom code here
}

Within this method is where you write the functionality that the custom job performs.

To access the configuration values, call:

this.jobDetail.getJobConfiguration();

For more information about the OpenPages GRC API, which you can use in custom jobs, see the IBM OpenPages with Watson API Javadoc. For links to the Javadoc, see OpenPages API documentation.

Exception or validation messages can be thrown from a custom job and displayed to the user. To display messages, use:

throwException(String message, Throwable cause)

Use this method to throw exceptions and display a custom message to users. Uncaught exceptions or exceptions that are explicitly thrown are logged by the application, but only a general error message is displayed to users.