@VisibleForTesting
  static ProcessIdentifier getProcessIdentifier(String jvmName, Timestamp censusTimestamp) {
    String hostname;
    int pid;
    // jvmName should be something like '<pid>@<hostname>', at least in Oracle and OpenJdk JVMs
    int delimiterIndex = jvmName.indexOf('@');
    if (delimiterIndex < 1) {
      // Not the expected format, generate a random number.
      try {
        hostname = InetAddress.getLocalHost().getHostName();
      } catch (UnknownHostException e) {
        hostname = "localhost";
      }
      // Generate a random number as the PID.
      pid = new SecureRandom().nextInt();
    } else {
      hostname = jvmName.substring(delimiterIndex + 1, jvmName.length());
      try {
        pid = Integer.parseInt(jvmName.substring(0, delimiterIndex));
      } catch (NumberFormatException e) {
        // Generate a random number as the PID if format is unexpected.
        pid = new SecureRandom().nextInt();
      }
    }

    return ProcessIdentifier.newBuilder()
        .setHostName(hostname)
        .setPid(pid)
        .setStartTimestamp(MetricsProtoUtils.toTimestampProto(censusTimestamp))
        .build();
  }
@ VisibleForTesting static ProcessIdentifier getProcessIdentifier ( String jvmName , Timestamp censusTimestamp ) { String hostname ; int pid ; int delimiterIndex = jvmName . indexOf ( '@' ) ; if ( delimiterIndex < 1 ) { try { hostname = InetAddress . getLocalHost ( ) . getHostName ( ) ; } catch ( UnknownHostException e ) { hostname = "localhost" ; } pid = new SecureRandom ( ) . nextInt ( ) ; } else { hostname = jvmName . substring ( delimiterIndex + 1 , jvmName . length ( ) ) ; try { pid = Integer . parseInt ( jvmName . substring ( 0 , delimiterIndex ) ) ; } catch ( NumberFormatException e ) { pid = new SecureRandom ( ) . nextInt ( ) ; } } return ProcessIdentifier . newBuilder ( ) . setHostName ( hostname ) . setPid ( pid ) . setStartTimestamp ( MetricsProtoUtils . toTimestampProto ( censusTimestamp ) ) . build ( ) ; }
Creates process identifier with the given JVM name and start time.