public class PortAssigner extends Object
ServerPortRegistry
. While you can use this class to assign
an open port, it will not be formally registered with the platform and will not be known to certain web services. The
preferred way to get an open port for the platform is to create a ServerPort
object and register it with
ServerPortRegistry.addPort
. The physical port number can then be assigned with
ServerPort.assignPort()
.Modifier and Type | Method and Description |
---|---|
int[] |
assignPorts(int numberOfPorts) |
void |
clear()
Clear all open ports.
|
int |
getFreePort() |
int |
getFreePortFromRange(int startPort,
int endPort)
Return the first free port number within a range.
|
static PortAssigner |
getInstance() |
HashSet<Integer> |
getUsedPorts() |
HashSet<Integer> |
getUsedPortsExternal() |
void |
readUsedPortFile(String filePath) |
void |
writeUsedPortFile(String filePath) |
public static PortAssigner getInstance()
public int[] assignPorts(int numberOfPorts) throws IOException
IOException
public int getFreePort() throws IOException
IOException
public int getFreePortFromRange(int startPort, int endPort) throws IOException
getUsedPorts()
or getUsedPortsExternal()
list.startPort
- lowest port number in rangeendPort
- highest port number in rangeIOException
- If port could not be obtained.IllegalStateException
- if start or end ports are invalid.public HashSet<Integer> getUsedPorts()
public HashSet<Integer> getUsedPortsExternal()
public void writeUsedPortFile(String filePath) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public void readUsedPortFile(String filePath) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public void clear()