이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 41. Remote Task Execution
41.1. Remote Task Execution 링크 복사링크가 클립보드에 복사되었습니다!
Tasks, or business logic, can run directly on JBoss Data Grid servers, which means task execution is close to the data and uses the resources of all nodes in the cluster.
You can bundle tasks in Java executable files and deploy them to server instances where you can run the executables programmatically.
41.2. Creating Remote Tasks 링크 복사링크가 클립보드에 복사되었습니다!
To create a task for remote execution, you must create a .jar
file that contains a class that implements the org.infinispan.tasks.ServerTask
interface.
The following methods are required in the implementation:
-
void setTaskContext(TaskContext taskContext)
Sets the task context. Use this method to access caches and other necessary resources. -
String getName()
Provides a unique name for the task. This name is used for execution byTaskManager
.
The following methods are optional in the implementation:
-
TaskExecutionMethod getExecutionMode()
Determines if the task is executed on one node, as inTaskExecutionMode.ONE_NODE
, or on all nodes, as inTaskExecutionMode.ALL_NODES
. Execution on one node is the default. -
Optional<String> getAllowedRole()
Sets a role that users must have to run a task. No additional user role is set by default. For more information, see Running Remote Tasks. -
Set<String> getParameters()
Specifies named parameters for use with the task.
41.3. Remote Task Example 링크 복사링크가 클립보드에 복사되었습니다!
The following provides an example class that implements the org.infinispan.tasks.ServerTask
interface:
41.4. Installing Remote Tasks 링크 복사링크가 클립보드에 복사되었습니다!
After you create a remote task and bundle it into a .jar
file, you can deploy it to a JBoss Data Grid server instance with one of the following options:
Option 1: Copy to the Deployments Directory
Copy the
.jar
file to the deployments/ directory.$] cp /path/to/sample_task.jar $JDG_HOME/standalone/deployments/
$] cp /path/to/sample_task.jar $JDG_HOME/standalone/deployments/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Option 2: Deploy with the CLI
Connect to the JBoss Data Grid server.
[$JDG_HOME] $ bin/cli.sh --connect --controller=$IP:$PORT
[$JDG_HOME] $ bin/cli.sh --connect --controller=$IP:$PORT
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the
.jar
file.deploy /path/to/sample_task.jar
deploy /path/to/sample_task.jar
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf JBoss Data Grid is in domain mode, you must specify the server groups with either the
--all-server-groups
or--server-groups
parameter.
41.5. Removing Remote Tasks 링크 복사링크가 클립보드에 복사되었습니다!
You can remove remote tasks from the running instances of JBoss Data Grid as follows:
Connect to the JBoss Data Grid server.
[$JDG_HOME] $ bin/cli.sh --connect --controller=$IP:$PORT
[$JDG_HOME] $ bin/cli.sh --connect --controller=$IP:$PORT
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the
undeploy
command to remove the.jar
file.undeploy /path/to/sample_task.jar
undeploy /path/to/sample_task.jar
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf JBoss Data Grid is in domain mode, you must specify the server groups with either the
--all-server-groups
or--server-groups
parameter.
41.6. Running Remote Tasks 링크 복사링크가 클립보드에 복사되었습니다!
If authorization is enabled on the JBoss Data Grid server, only users with EXEC
permissions can run remote tasks. If authorization is not enabled, any user can run remote tasks.
Remote tasks can have additional user roles specified with the getAllowedRole
method. In this case, users must belong to the role to run remote tasks.
To execute a previously deployed task call execute(String taskName, Map parameters)
on the desired cache.
The following example shows how to run a task named sampleTask
: