简体   繁体   English

Java代码来处理jgroups集群中的节点故障

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

My Jgroups config file contains the protocol/config 我的Jgroups配置文件包含协议/配置

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

But how do I use this in the Java code. 但是如何在Java代码中使用它。 For example, if there is a cluster and when I detect a failure I want to call an external notifier service via a REST call, like /nodeDown/nodeID I'm not able to find any java code which does this, all I see is message receive and send, is there a way I can implement this? 例如,如果有一个集群,并且当我检测到故障时,我想通过REST调用来调用外部通知程序服务, like /nodeDown/nodeID我将找不到任何可以执行此操作的Java代码,消息接收和发送,有没有一种方法可以实现?

Thanks 谢谢

Adding some more info I have done the step of writing a RecieverAdpater and override the start, stop, send, recieve method. 添加更多信息我已经完成了编写RecieverAdpater的步骤,并覆盖了start,stop,send,receve方法。 Please find some code here, 请在这里找到一些代码,

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 want to know where should 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.哪里I add code for example to handle the TimeOutException when I'm sending a message with the RSVP flag enabled. Another requirement is to know, which is the Java callback method which is called when SUSPECT(P) is triggered. 另一个要求是知道, which is the Java callback method which is called when SUSPECT(P) is triggered. I want to catch and handle the machine's going down, timout etc. 我想抓住并处理机器的故障,超时等。

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

Also is http://www.jgroups.org/manual/html/user-channel.html the section 3. APIs give all java/programmatic things we can do with JGroups. 这也是http://www.jgroups.org/manual/html/user-channel.html的第3部分。API提供了我们可以使用JGroups完成的所有Java /编程功能。

Thanks again 再次感谢

I found some documentation here, I think this is the class which I'm supposed to override 我在这里找到了一些文档,我认为这是我应该重写的类

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

OK, first off, you have a JChannel. 好,首先,您有一个JChannel。 You need to use it to register for view callbacks, like this: 您需要使用它来注册视图回调,如下所示:

   JChannel ch;
   ch.setReceiver(this);

' this ' extends ReceiverAdapter and overrides viewAccepted() : ' this ' 扩展了 ReceiverAdapter覆盖了 viewAccepted()

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

To determine the members which left between views v1 and v2: 要确定在视图v1和v2之间保留的成员:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM