簡體   English   中英

Java代碼來處理jgroups集群中的節點故障

[英]Java code to handle node failure in jgroups cluster

我的Jgroups配置文件包含協議/配置

<FD timeout="3000" max_tries="3" />

但是如何在Java代碼中使用它。 例如,如果有一個集群,並且當我檢測到故障時,我想通過REST調用來調用外部通知程序服務, like /nodeDown/nodeID我將找不到任何可以執行此操作的Java代碼,消息接收和發送,有沒有一種方法可以實現?

謝謝

添加更多信息我已經完成了編寫RecieverAdpater的步驟,並覆蓋了start,stop,send,receve方法。 請在這里找到一些代碼,

public void receive(Message msg) {
    JGroupsDataPacket pckt = (JGroupsDataPacket) msg.getObject();
    if ( pckt.getCmd().equals("cacheUpdate") ){
        int uid = pckt.getAffectedUid();
        cacheUpdateRoutine(uid);
    }
    if ( pckt.getCmd().equals("ack") ){
        System.out.println("got the mesaage!");
    }       
    logger.log(LogLevel.ERROR, "received msg from " + msg.getSrc() + ": " + msg.getObject());
}

public void send(JGroupsDataPacket pckt){
    Message msg = new Message(null, null, pckt);
    msg.setFlag(Message.Flag.RSVP);

    try {
        channel.send(msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

我想知道在I add code for example to handle the TimeOutException when I'm sending a message with the RSVP flag enabled.哪里I add code for example to handle the TimeOutException when I'm sending a message with the RSVP flag enabled. 另一個要求是知道, which is the Java callback method which is called when SUSPECT(P) is triggered. 我想抓住並處理機器的故障,超時等。

Is the viewAccepted() the only place where I can handle this? Is there a sample code around this? 

這也是http://www.jgroups.org/manual/html/user-channel.html的第3部分。API提供了我們可以使用JGroups完成的所有Java /編程功能。

再次感謝

我在這里找到了一些文檔,我認為這是我應該重寫的類

public interface MembershipListener {
    void viewAccepted(View new_view);
    void suspect(Object suspected_mbr);
    void block();
    void unblock();
}

好,首先,您有一個JChannel。 您需要使用它來注冊視圖回調,如下所示:

   JChannel ch;
   ch.setReceiver(this);

' this ' 擴展了 ReceiverAdapter覆蓋了 viewAccepted()

   public void viewAccepted(View view) {
       // handle new view
   }

要確定在視圖v1和v2之間保留的成員:

   List<Address> left_mbrs=View.leftMembers(v1,v2);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM