Interface IScheduledTask

All Superinterfaces:
AutoCloseable, Closeable, Runnable

public interface IScheduledTask extends Runnable, Closeable
A task to be executed by the i2 Analyze server, on a schedule.

To configure a task and its schedule, you add properties to a properties file in the following format:

 CustomTaskScheduler.TaskName.Class=com.example.ScheduledTask
 CustomTaskScheduler.TaskName.Expression=* * * * *
 

Here, TaskName is a name that uniquely identifies an instance of a task, com.example.ScheduledTask is the fully qualified name of the task class, and * * * * * is a cron expression that defines the schedule to run the task on.

Note: You can create multiple tasks from the same implementation class, provided that they all have different names.

Since:
12.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    A set of methods that provide access to other server APIs that you can use from inside a IScheduledTask.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Performs teardown or finalization on resources that the task required.
    default void
    Performs configuration or initialization that enables the task to run.
    void
    run()
    Executes the task.
  • Method Details

    • run

      void run() throws CustomTaskFailedException
      Executes the task.

      The server calls this method to perform the custom action, based on the schedule defined by the cron expression in the properties file.

      If this method encounters a problem, it must throw a CustomTaskFailedException that tells the server what to do next. Depending on how the exception is constructed, the server might re-run the task immediately, or when it is next scheduled, or never.

      If this method throws an exception other than CustomTaskFailedException, the custom task is canceled and will not run again until the scheduler is reinitialized through a server restart.

      Specified by:
      run in interface Runnable
      Throws:
      CustomTaskFailedException - If task execution fails.
    • onStartup

      default void onStartup(IScheduledTask.IScheduledTaskObjects scheduledTaskObjects)
      Performs configuration or initialization that enables the task to run.

      The server calls this method during startup, to give the task the opportunity to make itself ready to run. The task can also get access to other server APIs through the scheduledTaskObjects parameter. Implementing this method is optional; by default it does nothing.

      Parameters:
      scheduledTaskObjects - A set of methods that the task can call to retrieve API objects.
    • close

      default void close()
      Performs teardown or finalization on resources that the task required.

      The server calls this method during shutdown, to give the task the opportunity to release any resources that it used. Implementing this method is optional; by default it does nothing.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable