Enum NetStat.Platform

java.lang.Object
java.lang.Enum<NetStat.Platform>
org.terracotta.utilities.test.net.NetStat.Platform
All Implemented Interfaces:
Serializable, Comparable<NetStat.Platform>, java.lang.constant.Constable
Enclosing class:
NetStat

private static enum NetStat.Platform extends Enum<NetStat.Platform>
Specifies the platform-dependent support for obtaining netstat-like information.
  • Enum Constant Details

    • WINDOWS

      public static final NetStat.Platform WINDOWS
      Handles processing for Windows variants. For successful operation, powershell must be available via PATH.
    • MAC

      public static final NetStat.Platform MAC
      Handles processing for Mac OS X. This uses the nettop command in single-sample mode and augments the output with a ps command. Unlike lsof, nettop does not require elevated privileges to observe the open ports of processes opened by "other" users.
    • LINUX

      public static final NetStat.Platform LINUX
      Handles processing for Linux variants. This uses the lsof for discovering open ports and augments the lsof output with output from ps. lsof requires elevated privileges to see all ports and executed under the control of sudo with the password prompt suppressed.

      On Linux implementations which have sudo and lsof but do not have full representation of the network stack in the /proc filesystem, the netstat() method will return an empty list.

  • Field Details

    • osPlatform

      private final String osPlatform
    • PS_COMMAND

      private static final String[] PS_COMMAND
    • PS_PATTERN

      private static final Pattern PS_PATTERN
  • Constructor Details

    • Platform

      private Platform(String osPlatform)
  • Method Details

    • values

      public static NetStat.Platform[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static NetStat.Platform valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • netstat

      public abstract List<NetStat.BusyPort> netstat() throws NetStat.HostExecutionException
      Gets the list of TCP connections joined with information about the process that owns each connection. Administrator privileges may be required for complete output.
      Returns:
      a list of BusyPort instances describing the active ports; this list may include both IPv4 and IPv6 connections
      Throws:
      NetStat.HostExecutionException - if there was a failure in obtaining the TCP connections or host processes lists
    • netstat

      public abstract List<NetStat.BusyPort> netstat(int port) throws NetStat.HostExecutionException
      Gets the list of TCP connections for a single local port joined with information about the process that owns each connection. Administrator privileges may be required for complete output.
      Parameters:
      port - the target port
      Returns:
      a list of BusyPort instances describing the active connections for port; this list may include both IPv4 and IPv6 connections
      Throws:
      NetStat.HostExecutionException - if there was a failure in obtaining the TCP connections or host processes lists
    • getPlatform

      public static NetStat.Platform getPlatform() throws EnumConstantNotPresentException
      Gets the Platform constant for the current operating system.
      Returns:
      the current Platform constant
      Throws:
      EnumConstantNotPresentException - if the current operating system is not supported
    • mergeCommands

      private static List<NetStat.BusyPort> mergeCommands(List<NetStat.BusyPort> busyPorts) throws NetStat.HostExecutionException
      Creates an updated BusyPort list merging in a more complete command string from the ps command.
      Parameters:
      busyPorts - a list of BusyPort instances to update
      Returns:
      a new list of updated BusyPort instances
      Throws:
      NetStat.HostExecutionException - if an error is raised trying to run the ps command
    • runCommand

      private static <T> List<T> runCommand(String[] command, Function<Stream<String>,List<T>> conversion) throws NetStat.HostExecutionException
      Throws:
      NetStat.HostExecutionException
    • prepareCommand

      private static String[] prepareCommand(String[] commandTemplate, Object... args)
      Prepares a command array using String.format to substitute arguments. If the argument list contains more than one argument, commandTemplate should use format specifiers using the argument index form.
      Parameters:
      commandTemplate - the array composing the command to prepare
      args - the arguments to substitute into the command array strings
      Returns:
      the prepared command array