class PID implements Serializable {

  public static PID fromString(String pid) throws IllegalArgumentException {
    List<String> components = Splitter.on("@").omitEmptyStrings().splitToList(pid);
    if (components.size() != 2) {
      throw new IllegalArgumentException(
          "Illegal libprocess pid: " + pid + ". Format is id@host:port.");
    }
    String id = components.get(0);
    if (CharMatcher.WHITESPACE.matchesAnyOf(id)) {
      throw new IllegalArgumentException("No whitespace allowed in process id.");
    }
    HostAndPort hostAndPort = HostAndPort.fromString(components.get(1))
        .requireBracketsForIPv6();
    if (!hostAndPort.hasPort()) {
      throw new IllegalArgumentException("No port specified.");
    }
    return new PID(id, hostAndPort);
  }

}

class PIDTest {

  @Test
  public void testFromString() throws Exception {

    PID pid = PID.fromString("scheduler@192.168.1.1:8081");
    assertEquals("scheduler@192.168.1.1:8081", pid.toString());
    assertEquals("http://192.168.1.1:8081/scheduler", pid.getBaseUrl().toString());
  }

}