LimeWire Consolidated API

org.limewire.net
Interface SocketsManager

All Superinterfaces:
ListenerSupport<ConnectivityChangeEvent>
All Known Implementing Classes:
SocketsManagerImpl

public interface SocketsManager
extends ListenerSupport<ConnectivityChangeEvent>

Factory for creating Sockets.


Nested Class Summary
static class SocketsManager.ConnectType
          The different ways a connection can be attempted.
 
Method Summary
 boolean canConnect(Address address)
          Returns true if there is a connector that can connect to the address.
 boolean canResolve(Address address)
          Returns true if there is a resolver that can resolve the address.
<T extends ConnectObserver>
T
connect(Address address, T observer)
          Asynchronously connects to address resolving the address if possible/necessary and notifying observer of the success or failure.
 Socket connect(InetSocketAddress addr, int timeout)
          Connects and returns a socket to the given host, with a timeout.
 Socket connect(InetSocketAddress addr, int timeout, ConnectObserver observer)
          Sets up a socket for connecting.
 Socket connect(InetSocketAddress addr, int timeout, ConnectObserver observer, SocketsManager.ConnectType type)
          Sets up a socket for connecting.
 Socket connect(InetSocketAddress addr, int timeout, SocketsManager.ConnectType type)
          Connects and returns a socket to the given host, with a timeout.
 Socket connect(NBSocket socket, InetSocketAddress localAddr, InetSocketAddress remoteAddr, int timeout, ConnectObserver observer, SocketsManager.ConnectType type)
          Connects and returns a socket to the given host, with a timeout.
 Socket connect(NBSocket socket, InetSocketAddress localAddr, InetSocketAddress remoteAddr, int timeout, SocketsManager.ConnectType type)
          Connects and returns a socket to the given host, with a timeout.
 Socket create(SocketsManager.ConnectType type)
          Creates a new Socket.
 int getNumAllowedSockets()
          Returns the number of Sockets allowed to be created concurrently.
 int getNumWaitingSockets()
          Returns the number of Sockets that are waiting for the controller to process them.
 void registerConnector(AddressConnector connector)
          Registers an AddressConnector to handle connects for certain types of address.
 void registerResolver(AddressResolver resolver)
          Registers an AddressResolver to handle address resolution for certain types of addresses.
 boolean removeConnectObserver(ConnectObserver observer)
          Removes the given ConnectObserver from wanting to make a request.
<T extends AddressResolutionObserver>
T
resolve(Address address, T observer)
          Asynchronously resolves address to other addresses if possible and notifying observer of the success or failure.
 
Methods inherited from interface org.limewire.listener.ListenerSupport
addListener, removeListener
 

Method Detail

create

Socket create(SocketsManager.ConnectType type)
              throws IOException
Creates a new Socket. Does NOT bind or connnect the Socket The creation will use the specified connection type. For example, to make a plain socket, use ConnectType.PLAIN. To connect with a TLS Socket, use ConnectType.TLS.

Parameters:
type - the type of Socket to create
Returns:
Throws:
IOException

connect

Socket connect(NBSocket socket,
               InetSocketAddress localAddr,
               InetSocketAddress remoteAddr,
               int timeout,
               SocketsManager.ConnectType type)
               throws IOException
Connects and returns a socket to the given host, with a timeout. The timeout only applies to network conditions. More time might be spent waiting for an available slot to connect with. The connection will be attempted with the specified connection type. For example, to make a plain socket, use ConnectType.PLAIN. To connect with a TLS Socket, use ConnectType.TLS.

Parameters:
socket - the socket to connect; if null a new Socket will be created
localAddr - the Socket address to bind to locally; can be null
remoteAddr - the host/port to connect to
timeout - the desired timeout for connecting, in milliseconds, or 0 for no timeout. In case of a proxy connection, this timeout might be exceeded
type - the type of connection to attempt
Returns:
the connected Socket
Throws:
IOException - the connections couldn't be made in the requested time
IllegalArgumentException - if the port is invalid

connect

Socket connect(NBSocket socket,
               InetSocketAddress localAddr,
               InetSocketAddress remoteAddr,
               int timeout,
               ConnectObserver observer,
               SocketsManager.ConnectType type)
               throws IOException
Connects and returns a socket to the given host, with a timeout. The timeout only applies to network conditions. More time might be spent waiting for an available slot to connect with. The connection will be attempted with the specified connection type. For example, to make a plain socket, use ConnectType.PLAIN. To connect with a TLS Socket, use ConnectType.TLS.

Parameters:
socket - the socket to connect; if null a new Socket will be created
localAddr - the Socket address to bind to locally; can be null
remoteAddr - the host/port to connect to
timeout - the desired timeout for connecting, in milliseconds, or 0 for no timeout. In case of a proxy connection, this timeout might be exceeded
type - the type of connection to attempt
Returns:
the connected Socket
Throws:
IOException - the connections couldn't be made in the requested time
IllegalArgumentException - if the port is invalid

connect

Socket connect(InetSocketAddress addr,
               int timeout)
               throws IOException
Connects and returns a socket to the given host, with a timeout. The timeout only applies to network conditions. More time might be spent waiting for an available slot to connect with.

Parameters:
addr - the host/port to connect to
timeout - the desired timeout for connecting, in milliseconds, or 0 for no timeout. In case of a proxy connection, this timeout might be exceeded
Returns:
the connected Socket
Throws:
IOException - the connections couldn't be made in the requested time
IllegalArgumentException - if the port is invalid

connect

Socket connect(InetSocketAddress addr,
               int timeout,
               SocketsManager.ConnectType type)
               throws IOException
Connects and returns a socket to the given host, with a timeout. The timeout only applies to network conditions. More time might be spent waiting for an available slot to connect with. The connection will be attempted with the specified connection type. For example, to make a plain socket, use ConnectType.PLAIN. To connect with a TLS Socket, use ConnectType.TLS.

Parameters:
addr - the host/port to connect to
timeout - the desired timeout for connecting, in milliseconds, or 0 for no timeout. In case of a proxy connection, this timeout might be exceeded
type - the type of connection to attempt
Returns:
the connected Socket
Throws:
IOException - the connections couldn't be made in the requested time
IllegalArgumentException - if the port is invalid

connect

Socket connect(InetSocketAddress addr,
               int timeout,
               ConnectObserver observer)
               throws IOException
Sets up a socket for connecting. This method may either block or return immediately, depending on if if observer is null or not. If observer is non-null, this returns immediately. This may either return a connected or unconnected Socket, depending on if a connection was able to be established immediately. The ConnectObserver will always be notified of success via handleConnect(Socket), and failure via shutdown(). If the connection was established immediately, it is possible that handleConnect(Socket) is called before this method returns. If observer is null, this method blocks until a connection can be established. If no connection can be established, an IOException is thrown.

Parameters:
addr - address/port
timeout - the desired timeout for connecting, in milliseconds, or 0 for no timeout. In case of a proxy connection, this timeout might be exceeded
observer - the ConnectObserver to notify about non-blocking connect events
Returns:
the Socket (connected or unconnected)
Throws:
IOException - see above
IllegalArgumentException - if the port is invalid

connect

Socket connect(InetSocketAddress addr,
               int timeout,
               ConnectObserver observer,
               SocketsManager.ConnectType type)
               throws IOException
Sets up a socket for connecting. This method may either block or return immediately, depending on if if observer is null or not. If observer is non-null, this returns immediately. This may either return a connected or unconnected Socket, depending on if a connection was able to be established immediately. The ConnectObserver will always be notified of success via handleConnect(Socket), and failure via shutdown(). If the connection was established immediately, it is possible that handleConnect(Socket) is called before this method returns. If observer is null, this method blocks until a connection can be established. If no connection can be established, an IOException is thrown. The ConnectType determines the kind of connection that is attempted. For example, ConnectType.PLAIN will create a plaintext socket, whereas ConnectType.TLS will create a TLS socket.

Parameters:
addr - address/port
timeout - the desired timeout for connecting, in milliseconds, or 0 for no timeout. In case of a proxy connection, this timeout might be exceeded
observer - the ConnectObserver to notify about non-blocking connect events
type - the type of connection to attempt
Returns:
the Socket (connected or unconnected)
Throws:
IOException - see above
IllegalArgumentException - if the port is invalid

connect

<T extends ConnectObserver> T connect(Address address,
                                      T observer)
Asynchronously connects to address resolving the address if possible/necessary and notifying observer of the success or failure.

Parameters:
timeout - timeout in milliseconds
Returns:
the observer for fluent access

resolve

<T extends AddressResolutionObserver> T resolve(Address address,
                                                T observer)
Asynchronously resolves address to other addresses if possible and notifying observer of the success or failure.

If there is no resolver for address, the observer is notified of a address resolution with the exact same address.

Returns:
observer for fluent access

removeConnectObserver

boolean removeConnectObserver(ConnectObserver observer)
Removes the given ConnectObserver from wanting to make a request. This returns true if it was able to remove the observer because the request had not been processed yet. Otherwise it returns false, and the ConnectObserver should expect some sort of callback indicating whether or not the connect succeeded.


getNumAllowedSockets

int getNumAllowedSockets()
Returns the number of Sockets allowed to be created concurrently.


getNumWaitingSockets

int getNumWaitingSockets()
Returns the number of Sockets that are waiting for the controller to process them.


registerConnector

void registerConnector(AddressConnector connector)
Registers an AddressConnector to handle connects for certain types of address. When #connect(Address, int, ConnectObserver) is called the sockets manager will iterate over all registered address connectors and see which one can connect to the given address. See AddressConnector.


registerResolver

void registerResolver(AddressResolver resolver)
Registers an AddressResolver to handle address resolution for certain types of addresses. When #resolve(Address, int, AddressResolutionObserver) is called the sockets manager will iterate over all registered address resolvers and see which one can resolve the given address. See AddressResolver.


canConnect

boolean canConnect(Address address)
Returns true if there is a connector that can connect to the address.


canResolve

boolean canResolve(Address address)
Returns true if there is a resolver that can resolve the address.


LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.