コード例 #1
0
ファイル: TMan.java プロジェクト: Nypias/id2210-vt13
        @Override
        public void handle(ThinkLeaderMessage event) {
          if (!electing) {
            electing = true;
            leader = null;
            ArrayList<PeerAddress> electionGroup = event.getElectionGroup();
            System.err.println(
                "[ELECTION::" + self.getPeerId() + "] I got a THINK_LEADER message!");
            if (self.getPeerId().equals(minimumUtility(electionGroup))) {
              System.err.println(
                  "[ELECTION::"
                      + self.getPeerId()
                      + "] I am eligible to start the election! ("
                      + minimumUtility(electionGroup)
                      + ")");
              for (PeerAddress peer : electionGroup) {
                if (!self.getPeerId().equals(peer.getPeerId())) {
                  trigger(new ElectionMessage(self, peer, electionGroup), networkPort);
                }
              }
              Stats.registerElectionMessages(electionGroup.size());

              ScheduleTimeout st = new ScheduleTimeout(JRConfig.BULLY_TIMEOUT);
              st.setTimeoutEvent(new ElectionTimeout(st, electionGroup));
              timeoutId = st.getTimeoutEvent().getTimeoutId();
              trigger(st, timerPort);
            }
          }
        }
コード例 #2
0
ファイル: TMan.java プロジェクト: Nypias/id2210-vt13
        @Override
        public void handle(LeaderDeadMessage event) {
          electing = true;
          if (tmanPartners.contains(leader)) {
            tmanPartners.remove(leader);
          }
          leader = null;

          CancelTimeout ct = new CancelTimeout(heartbeatTimeoutId);
          trigger(ct, timerPort);

          ArrayList<PeerAddress> electionGroup = event.getElectionGroup();
          System.err.println("[ELECTION::" + self.getPeerId() + "] I got a LEADER_DEAD message!");
          if (self.getPeerId().equals(minimumUtility(electionGroup))) {
            System.err.println(
                "[ELECTION::"
                    + self.getPeerId()
                    + "] I am eligible to start the election! ("
                    + minimumUtility(electionGroup)
                    + ")");
            for (PeerAddress peer : electionGroup) {
              if (!self.getPeerId().equals(peer.getPeerId())) {
                trigger(new ElectionMessage(self, peer, electionGroup), networkPort);
              }
            }
            Stats.registerElectionMessages(electionGroup.size());

            ScheduleTimeout st = new ScheduleTimeout(JRConfig.BULLY_TIMEOUT);
            st.setTimeoutEvent(new ElectionTimeout(st, electionGroup));
            timeoutId = st.getTimeoutEvent().getTimeoutId();
            trigger(st, timerPort);
          }
        }
コード例 #3
0
ファイル: TMan.java プロジェクト: Nypias/id2210-vt13
        @Override
        public void handle(HeartbeatTimeout event) {
          if (leader != null) {
            //                System.err.println("[HEARTBEAT::" + self.getPeerId() + "] I am sending
            // a heartbeat to the leader (" + leader.getPeerId() + ") ");
            trigger(new HeartbeatLeader(self, leader), networkPort);

            ScheduleTimeout st = new ScheduleTimeout(JRConfig.HEARTBEAT_TIMEOUT);
            st.setTimeoutEvent(new HeartbeatLeaderTimeout(st));
            heartbeatTimeoutId = st.getTimeoutEvent().getTimeoutId();
            trigger(st, timerPort);
          }
        }
コード例 #4
0
  /*
   * Ask for leader and best peers to a peer and launch a timeout in case of the peer is offline
   */
  void askInfos(Address peer) {
    // A request is currently pending
    if (currentRequests.containsKey(peer)) {
      return;
    }

    trigger(new LeaderMsg.AskLeaderInfos(self, peer, oldLeader), networkPort);

    ScheduleTimeout st = new ScheduleTimeout(config_timeout_info);
    st.setTimeoutEvent(new LeaderInfosTimeout(st));
    currentRequests.put(peer, st.getTimeoutEvent().getTimeoutId());
    trigger(st, timerPort);
  }
コード例 #5
0
ファイル: TMan.java プロジェクト: Nypias/id2210-vt13
        @Override
        public void handle(OKMessage event) {
          if (electing) {
            System.err.println(
                "[ELECTION::"
                    + self.getPeerId()
                    + "] I got an OK message from "
                    + event.getPeerSource().getPeerId()
                    + "!");
            CancelTimeout ct = new CancelTimeout(timeoutId);
            trigger(ct, timerPort);

            ScheduleTimeout st = new ScheduleTimeout(2 * JRConfig.BULLY_TIMEOUT);
            st.setTimeoutEvent(new CoordinatorTimeout(st, event.getElectionGroup()));
            timeoutId = st.getTimeoutEvent().getTimeoutId();
            trigger(st, timerPort);
          }
        }
コード例 #6
0
ファイル: TMan.java プロジェクト: Nypias/id2210-vt13
        @Override
        public void handle(CoordinatorTimeout event) {
          if (electing) {
            System.err.println("[ELECTION::" + self.getPeerId() + "] I got a coordinator timeout!");
            ArrayList<PeerAddress> electionGroup = event.getElectionGroup();
            for (PeerAddress peer : electionGroup) {
              if (self.getPeerId().compareTo(peer.getPeerId()) == -1) {
                trigger(new ElectionMessage(self, peer, electionGroup), networkPort);
                Stats.registerElectionMessage();

                ScheduleTimeout st = new ScheduleTimeout(JRConfig.BULLY_TIMEOUT);
                st.setTimeoutEvent(new ElectionTimeout(st, electionGroup));
                timeoutId = st.getTimeoutEvent().getTimeoutId();
                trigger(st, timerPort);
              }
            }
          }
        }
コード例 #7
0
ファイル: TMan.java プロジェクト: Nypias/id2210-vt13
        @Override
        public void handle(ElectionMessage event) {
          if (electing) {
            boolean sentElectionMessage = false;
            System.err.println(
                "[ELECTION::"
                    + self.getPeerId()
                    + "] I got an election message from "
                    + event.getPeerSource().getPeerId()
                    + "!");
            BigInteger sender = event.getPeerSource().getPeerId();
            if (sender.compareTo(self.getPeerId()) == -1) {
              trigger(
                  new OKMessage(self, event.getPeerSource(), event.getElectionGroup()),
                  networkPort);
              Stats.registerElectionMessage();
              ArrayList<PeerAddress> electionGroup = event.getElectionGroup();
              for (PeerAddress peer : electionGroup) {
                if (self.getPeerId().compareTo(peer.getPeerId()) == -1) {
                  sentElectionMessage = true;
                  trigger(new ElectionMessage(self, peer, electionGroup), networkPort);
                  Stats.registerElectionMessage();

                  ScheduleTimeout st = new ScheduleTimeout(JRConfig.BULLY_TIMEOUT);
                  st.setTimeoutEvent(new ElectionTimeout(st, electionGroup));
                  timeoutId = st.getTimeoutEvent().getTimeoutId();
                  trigger(st, timerPort);
                }
              }

              if (!sentElectionMessage) {
                for (PeerAddress peer : electionGroup) {
                  trigger(new CoordinatorMessage(self, peer, electionGroup), networkPort);
                }
                Stats.registerElectionMessages(electionGroup.size());
              }
            }
          }
        }