我编写了以下类来创建 JGroup 集群:
public class TestClient extends ReceiverAdapter {
JChannel channel;
private void start() throws Exception {
channel=new JChannel().setReceiver(this);
channel.connect("ChatCluster");
eventLoop();
channel.close();
}
private void eventLoop() {
while(true) {
}
}
public void viewAccepted(View new_view) {
System.out.println("** view: " + new_view);
System.out.println("Get Coord"+new_view.getCoord());
System.out.println(new_view.getMembers());
}
public void receive(Message msg) {
System.out.println(msg.getSrc() + ": " + msg.getObject());
}
public void getState(OutputStream output) throws Exception {
}
public void setState(InputStream input) throws Exception {
}
}
ReceiverAdapter 是一个 Jgroups 定义的类:
public class ReceiverAdapter implements Receiver {
public ReceiverAdapter() {
}
public void receive(Message msg) {
}
public void receive(MessageBatch batch) {
Iterator var2 = batch.iterator();
while(var2.hasNext()) {
Message msg = (Message)var2.next();
try {
this.receive(msg);
} catch (Throwable var5) {
;
}
}
}
public void getState(OutputStream output) throws Exception {
}
public void setState(InputStream input) throws Exception {
}
public void viewAccepted(View view) {
}
public void suspect(Address mbr) {
}
public void block() {
}
public void unblock() {
}
}
我的问题是如何在视图更改或发送/接收消息时调用 ReceiverAdapter 类中的这些方法,因为我不需要显式调用这些方法。JGroups 是否实现了某种事件侦听器?
HUWWW
相关分类