p2ps.imp.endpoint
Class PortFactory
java.lang.Object
p2ps.imp.endpoint.PortFactory
- public class PortFactory
- extends java.lang.Object
A static class that maintains the range of ports available through a firewall
and suggests the next port that should be used
- Version:
- $Revision: 295 $
- Author:
- Ian Wang
|
Method Summary |
static int |
getMaxPort()
|
static int |
getMinPort()
|
static java.lang.Object |
getNewFactoryKey()
|
static int |
getNextPort(boolean input,
java.lang.Object key)
Returns the next port in the port range. |
static void |
setPortRange(int minport,
int maxport,
boolean inputonly)
Sets the range of available ports through the firewall |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PortFactory
public PortFactory()
setPortRange
public static void setPortRange(int minport,
int maxport,
boolean inputonly)
- Sets the range of available ports through the firewall
getMinPort
public static int getMinPort()
- Returns:
- the minimum available port
getMaxPort
public static int getMaxPort()
- Returns:
- the maximum available port
getNewFactoryKey
public static java.lang.Object getNewFactoryKey()
- Returns:
- a key used to access getNextPort(). A new key should be
generated each time a port is created.
getNextPort
public static int getNextPort(boolean input,
java.lang.Object key)
throws java.net.SocketException
- Returns the next port in the port range. Note that this port is not
guaranteed be available and might already be bound.
- Parameters:
input - true if this is an input portkey - the key created using getNewFactoryKey()
- Returns:
- a suggested port (or 0 if an ephemeral port is acceptable)
- Throws:
java.net.SocketException