Пример #1
0
  protected List<PingData> read(InputStream in) {
    List<PingData> retval = null;
    try {
      while (true) {
        try {
          String name_str = Util.readToken(in);
          String uuid_str = Util.readToken(in);
          String addr_str = Util.readToken(in);
          String coord_str = Util.readToken(in);
          if (name_str == null || uuid_str == null || addr_str == null || coord_str == null) break;

          UUID uuid = null;
          try {
            long tmp = Long.valueOf(uuid_str);
            uuid = new UUID(0, tmp);
          } catch (Throwable t) {
            uuid = UUID.fromString(uuid_str);
          }

          PhysicalAddress phys_addr = new IpAddress(addr_str);
          boolean is_coordinator = coord_str.trim().equals("T") || coord_str.trim().equals("t");

          if (retval == null) retval = new ArrayList<>();
          retval.add(new PingData(uuid, true, name_str, phys_addr).coord(is_coordinator));
        } catch (Throwable t) {
          log.error(Util.getMessage("FailedReadingLineOfInputStream"), t);
        }
      }
      return retval;
    } finally {
      Util.close(in);
    }
  }
Пример #2
0
  /**
   * Main function
   *
   * @param args
   */
  public static void main(String[] args) {
    JWhiteBoard whiteBoard = null;
    String props = null;
    boolean no_channel = false;
    boolean jmx = true;
    boolean use_state = false;
    String group_name = null;
    long state_timeout = 5000;
    boolean use_unicasts = false;
    String name = null;
    boolean send_own_state_on_merge = true;
    AddressGenerator generator = null;

    // Get startup parameters for JWhiteBoard
    for (int i = 0; i < args.length; i++) {
      // Show help
      if ("-help".equals(args[i])) {
        help();
        return;
      }
      // Properties for Channel
      if ("-props".equals(args[i])) {
        props = args[++i];
        continue;
      }
      // If existed, use no channel
      if ("-no_channel".equals(args[i])) {
        no_channel = true;
        continue;
      }
      // Use Java Management Extensions or not
      if ("-jmx".equals(args[i])) {
        jmx = Boolean.parseBoolean(args[++i]);
        continue;
      }
      // If existed, set name for the Group
      if ("-clustername".equals(args[i])) {
        group_name = args[++i];
        continue;
      }
      // If existed, save Group's state
      if ("-state".equals(args[i])) {
        use_state = true;
        continue;
      }
      // If existed, set timeout for state
      if ("-timeout".equals(args[i])) {
        state_timeout = Long.parseLong(args[++i]);
        continue;
      }
      if ("-bind_addr".equals(args[i])) {
        System.setProperty("jgroups.bind_addr", args[++i]);
        continue;
      }
      if ("-use_unicasts".equals(args[i])) {
        use_unicasts = true;
        continue;
      }
      if ("-name".equals(args[i])) {
        name = args[++i];
        continue;
      }
      if ("-send_own_state_on_merge".equals(args[i])) {
        send_own_state_on_merge = Boolean.getBoolean(args[++i]);
        continue;
      }
      if ("-uuid".equals(args[i])) {
        generator = new OneTimeAddressGenerator(Long.valueOf(args[++i]));
        continue;
      }

      help();
      return;
    }

    try {
      whiteBoard =
          new JWhiteBoard(
              props,
              no_channel,
              jmx,
              use_state,
              state_timeout,
              use_unicasts,
              name,
              send_own_state_on_merge,
              generator);
      if (group_name == null) whiteBoard.setGroupName(group_name);
      whiteBoard.go();
    } catch (Throwable e) {
      e.printStackTrace(System.err);
      System.exit(0);
    }
  }