Chapter 32. Remote Task Execution

Tasks, or business logic, may be executed directly on JBoss Data Grid servers, allowing this logic to be executed close to the data and using the resources of all nodes in the cluster. These tasks may be bundled in java executables which are deployed to the server instances, and once deployed the tasks may be executed programmatically.

32.1. Creating a Remote Task

To create a task for remote execution a .jar file must be created containing a class that implements org.infinispan.tasks.ServerTask. This interface contains the following methods that must be implemented:
  • void setTaskContext(TaskContext taskContext) - sets the task context; should be used to access caches and other resources necessary.
  • String getName() - provides a unique name for the task. This is the name that will be used for execution by the TaskManager.
In addition to the above the following may be implemented; however, these are not required for execution:
  • TaskExecutionMethod getExecutionMode() - Determines if the task is executed on one node, TaskExecutionMode.ONE_NODE, or on all nodes, TaskExecutionMode.ALL_NODES. Execution on one node is enabled by default.
  • Optional<String> getAllowedRole() - Sets the role that may execute this task. By default no role is provided, indicating that no additional role is required for execution. Additional information on executing tasks is found in Section 32.4, “Running Remote Tasks”.
  • Set<String> getParameters() - A collection of named parameters for use with the task.