我正在尝试为hazelcast 3.1使用分布式执行程序服务,并发现我无法使用submitToMember(任务,成员)。在我的例子中,10.69.108.60是我的本地机器,170.194.100.111是我的远程机器。当成员是我的本地计算机时,我能够在将来获得返回值,但如果成员是远程计算机,则会给我 TargetNotAMemberException 。 以下是代码
public class DistExecutionTest {
public static void main(String args[]){
DistributedExecutor dex = new DistributedExecutor();
try {
Member member = new MemberImpl(new Address("170.194.100.111",5701), false );
String msg;
msg = dex.echoOnTheMember("Hey youuuu!", member);
System.out.println(msg);
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
}
}
和
public class DistributedExecutor {
Config config;
NetworkConfig network;
JoinConfig join;
DistributedExecutor(){
config = new Config();
network = config.getNetworkConfig();
// network.setPort(5701);
join = network.getJoin();
join.getMulticastConfig().setEnabled(false);
join.getTcpIpConfig().addMember("170.194.100.111").addMember("10.69.108.60").setEnabled(true);
network.getInterfaces().setEnabled(true).addInterface("170.194.100.*").addInterface("10.69.108.*");
}
public String echoOnTheMember(String input, Member member) throws Exception {
Callable<String> task = new DistObject(input);
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
IExecutorService executorService = hz.getExecutorService("default");
Future<String> future = executorService.submitToMember(task, member);
String distObjectResult = future.get();
return distObjectResult;
}
}
和
public class Echo implements Callable<String>, Serializable, HazelcastInstanceAware {
private static final long serialVersionUID = -3164053990811643392L;
String message = null;
transient HazelcastInstance localInstance;
public Echo(String msg){
message = msg;
}
@Override
public String call() throws Exception {
return localInstance.toString() + message;
}
@Override
public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
this.localInstance = hazelcastInstance;
}
}
以下是本地计算机上的日志记录
Dec 17, 2013 1:03:20 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Interfaces is enabled, trying to pick one address matching to one of: [162.124.194.*, 10.38.148.*]
Dec 17, 2013 1:03:20 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Prefer IPv4 stack is true.
Dec 17, 2013 1:03:20 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Picked Address[10.69.108.60]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
Dec 17, 2013 1:03:21 PM com.hazelcast.system
INFO: [10.69.108.60]:5701 [dev] Hazelcast Community Edition 3.1 (20131011) starting at Address[10.69.108.60]:5701
Dec 17, 2013 1:03:21 PM com.hazelcast.system
INFO: [10.69.108.60]:5701 [dev] Copyright (C) 2008-2013 Hazelcast.com
Dec 17, 2013 1:03:21 PM com.hazelcast.instance.Node
INFO: [10.69.108.60]:5701 [dev] Creating TcpIpJoiner
Dec 17, 2013 1:03:21 PM com.hazelcast.core.LifecycleService
INFO: [10.69.108.60]:5701 [dev] Address[10.69.108.60]:5701 is STARTING
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[10.69.108.60]:5703
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[10.69.108.60]:5702
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Connecting to /10.69.108.60:5703, timeout: 0, bind-any: true
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Connecting to /10.69.108.60:5702, timeout: 0, bind-any: true
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[170.194.100.111]:5703
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[170.194.100.111]:5702
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Connecting to /170.194.100.111:5703, timeout: 0, bind-any: true
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Connecting to /170.194.100.111:5702, timeout: 0, bind-any: true
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[170.194.100.111]:5701
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Connecting to /170.194.100.111:5701, timeout: 0, bind-any: true
Dec 17, 2013 1:03:22 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Could not connect to: /10.69.108.60:5703. Reason: SocketException[Connection refused: connect to address /10.69.108.60:5703]
Dec 17, 2013 1:03:22 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Could not connect to: /10.69.108.60:5702. Reason: SocketException[Connection refused: connect to address /10.69.108.60:5702]
Dec 17, 2013 1:03:22 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Could not connect to: /170.194.100.111:5703. Reason: SocketException[Connection refused: connect to address /170.194.100.111:5703]
Dec 17, 2013 1:03:22 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Could not connect to: /170.194.100.111:5702. Reason: SocketException[Connection refused: connect to address /170.194.100.111:5702]
Dec 17, 2013 1:03:22 PM com.hazelcast.nio.SocketConnector
INFO: [10.69.108.60]:5701 [dev] Could not connect to: /170.194.100.111:5701. Reason: SocketException[Connection refused: connect to address /170.194.100.111:5701]
Dec 17, 2013 1:03:23 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev]
Members [1] {
Member [10.69.108.60]:5701 this
}
Dec 17, 2013 1:03:23 PM com.hazelcast.core.LifecycleService
INFO: [10.69.108.60]:5701 [dev] Address[10.69.108.60]:5701 is STARTED
HazelcastInstance{name='_hzInstance_1_dev', node=Address[10.69.108.60]:5701}Hey youuuu!
远程计算机上的日志记录位于这些行上。可以粘贴所有日志记录。管理以获取重要部分。
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[10.38.148.60]:5703
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[10.38.148.60]:5702
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[10.38.148.60]:5701
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[170.194.100.111]:5703
Dec 17, 2013 1:03:21 PM com.hazelcast.cluster.TcpIpJoiner
INFO: [10.69.108.60]:5701 [dev] Connecting to possible member: Address[170.194.100.111]:5702
Dec 17, 2013 1:03:21 PM com.hazelcast.nio.SocketConnector
Members [2] {
Member [10.69.108.60]:5701 this
Member [170.194.100.111]:5701
}
答案 0 :(得分:0)
您是否可以使用hz.getCluster()。getMembers()方法获取成员实例,并选择要发送到的成员实例,而不是直接创建成员实例?我想看看它是否是由你创建该成员的方式引起的。
答案 1 :(得分:0)
我无法在评论中设置文字格式,所以我会另外给出答案。
因此,您遇到的问题是您的成员不会形成群集的原因。
您应该看到如下记录:
Members [2] {
Member [192.168.1.104]:5701 this
Member [192.168.1.104]:5702
}
这就是为什么我需要更多日志记录只是你的堆栈跟踪,但目前不提供任何更多的值。我需要看看Hazelcast关于加入其他集群的内容。
我需要看到这样的事情:
Dec 17, 2013 7:24:13 PM com.hazelcast.config.XmlConfigBuilder
INFO: Looking for hazelcast.xml config file in classpath.
Dec 17, 2013 7:24:13 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find hazelcast.xml in classpath.
Hazelcast will use hazelcast-default.xml config file in jar.
Dec 17, 2013 7:24:13 PM com.hazelcast.config.XmlConfigBuilder
INFO: Using configuration file /java/projects/Hazelcast/hazelcast/hazelcast/target/classes/hazelcast-default.xml in the classpath.
Dec 17, 2013 7:24:13 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Prefer IPv4 stack is true.
Dec 17, 2013 7:24:13 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Picked Address[192.168.1.102]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
Dec 17, 2013 7:24:13 PM com.hazelcast.system
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Hazelcast Community Edition 3.2-SNAPSHOT (20131217) starting at Address[192.168.1.102]:5701
Dec 17, 2013 7:24:13 PM com.hazelcast.system
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Copyright (C) 2008-2013 Hazelcast.com
Dec 17, 2013 7:24:13 PM com.hazelcast.instance.Node
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Creating MulticastJoiner
Dec 17, 2013 7:24:13 PM com.hazelcast.core.LifecycleService
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Address[192.168.1.102]:5701 is STARTING
Dec 17, 2013 7:24:15 PM com.hazelcast.cluster.MulticastJoiner
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT]
Members [1] {
Member [192.168.1.102]:5701 this
}
Dec 17, 2013 7:24:16 PM com.hazelcast.core.LifecycleService
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Address[192.168.1.102]:5701 is STARTED
Dec 17, 2013 7:24:16 PM com.hazelcast.partition.PartitionService
INFO: [192.168.1.102]:5701 [dev] [3.2-SNAPSHOT] Initializing cluster partition table first arrangement...
答案 2 :(得分:0)
我也遇到了同样的错误。
这是由echoonthemember
函数
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
它创建默认或cfg config的新hazelcast实例。在这个实际上不存在的淡褐色的实例中搜索该成员。因此,错误消息显示为
TargetNotAMemberException
。
要使其正常工作,只需在echoonthemember
函数中传递创建的实例即可。
例如,将它作为类DistributedExecutor
中的成员变量并通过构造函数进行设置。
然后,如果您的实际实例是'abcdef'
,那么
用作
IExecutorService executorService = abcdef.getExecutorService("default");
不要创建新的Hazelcast
实例。