Reputation: 21
I have to create a cluster with a single receiver and several senders on a WAN.
The problem is that after calling JChannel.connect()
with the same clustername in each member there's no common cluster with common view created but each component sees its own.
The result is that when sending messages to receiver the latter's physical address cannot be determined and all messages are dopped.
The sender :
package mydemo;
import org.jgroups.Address;
import org.jgroups.JChannel;
import org.jgroups.ReceiverAdapter;
public class Sender {
JChannel channel;
Address receiver;
String group;
String props;
String name;
public Sender(Address rcv, String group, String props, String name) {
receiver = rcv;
this.group = group;
this.props = props;
this.name = name;
try {
channel = new JChannel(props);
//channel.setName(group);
channel.connect(group);
System.out.println("View size(sender): " + channel.getView().getMembers().size());
System.out.println("Sender address: " + channel.getView().getMembers().get(0));
} catch (Exception e) {
e.printStackTrace();
}
}
public void sendMessage() throws Exception {
channel.send(receiver,"Hello, I am "+name);
}
public void setReceiverAdapter(ReceiverAdapter adapter) {
channel.setReceiver(adapter);
}
}
The receiver:
package mydemo;
import java.util.LinkedList;
import java.util.List;
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;
import org.jgroups.View;
public class ClusterTest extends ReceiverAdapter {
JChannel channel;
List<Sender> senders;
public ClusterTest(int num, String props, String name)
throws Exception {
senders = new LinkedList<Sender>();
channel = new JChannel(props);
channel.setReceiver(this);
//channel.setName(name);
channel.connect(name);
System.out.println("Rcv address: " + channel.getView().getMembers().get(0));
for (int i = 0; i < num; i++) {
/* senders.add(new Sender(channel.getView().getMembers().get(0), name,
props, "Sender" + i));*/
senders.add(new Sender(channel.getAddress(), name,
props, "Sender" + i));
senders.get(i).setReceiverAdapter(this);
System.out.println("View size(rcv): " + channel.getView().getMembers().size());
}
}
public void receive(Message msg) {
System.out.println("received message " + msg);
}
public void viewAccepted(View view) {
System.out.println("received view " + view.toString());
}
public void start() throws Exception {
for (Sender sender : senders) {
Thread.sleep(3000);
sender.sendMessage();
}
channel.close();
}
public static void main(String[] args) throws Exception {
new ClusterTest(3, "d:/sth/MyDemo/src/conf/tcp.xml", "TestGroup").start();
}
}
The tcp.xml provided by jgroups was used with small changes in TCPPING:
<TCPPING timeout="3000"
initial_hosts="${jgroups.tcpping.initial_hosts:localhost[7800],localhost[7801],localhost[7802],
localhost[7803],localhost[7804],localhost[7805],localhost[7806],localhost[7807],localhost[7808],
localhost[7809],localhost[7810],localhost[7811],localhost[7812],localhost[7813],localhost[7814],
localhost[7815],localhost[7816]}"
port_range="10"
num_initial_members="11"/>
Output:
GMS: address=myhost-42336, cluster=TestGroup, physical address=192.168.3.1:7806
received view [myhost-42336|0] [myhost-42336]
Rcv address: myhost-42336
GMS: address=myhost-48774, cluster=TestGroup, physical address=192.168.3.1:7807
View size(sender): 1
Sender address: myhost-48774
View size(rcv): 1
GMS: address=myhost-38597, cluster=TestGroup, physical address=192.168.3.1:7808
View size(sender): 1
Sender address: myhost-38597
View size(rcv): 1
GMS: address=myhost-55548, cluster=TestGroup, physical address=192.168.3.1:7809
View size(sender): 1
Sender address: myhost-55548
View size(rcv): 1
WARNING: myhost-48774: no physical address for myhost-42336, dropping message
WARNING: myhost-48774: no physical address for myhost-42336, dropping message
WARNING: myhost-38597: no physical address for myhost-42336, dropping message
WARNING: myhost-38597: no physical address for myhost-42336, dropping message
WARNING: myhost-48774: no physical address for myhost-42336, dropping message
...
Could you please help me? Maybe the concept is wrong but as the target is working on WAN I have to use unicast and TCP.
Upvotes: 1
Views: 6873
Reputation: 271
Make sure 'localhost' does NOT resolve to 127.0.0.1, but to one of the addresses you listed. I suggest start an instance with -Djgroups.bind_addr=1.2.3.4, where 1.2.3.4 is listed in 'initial_hosts'.
Upvotes: 3