com.sun.grizzly
Class PortRange

java.lang.Object
  extended by com.sun.grizzly.PortRange

public class PortRange
extends Object

Immutable class representing a port range.


Constructor Summary
PortRange(int port)
          Creates a port range containing a single port.
PortRange(int low, int high)
          Creates a port range with the given bounds (both inclusive).
 
Method Summary
 void bind(DatagramSocket socket)
          Binds socket to the wildcard address.
 void bind(DatagramSocket socket, InetAddress address)
          Binds socket to address.
 void bind(ServerSocket socket, InetAddress address, int backLog)
          Binds socket to address.
 void bind(ServerSocket socket, InetSocketAddress endpoint, int backLog)
          Binds socket to endpoint.
 void bind(ServerSocket socket, int backLog)
          Binds socket to the wildcard address.
 void bind(Socket socket)
          Binds socket to the wildcard address.
 void bind(Socket socket, InetAddress address)
          Binds socket to address.
 void bind(Socket socket, InetSocketAddress endpoint)
          Binds socket to endpoint.
 int getLower()
           
 int getUpper()
           
 int random()
          Returns a random port within the range.
 int succ(int port)
          Returns the successor of a port within the range, wrapping around to the lowest port if necessary.
 String toString()
           
static PortRange valueOf(String s)
          Parse a port range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PortRange

public PortRange(int low,
                 int high)
Creates a port range with the given bounds (both inclusive).

Throws:
IllegalArgumentException - is either bound is not between 0 and 65535, or if high is lower than low.

PortRange

public PortRange(int port)
Creates a port range containing a single port.

Method Detail

valueOf

public static PortRange valueOf(String s)
                         throws IllegalArgumentException
Parse a port range. A port range consists of either a single integer, or two integers separated by either a comma or a colon. The bounds must be between 0 and 65535, both inclusive.

Returns:
The port range represented by s. Returns the range [0,0] if s is null or empty.
Throws:
IllegalArgumentException

random

public int random()
Returns a random port within the range.


succ

public int succ(int port)
Returns the successor of a port within the range, wrapping around to the lowest port if necessary.


getLower

public int getLower()

getUpper

public int getUpper()

bind

public void bind(ServerSocket socket,
                 InetSocketAddress endpoint,
                 int backLog)
          throws IOException
Binds socket to endpoint. If the port in endpoint is zero, then a port is chosen from this port range. If the port range is [0,0], then a free port is chosen by the OS.

Throws:
IOException - if the bind operation fails, or if the socket is already bound.

bind

public void bind(Socket socket,
                 InetSocketAddress endpoint)
          throws IOException
Binds socket to endpoint. If the port in endpoint is zero, then a port is chosen from this port range. If the port range is [0,0], then a free port is chosen by the OS.

Throws:
IOException - if the bind operation fails, or if the socket is already bound.

bind

public void bind(ServerSocket socket,
                 InetAddress address,
                 int backLog)
          throws IOException
Binds socket to address. A port is chosen from this port range. If the port range is [0,0], then a free port is chosen by the OS.

Throws:
IOException - if the bind operation fails, or if the socket is already bound.

bind

public void bind(Socket socket,
                 InetAddress address)
          throws IOException
Binds socket to address. A port is chosen from this port range. If the port range is [0,0], then a free port is chosen by the OS.

Throws:
IOException - if the bind operation fails, or if the socket is already bound.

bind

public void bind(DatagramSocket socket,
                 InetAddress address)
          throws IOException
Binds socket to address. A port is chosen from this port range. If the port range is [0,0], then a free port is chosen by the OS.

Throws:
IOException - if the bind operation fails, or if the socket is already bound.

bind

public void bind(DatagramSocket socket)
          throws IOException
Binds socket to the wildcard address. A port is chosen from this port range. If the port range is [0,0], then a free port is chosen by the OS.

Throws:
IOException - if the bind operation fails, or if the socket is already bound.

bind

public void bind(ServerSocket socket,
                 int backLog)
          throws IOException
Binds socket to the wildcard address. A port is chosen from this port range. If the port range is [0,0], then a free port is chosen by the OS.

Throws:
IOException - if the bind operation fails, or if the socket is already bound.

bind

public void bind(Socket socket)
          throws IOException
Binds socket to the wildcard address. A port is chosen from this port range. If the port range is [0,0], then a free port is chosen by the OS.

Throws:
IOException - if the bind operation fails, or if the socket is already bound.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012 Oracle Corporation. All Rights Reserved.