Package org.globus.net
Class PortRange
- java.lang.Object
-
- org.globus.net.PortRange
-
public class PortRange extends java.lang.Object
This class manages the port ranges. It keeps track of which ports are used and which ones are open.
-
-
Field Summary
Fields Modifier and Type Field Description private int
maxPort
private int
minPort
private boolean
portRange
private byte[]
ports
private static PortRange
tcpPortRange
private static PortRange
tcpSourcePortRange
private static PortRange
udpSourcePortRange
protected static byte
UNUSED
protected static byte
USED
-
Constructor Summary
Constructors Modifier Constructor Description protected
PortRange()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
free(int portNumber)
Releases or frees the port number.int
getFreePort(int lastPortNumber)
Returns first available port.static PortRange
getInstance()
Returns PortRange instance for TCP listening sockets.static PortRange
getTcpInstance()
Returns PortRange instance for TCP listening sockets.static PortRange
getTcpSourceInstance()
Returns PortRange instance for TCP source sockets.static PortRange
getUdpSourceInstance()
Returns PortRange instance for UDP source sockets.private void
init(java.lang.String portRangeStr)
boolean
isEnabled()
Checks if the port range is set.boolean
isInRange(int portNumber)
Checks if the port number if within port range.private void
setPort(int portNumber, byte type)
void
setUsed(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
-
portRange
private boolean portRange
-
minPort
private int minPort
-
maxPort
private int maxPort
-
ports
private byte[] ports
-
tcpPortRange
private static PortRange tcpPortRange
-
tcpSourcePortRange
private static PortRange tcpSourcePortRange
-
udpSourcePortRange
private static PortRange udpSourcePortRange
-
-
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.IOException
Returns 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.
-
setPort
private void setPort(int portNumber, byte type)
-
init
private void init(java.lang.String portRangeStr)
-
-