/**
  * Pick the best node from which to stream the data. Entries in <i>nodes</i> are already in the
  * priority order
  */
 static DatanodeInfo bestNode(
     DatanodeInfo nodes[], AbstractMap<DatanodeInfo, DatanodeInfo> deadNodes) throws IOException {
   if (nodes != null) {
     for (int i = 0; i < nodes.length; i++) {
       if (!deadNodes.containsKey(nodes[i])) {
         return nodes[i];
       }
     }
   }
   throw new IOException("No live nodes contain current block");
 }
Ejemplo n.º 2
0
  private void joinChat() {
    String userColor;

    sessionService.addOnSessionDestroyedListener(callback);

    defaultSessionTimeout = httpSession.getMaxInactiveInterval();
    httpSession.setMaxInactiveInterval(0);
    lastActivityTime = System.currentTimeMillis();

    String username = ((User) authToken.getPrincipal()).getUsername();
    LOG.debug("joinChat() user: "******"USER", username);

    int userNb = usersLoggedIn.incrementAndGet();
    // If a user is active more than once, give him the same color:
    if (userColorMap.containsKey(username)) {
      userColor = userColorMap.get(username);
    } else {
      userColor = PEER_COLORS[userNb % PEER_COLOR_NB];
      userColorMap.put(username, userColor);
    }

    thisSession.getUserProperties().put("COLOR", userColor);

    Message joinMsg = new Message();
    joinMsg.TYPE = "JOIN";
    joinMsg.SUBTYPE = "JOIN";
    joinMsg.USER_LIST = buildUserList(true);
    joinMsg.STATS_MSG = userNb + " User" + (userNb > 1 ? "s " : " ") + "online!";

    sendMessage(joinMsg);

    Message infoMsg = new Message();
    infoMsg.TYPE = "INFO";
    infoMsg.SUBTYPE = "JOIN";
    infoMsg.INFO_MSG = username + " has entered the building";
    infoMsg.STATS_MSG = userNb + " User" + (userNb > 1 ? "s " : " ") + "online!";
    infoMsg.USER_LIST = buildUserList(true);

    broadcastMessage(infoMsg, false);
  }
 /**
  * Replaces all unquantified variables with the unique copy stored as a value of the given map;
  * also instantiates all quantified variables and stores them in the given map.
  *
  * @param m The map in which to find unique copies of the variables.
  */
 public void consolidateVariables(java.util.AbstractMap m) {
   variableMap = m;
   if (m.containsKey(left)) left = (FirstOrderVariable) m.get(left);
   else m.put(left, left);
 }