亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果我沒有明確調用它們,那么如何在 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 關注
  • 250 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號