如果我没有显式调用ReceiverAdapter类的重写方法,例如jgroups中的viewAccepted()方法,该如何处理?

时间:2018-08-15 13:16:00

标签: java inheritance jboss jgroups

我编写了以下类来创建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 个答案:

答案 0 :(得分:1)

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

data %>% 
     group_by(person) %>% 
     filter(all(activity %in% relevant_activities))

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