此内容没有您所选择的语言版本。

Chapter 37. Remote Task Execution


37.1. 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.

37.2. 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 Running Remote Tasks.
  • Set<String> getParameters() - A collection of named parameters for use with the task.

37.3. Installing Remote Tasks

Once a remote task has been created, and bundled into a .jar, it may be deployed to the server by using either of the following methods:

Option 1: Using the Deployments Directory

  1. Copy the deployment into the deployments/ directory of the JBoss Data Grid server as seen in the following example:

    $] cp /path/to/sample_task.jar $JDG_HOME/standalone/deployments/
    Copy to Clipboard Toggle word wrap

Option 2: Using the CLI.. Connect to the JDG server by running the below command:

+

[$JDG_HOME] $ bin/cli.sh --connect --controller=$IP:$PORT
Copy to Clipboard Toggle word wrap
  1. Deploy the .jar file by executing the following command:

    deploy /path/to/sample_task.jar
    Copy to Clipboard Toggle word wrap
Note

When JBoss Data Grid is used in domain mode the server groups must be specified using either the --all-server-groups or --server-groups parameters.

37.4. Removing Remote Tasks

Remote tasks may be removed from the running instances by using the JBoss Data Grid CLI. Follow the below instructions to remove a remote task:

  1. Connect to the JDG server by running the below command:

    [$JDG_HOME] $ bin/cli.sh --connect --controller=$IP:$PORT
    Copy to Clipboard Toggle word wrap
  2. Remove the .jar file by using the undeploy command, as seen below:

    undeploy /path/to/sample_task.jar
    Copy to Clipboard Toggle word wrap
    Note

    When JBoss Data Grid is used in domain mode the server groups must be specified using either the --all-relevant-server-groups or --server-groups parameters.

37.5. Running Remote Tasks

If authorization is disabled on the server then anyone may execute remote tasks once they have been installed. Otherwise, only users with EXEC permissions will be allowed to run previously installed tasks. If a remote task has additional users specified, via the getAllowedRole method, then users must also belong to this role to execute the script.

To execute a previously deployed task call execute(String taskName, Map parameters) on the desired cache. The following example demonstrates executing a task with the name sampleTask:

import org.infinispan.client.hotrod.*;
import java.util.*;
[...]
String TASK_NAME = "sampleTask";

RemoteCacheManager rcm = new RemoteCacheManager();
RemoteCache remoteCache = rcm.getCache();

// Assume the task takes a single parameter, and will return a result
Map<String, String> params = new HashMap<>();
params.put("name", "value");

String result = (String) remoteCache.execute(TASK_NAME, params);
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat