Ján*_*res 4 java key owner execution hazelcast
我无法理解 Hazelcast 分布式执行的概念。据说能够对特定密钥的所有者实例执行执行。
来自文档:
<T> Future<T> submitToKeyOwner(Callable<T> task, Object key)
Submits task to owner of the specified key and returns a Future representing that task.
Parameters:
task - task
key - key
Returns:
a Future representing pending completion of the task
Run Code Online (Sandbox Code Playgroud)
我相信我并不是唯一拥有一个由多个映射构建的集群的人,这些映射实际上可能使用相同的密钥用于不同的目的,持有不同的对象(例如,以下设置中的某些内容):
IMap<String, ObjectTypeA> firstMap = HazelcastInstance.getMap("firstMap");
IMap<String, ObjectTypeA_AppendixClass> secondMap = HazelcastInstance.getMap("secondMap");
Run Code Online (Sandbox Code Playgroud)
对我来说,文档中关于密钥所有者的描述似乎很令人困惑。我真正的沮丧是我不知道它指的是哪个 - 在哪个地图 - 键?
该文档还给出了这种方法的“演示”:
import com.hazelcast.core.Member;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.IExecutorService;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.Set;
import com.hazelcast.config.Config;
public void echoOnTheMemberOwningTheKey(String input, Object key) throws Exception {
Callable<String> task = new Echo(input);
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
IExecutorService executorService = hz.getExecutorService("default");
Future<String> future = executorService.submitToKeyOwner(task, key);
String echoResult = future.get();
}
Run Code Online (Sandbox Code Playgroud)
以下是文档站点的链接:Hazelcast MultiHTML Documentation 3.0 - 分布式执行
你们中有人在过去弄清楚它需要什么密钥吗?
也许我可以用代码示例更好地解释它:
Callable<String> task = new Echo(input);
String key = "foo";
IMap map1 = hz.getMap("m1");
IMap map2 = hz.getMap("m2");
map1.put(key,1);
map2.put(key,2);
IExecutorService executorService = hz.getExecutorService("default");
Future<String> future = executorService.submitToKeyOwner(task, key);
String echoResult = future.get();
Run Code Online (Sandbox Code Playgroud)
如您所见,有 2 个地图,map1 和 map2。
这两个映射都有一个具有相同键“foo”但值不同的映射条目。
但这两个映射条目最终将位于同一分区(因此在同一成员上),因为密钥用于确定分区。
在最后几行中,任务被发送给密钥所有者,在本例中,我们将把任务发送给拥有密钥“foo”的成员。因此,任务将被发送到存储两个映射条目的同一台机器。
我没有查看您关于支持的讨论;这是您在堆栈溢出上发布的原始问题的答案。