8.3. サーバー側のタスクとスクリプトの実行


Data Grid サーバーで、タスクとカスタムスクリプトを実行します。

8.3.1. タスクおよびスクリプトの実行

コマンドラインインターフェイスを使用して、Data Grid クラスターでタスクおよびスクリプトを実行します。

手順

  1. Data Grid への CLI 接続を作成します。
  2. 以下の例のように、task コマンドを使用して、タスクおよびスクリプトを実行します。

    • multipler.js という名前のスクリプトを実行して、2 つのパラメーターを指定します。

      [//containers/default]> task exec multipler.js -Pmultiplicand=10 -Pmultiplier=20
      200.0
      Copy to Clipboard Toggle word wrap
    • @@cache@names という名前のタスクを実行して、利用可能なすべてのキャッシュのリストを取得します。

      //containers/default]> task exec @@cache@names
      ["___protobuf_metadata","mycache","___script_cache"]
      Copy to Clipboard Toggle word wrap

8.3.2. プログラムでのスクリプトの実行

以下の例のように、execute() を呼び出して、Hot Rod RemoteCache インターフェイスを使用してスクリプトを実行します。

RemoteCache<String, Integer> cache = cacheManager.getCache();
// Create parameters for script execution.
Map<String, Object> params = new HashMap<>();
params.put("multiplicand", 10);
params.put("multiplier", 20);
// Run the script with the parameters.
Object result = cache.execute("multiplication.js", params);
Copy to Clipboard Toggle word wrap

8.3.3. プログラムでのタスクの実行

以下の例のように、execute() を呼び出して、Hot Rod RemoteCache インターフェイスを使用してタスクを実行します。

// Add configuration for a locally running server.
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer().host("127.0.0.1").port(11222);

// Connect to the server.
RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());

// Retrieve the remote cache.
RemoteCache<String, String> cache = cacheManager.getCache();

// Create task parameters.
Map<String, String> parameters = new HashMap<>();
parameters.put("name", "developer");

// Run the server task.
String greet = cache.execute("hello-task", parameters);
System.out.println(greet);
Copy to Clipboard Toggle word wrap
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat