Beispiel #1
0
  /** Distribute peer information */
  private void sendHello() {
    HeartBeatMsg.Hello msg = new HeartBeatMsg.Hello();
    for (Map.Entry<String, JiniPeer> entry : agent.getPeers().entrySet()) {
      if (!entry.getValue().getReady()) continue;

      msg.appendPeers(entry.getKey());
    }
    msg.setUnversionedHeaders(agent.getHeaders());

    for (JiniPeer peer : agent.getPeers().values()) {
      if (!peer.getReady()) continue;
      msg.setSequence(peer.incSequence());
      peer.send(msg);
    }
  }
Beispiel #2
0
  @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);
  }