コード例 #1
0
  /** Generates an instance based on the specified file. */
  public static RemoteControlPipeTable readHostFile(String filename) throws IOException {
    RemoteControlPipeTable table = new RemoteControlPipeTable();

    BufferedReader in = null;
    try {
      in = new BufferedReader(new InputStreamReader(new FileInputStream(filename), Main.ENCODING));
    } catch (UnsupportedEncodingException e) {
      // NOTREACHED
    }

    String line;
    while (true) {
      line = in.readLine();
      if (line == null) break; // EOF
      if (line.length() <= 0) continue; // skip brank lines

      if (line.startsWith("#") || line.startsWith(";") || line.startsWith("//"))
        continue; // comments

      String[] splitted = line.split("\\s+");
      HostAndPort hostPort = MessagingUtility.parseHostnameAndPort(splitted[0], Main.DIST_EMU_PORT);
      int startHostID = Integer.parseInt(splitted[1]);

      WorkerEntry entry = new WorkerEntry(hostPort, startHostID);
      table.entrySet.add(entry);
      table.entryMap.put(hostPort.getHostAddress(), entry);
    }

    return table;
  }
コード例 #2
0
  protected InetAddress getWorkerHostAddress(int hostID) {
    InetAddress ret = null;

    HostAndPort hostPort = this.getWorkerHostAndPort(hostID);
    if (hostPort != null) {
      try {
        ret = hostPort.getHostAddress();
      } catch (UnknownHostException e) {
        System.err.println("Could not resolve a hostname: " + hostPort.getHostName());
      }
    } else {
      ret = null;
    }

    return ret;
  }
コード例 #3
0
  /** Generates an instance based on the specified String. */
  public static RemoteControlPipeTable parseString(String str) throws UnknownHostException {
    RemoteControlPipeTable table = new RemoteControlPipeTable();

    String[] splitted = str.split("\\s*,\\s*");

    try {
      int index = 0;
      while (true) {
        HostAndPort hostPort =
            MessagingUtility.parseHostnameAndPort(splitted[index], Main.DIST_EMU_PORT);
        int startHostID = Integer.parseInt(splitted[index + 1]);

        WorkerEntry entry = new WorkerEntry(hostPort, startHostID);
        table.entrySet.add(entry);
        table.entryMap.put(hostPort.getHostAddress(), entry);

        index += 2;
      }
    } catch (ArrayIndexOutOfBoundsException e) {
      // ignore
    }

    return table;
  }