Package org.globus.net
Class PortRange
- java.lang.Object
-
- org.globus.net.PortRange
-
public class PortRange extends java.lang.ObjectThis class manages the port ranges. It keeps track of which ports are used and which ones are open.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedPortRange()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfree(int portNumber)Releases or frees the port number.intgetFreePort(int lastPortNumber)Returns first available port.static PortRangegetInstance()Returns PortRange instance for TCP listening sockets.static PortRangegetTcpInstance()Returns PortRange instance for TCP listening sockets.static PortRangegetTcpSourceInstance()Returns PortRange instance for TCP source sockets.static PortRangegetUdpSourceInstance()Returns PortRange instance for UDP source sockets.booleanisEnabled()Checks if the port range is set.booleanisInRange(int portNumber)Checks if the port number if within port range.voidsetUsed(int portNumber)Sets the port number as used.
-
-
-
Field Detail
-
UNUSED
protected static final byte UNUSED
- See Also:
- Constant Field Values
-
USED
protected static final byte USED
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static PortRange getInstance()
Returns PortRange instance for TCP listening sockets.- See Also:
getTcpInstance()
-
getTcpInstance
public static PortRange getTcpInstance()
Returns PortRange instance for TCP listening sockets. If the tcp.port.range property is set, the class will be initialized with the specified port ranges.- Returns:
- PortRange the default instace of this class.
-
getTcpSourceInstance
public static PortRange getTcpSourceInstance()
Returns PortRange instance for TCP source sockets. If the tcp.source.port.range property is set, the class will be initialized with the specified port ranges.- Returns:
- PortRange the default instace of this class.
-
getUdpSourceInstance
public static PortRange getUdpSourceInstance()
Returns PortRange instance for UDP source sockets. If the udp.source.port.range property is set, the class will be initialized with the specified port ranges.- Returns:
- PortRange the default instace of this class.
-
isEnabled
public boolean isEnabled()
Checks if the port range is set.- Returns:
- true if the port range is set, false otherwise.
-
getFreePort
public int getFreePort(int lastPortNumber) throws java.io.IOExceptionReturns first available port.- Parameters:
lastPortNumber- port number to start finding the next available port from. Set it to 0 if called initialy.- Returns:
- the next available port number from the lastPortNumber.
- Throws:
java.io.IOException- if there is no more free ports available or if the lastPortNumber is incorrect.
-
setUsed
public void setUsed(int portNumber)
Sets the port number as used.- Parameters:
portNumber- port number
-
free
public void free(int portNumber)
Releases or frees the port number. (Mark it as unused)- Parameters:
portNumber- port number
-
isInRange
public boolean isInRange(int portNumber)
Checks if the port number if within port range. Does not check if it is a free, but only checks if it is within said range.
-
-