为了账号安全,请及时绑定邮箱和手机立即绑定

如果我没有明确调用它们,那么如何在 jgroups 中调用 ReceiverAdapter

如果我没有明确调用它们,那么如何在 jgroups 中调用 ReceiverAdapter

慕婉清6462132 2021-07-16 17:15:46
我编写了以下类来创建 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 是否实现了某种事件侦听器?
查看完整描述

1 回答

?
HUWWW

TA贡献1874条经验 获得超12个赞

如果我正确理解了您的问题,我认为您已经解决了您的问题。您需要将您的 Receiver 实现显式传递给您想要使用它的 JChannel:

Receiver receiver = new MyReceiverImplementation();
JChannel jChannel = new JChannel().connect("clusterName").receiver(receiver);

JGroups 不会自动寻找要注入的接收器。


查看完整回答
反对 回复 2021-07-23
  • 1 回答
  • 0 关注
  • 236 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信