示例#1
0
        @Override
        public void handle(CoordinatorMessage event) {
          System.err.println(
              "[ELECTION::"
                  + self.getPeerId()
                  + "] I got a coordinator message from "
                  + event.getPeerSource().getPeerId()
                  + " the leader is "
                  + event.getLeader().getPeerId()
                  + "!");
          CancelTimeout ct = new CancelTimeout(timeoutId);
          trigger(ct, timerPort);

          leader = event.getLeader();
          electionGroup = event.getElectionGroup();
          electing = false;

          if (self.getPeerId().compareTo(leader.getPeerId()) != 0) {
            ScheduleTimeout heartbeatTimeout = new ScheduleTimeout(JRConfig.HEARTBEAT_TIMEOUT);
            heartbeatTimeout.setTimeoutEvent(new HeartbeatTimeout(heartbeatTimeout));
            trigger(heartbeatTimeout, timerPort);
          }

          Stats.reportElectionMessages();
          Stats.reportLeader(leader);
        }
示例#2
0
        @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);
            }
          }
        }
示例#3
0
        public void handle(Pp2pSend event) {
          Address destination = event.getDestination();

          if (destination.equals(self)) {
            // deliver locally
            Pp2pDeliver deliverEvent = event.getDeliverEvent();
            trigger(deliverEvent, pp2p);
            return;
          }

          long latency;
          try {
            latency = topology.getLatencyMs(self, destination);
          } catch (NoLinkException e) {
            // there is no link to the destination, we drop the message
            return;
          }

          // make a DelayLinkMessage to be delivered at the destination
          DelayLinkMessage message =
              new DelayLinkMessage(self, destination, event.getDeliverEvent());

          if (latency > 0) {
            // delay the sending according to the latency
            ScheduleTimeout st = new ScheduleTimeout(latency);
            st.setTimeoutEvent(new DelayedMessage(st, message));
            trigger(st, timer);
          } else {
            // send immediately
            trigger(message, network);
          }
        }
示例#4
0
        @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);
          }
        }
  private void doSleep(long delay) {
    logger.info("Sleeping {} milliseconds...", delay);

    ScheduleTimeout st = new ScheduleTimeout(delay);
    st.setTimeoutEvent(new ApplicationContinue(st));
    trigger(st, timer);

    blocking = true;
  }
示例#6
0
 /**
  * executing a task means allocate the resources for TimeToHoldResources.
  *
  * <p>This is the only time that TimeToHoldResources is used (since in theory is not known a
  * priori, but we need it to simulate the "execution" of the task
  *
  * @param t
  */
 private void runTask(Task t) {
   t.allocate();
   log.debug(
       "{} RUNNING {} ({}/{}) AFTER {} QUEUE TIME ",
       new Object[] {getId(), t.id, res.numFreeCpus, res.freeMemInMbs, t.getQueueTime()});
   ScheduleTimeout tout = new ScheduleTimeout(t.timeToHoldResource);
   tout.setTimeoutEvent(new TaskDone(tout, t.id));
   trigger(tout, timerPort);
 }
示例#7
0
  /*
   * Launch an election: ask my neighbors if they agree
   */
  public void launchElection() {
    // Ask all tman neighbours if I can be the leader
    for (Address dest : tmanNeighbours) {
      trigger(new LeaderMsg.Apply(self, dest), networkPort);
    }

    expectedElectors = tmanNeighbours;
    ScheduleTimeout rst = new ScheduleTimeout(config_timeout_election);
    rst.setTimeoutEvent(new ElectionTimeout(rst));
    trigger(rst, timerPort);
  }
示例#8
0
 private void scheduleShuffleTimeout(NatedAddress dest) {
   if (shuffleTimeoutId != null) {
     log.warn("{} double starting shuffle timeout", logPrefix);
     return;
   }
   ScheduleTimeout spt = new ScheduleTimeout(croupierConfig.shufflePeriod / 2);
   ShuffleTimeout sc = new ShuffleTimeout(spt, dest);
   spt.setTimeoutEvent(sc);
   shuffleTimeoutId = sc.getTimeoutId();
   trigger(spt, timer);
 }
示例#9
0
        @Override
        public void handle(HeartbeatLeaderResponse event) {
          if (leader != null) {
            //                System.err.println("[HEARTBEAT::" + self.getPeerId() + "] I got a
            // leader heartbeat response!");
            CancelTimeout ct = new CancelTimeout(heartbeatTimeoutId);
            trigger(ct, timerPort);

            ScheduleTimeout heartbeatTimeout = new ScheduleTimeout(JRConfig.HEARTBEAT_TIMEOUT);
            heartbeatTimeout.setTimeoutEvent(new HeartbeatTimeout(heartbeatTimeout));
            trigger(heartbeatTimeout, timerPort);
          }
        }
示例#10
0
        @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);
          }
        }
示例#11
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);
  }
示例#12
0
        @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);
          }
        }
示例#13
0
        @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);
              }
            }
          }
        }
示例#14
0
  /*
   * Lauch requests for the leader and best peers to the best peers we know
   */
  void launchRequests() {
    // If the leader is still unknown and we have not exceeded our limit of concurrent requests.
    while (currentLeader == null && currentRequests.size() <= config_max_requests) {
      // Select a peer which may be contacted
      Address peer = selectNextPeer();

      if (peer != null) askInfos(peer);
      else {
        // we have no possibility to find a leader, so we wait some time and try again
        if (currentRequests.isEmpty()) {
          ScheduleTimeout rst = new ScheduleTimeout(config_delay_tryagain);
          rst.setTimeoutEvent(new UpdateLeaderTimeout(rst));
          trigger(rst, timerPort);
        }

        return;
      }
    }
  }
示例#15
0
        @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());
              }
            }
          }
        }
示例#16
0
文件: Epfd.java 项目: Fil0x/ID2203
 private void setTimer(long delay) {
   timeout = new ScheduleTimeout(delay);
   timeout.setTimeoutEvent(new CheckTimeout(timeout));
   trigger(timeout, timer);
 }