<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.htrace.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.htrace.HTraceConfiguration;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.TreeSet;

/**
 * The HTrace process ID.<p/>
 *
 * HTrace process IDs are created from format strings.
 * Format strings contain variables which the ProcessId class will
 * replace with the correct values at runtime.<p/>
 *
 * <ul>
 * <li>${ip}: will be replaced with an ip address.</li>
 * <li>${pname}: will be replaced the process name obtained from java.</li>
 * </ul><p/>
 *
 * For example, the string "${pname}/${ip}" will be replaced with something
 * like: DataNode/192.168.0.1, assuming that the process' name is DataNode
 * and its IP address is 192.168.0.1.<p/>
 *
 * Process ID strings can contain backslashes as escapes.
 * For example, "\a" will map to "a".  "\${ip}" will map to the literal
 * string "${ip}", not the IP address.  A backslash itself can be escaped by a
 * preceding backslash.
 */
public final class ProcessId {
  private static final Log LOG = LogFactory.getLog(ProcessId.class);

  /**
   * The configuration key to use for process id
   */
  static final String PROCESS_ID_KEY = "process.id";

  /**
   * The default process ID to use if no other ID is configured.
   */
  private static final String DEFAULT_PROCESS_ID = "${pname}/${ip}";

  private final String processId;

  ProcessId(String fmt) {
    StringBuilder bld = new StringBuilder();
    StringBuilder varBld = null;
    boolean escaping = false;
    int varSeen = 0;<commit_msg>HTRACE-184 Expose PROCESS_ID_KEY configuration key (<NAME>)<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.htrace.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.htrace.HTraceConfiguration;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.TreeSet;

/**
 * The HTrace process ID.<p/>
 *
 * HTrace process IDs are created from format strings.
 * Format strings contain variables which the ProcessId class will
 * replace with the correct values at runtime.<p/>
 *
 * <ul>
 * <li>${ip}: will be replaced with an ip address.</li>
 * <li>${pname}: will be replaced the process name obtained from java.</li>
 * </ul><p/>
 *
 * For example, the string "${pname}/${ip}" will be replaced with something
 * like: DataNode/192.168.0.1, assuming that the process' name is DataNode
 * and its IP address is 192.168.0.1.<p/>
 *
 * Process ID strings can contain backslashes as escapes.
 * For example, "\a" will map to "a".  "\${ip}" will map to the literal
 * string "${ip}", not the IP address.  A backslash itself can be escaped by a
 * preceding backslash.
 */
public final class ProcessId {
  private static final Log LOG = LogFactory.getLog(ProcessId.class);

  /**
   * The configuration key to use for process id
   */
  public static final String PROCESS_ID_KEY = "process.id";

  /**
   * The default process ID to use if no other ID is configured.
   */
  private static final String DEFAULT_PROCESS_ID = "${pname}/${ip}";

  private final String processId;

  ProcessId(String fmt) {
    StringBuilder bld = new StringBuilder();
    StringBuilder varBld = null;
    boolean escaping = false;
    int varSeen = 0;
{'fraction_non_alphanumeric': 0.09563602599814298, 'fraction_numerical': 0.008356545961002786, 'mean_word_length': 3.932234432234432, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1889182', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1458, 'n_words': 627}