Implementing a Java class for custom jobs
Custom jobs must be deployed to each OpenPages® application server and are dynamically loaded during startup.
- 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.
setName(). For example, this code creates a custom job that is called My
Custom Job:public class CustomJob extends AbstractScheduledProcess {
public CustomJob() {
super(ProcessConstants.TYPE_GENERAL);
setName("My Custom Job");
}
AbstractScheduledProcess called
execute must be implemented in your derived Java class. Within this method is where you write the functionality that the custom job
performs.void execute(){
//add your custom code here
}
To access the configuration values for the job, call:
this.jobDetail.getJobConfiguration();
For more information about the IBM OpenPages GRC Java API, which you can use in custom actions, see IBM OpenPages GRC Java API .
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.
Setting a timeout for the job
The default timeout for all scheduler jobs is defined in the setting. You can override this timeout setting for a custom job.
To set a timeout for a custom job, you need the custom job name, which is defined by
setName() in the constructor of the job. Create the following setting to define the
timeout:
.
For example: .