@Override public void processCallback(JiniMsg msg) { String endpoint = msg.getIdentityString(); JiniPeer peer = agent.findPeer(endpoint); if (peer == null && msg.getId() == HeartBeatMsg.PING) peer = agent.connectPeer(endpoint); if (peer == null) return; switch (msg.getId()) { case HeartBeatMsg.PING: peer.send(new HeartBeatMsg.PingOk(peer.incSequence())); break; case HeartBeatMsg.PING_OK: if (!peer.getReady()) { peer.setReady(true); sendHello(); agent.onEvent(JiniEvent.PEER_ENTER, peer.getEndpoint()); } break; case HeartBeatMsg.HELLO: HeartBeatMsg.Hello hello = (HeartBeatMsg.Hello) msg; List<String> peers = hello.getPeers(); for (String peerAddr : peers) { if (peerAddr.equals(agent.getAddress())) continue; JiniPeer peer_ = agent.findPeer(peerAddr); if (peer_ == null) { // Other node knows new peer information agent.connectPeer(peerAddr); } } break; } peer.refresh(evasive, expired); }
@Override public void initialize(JiniAgent agent, Object... args) { this.agent = agent; for (String addr : addrs) agent.connectPeer(addr); }