Enum NetStat.Platform
- java.lang.Object
-
- java.lang.Enum<NetStat.Platform>
-
- org.terracotta.utilities.test.net.NetStat.Platform
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<NetStat.Platform>
- Enclosing class:
- NetStat
private static enum NetStat.Platform extends java.lang.Enum<NetStat.Platform>
Specifies the platform-dependent support for obtainingnetstat-like information.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringosPlatformprivate static java.lang.String[]PS_COMMANDprivate static java.util.regex.PatternPS_PATTERN
-
Constructor Summary
Constructors Modifier Constructor Description privatePlatform(java.lang.String osPlatform)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static NetStat.PlatformgetPlatform()Gets thePlatformconstant for the current operating system.private static java.util.List<NetStat.BusyPort>mergeCommands(java.util.List<NetStat.BusyPort> busyPorts)Creates an updatedBusyPortlist merging in a more complete command string from thepscommand.abstract java.util.List<NetStat.BusyPort>netstat()Gets the list of TCP connections joined with information about the process that owns each connection.abstract java.util.List<NetStat.BusyPort>netstat(int port)Gets the list of TCP connections for a single local port joined with information about the process that owns each connection.private static java.lang.String[]prepareCommand(java.lang.String[] commandTemplate, java.lang.Object... args)Prepares a command array usingString.formatto substitute arguments.private static <T> java.util.List<T>runCommand(java.lang.String[] command, java.util.function.Function<java.util.stream.Stream<java.lang.String>,java.util.List<T>> conversion)static NetStat.PlatformvalueOf(java.lang.String name)Returns the enum constant of this type with the specified name.static NetStat.Platform[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
WINDOWS
public static final NetStat.Platform WINDOWS
Handles processing for Windows variants. For successful operation,powershellmust be available viaPATH.
-
MAC
public static final NetStat.Platform MAC
Handles processing for Mac OS X. This uses thenettopcommand in single-sample mode and augments the output with apscommand. Unlikelsof,nettopdoes 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 thelsoffor discovering open ports and augments thelsofoutput with output fromps.lsofrequires elevated privileges to see all ports and executed under the control ofsudowith the password prompt suppressed.On Linux implementations which have
sudoandlsofbut do not have full representation of the network stack in the/procfilesystem, thenetstat()method will return an empty list.
-
-
Method Detail
-
values
public static NetStat.Platform[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (NetStat.Platform c : NetStat.Platform.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static NetStat.Platform valueOf(java.lang.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:
java.lang.IllegalArgumentException- if this enum type has no constant with the specified namejava.lang.NullPointerException- if the argument is null
-
netstat
public abstract java.util.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
BusyPortinstances 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 java.util.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
BusyPortinstances describing the active connections forport; 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 java.lang.EnumConstantNotPresentException
Gets thePlatformconstant for the current operating system.- Returns:
- the current
Platformconstant - Throws:
java.lang.EnumConstantNotPresentException- if the current operating system is not supported
-
mergeCommands
private static java.util.List<NetStat.BusyPort> mergeCommands(java.util.List<NetStat.BusyPort> busyPorts) throws NetStat.HostExecutionException
Creates an updatedBusyPortlist merging in a more complete command string from thepscommand.- Parameters:
busyPorts- a list ofBusyPortinstances to update- Returns:
- a new list of updated
BusyPortinstances - Throws:
NetStat.HostExecutionException- if an error is raised trying to run thepscommand
-
runCommand
private static <T> java.util.List<T> runCommand(java.lang.String[] command, java.util.function.Function<java.util.stream.Stream<java.lang.String>,java.util.List<T>> conversion) throws NetStat.HostExecutionException- Throws:
NetStat.HostExecutionException
-
prepareCommand
private static java.lang.String[] prepareCommand(java.lang.String[] commandTemplate, java.lang.Object... args)Prepares a command array usingString.formatto substitute arguments. If the argument list contains more than one argument,commandTemplateshould use format specifiers using the argument index form.- Parameters:
commandTemplate- the array composing the command to prepareargs- the arguments to substitute into the command array strings- Returns:
- the prepared command array
-
-