com.googlecode.mobilityrpc.network
Interface ConnectionManager

All Known Subinterfaces:
ConnectionManagerInternal
All Known Implementing Classes:
ConnectionManagerImpl

public interface ConnectionManager

Keeps track of incoming and outgoing connections to/from remote machines, and controls the opening and closing of server sockets on the local machine to receive incoming connections.

Provides bindConnectionListener(ConnectionId) and unbindConnectionListener(ConnectionId) methods which allow the application to request the library to start and stop listening, respectively, for incoming connections from remote machines on the specified ports.

Provides a getConnection(ConnectionId) method, which will establish a new connection to the specified machine if no such connection already exists, or will return an already-established connection if one already exists. It should be noted that an already-established connection could include an inbound connection received from the specified machine. Connections are persistent, bi-directional, full-duplex, multiplexed, and responses are asynchronous and non-blocking; therefore inbound connections are equivalent to outbound ones.

Note that applications are unlikely to call getConnection(ConnectionId) explicitly; connections are established/reused automatically whenever sessions enqueue objects/messages for sending to remote machines. The only reason for an application to call this directly, would be if the application wished to establish connections proactively, for example at startup.

Author:
Niall Gallagher

Method Summary
 void bindConnectionListener(ConnectionId localEndpointIdentifier)
          Opens a listener on the local machine to receive inbound connections from other machines to the specified address and port on the local machine.
 Connection getConnection(ConnectionId destinationIdentifier)
          Returns a connection to the destination specified.
 Collection<ConnectionId> getConnectionIds()
          Returns the set of ConnectionIds for the currently open connections.
 Collection<ConnectionId> getConnectionListenerIdentifiers()
          Returns the set of ConnectionIds for the currently bound listeners.
 void unbindConnectionListener(ConnectionId localEndpointIdentifier)
          Closes a listener on the local machine which was previously opened via the bindConnectionListener(ConnectionId) method.
 

Method Detail

getConnection

Connection getConnection(ConnectionId destinationIdentifier)
Returns a connection to the destination specified.

If an inbound connection has previously been received from this destination, returns that connection.

If an outbound connection has previously been established to the destination, returns that connection.

If no connection to the destination currently exists, establishes a new outgoing connection to the destination, and returns the new connection.

The method caches any new connection it creates and will return the same connection again in future. The connection itself will will un-register itself from this cache if it becomes disconnected.

Parameters:
destinationIdentifier - Identifies a remote machine (address and port) to which a connection is required
Returns:
A connection to the remote machine

bindConnectionListener

void bindConnectionListener(ConnectionId localEndpointIdentifier)
Opens a listener on the local machine to receive inbound connections from other machines to the specified address and port on the local machine.

The address supplied could be localhost to receive connections only from other processes on the local machine, or could be the local machine's IP address or host name on its network.

Parameters:
localEndpointIdentifier - Identifies an address and port on the local machine

unbindConnectionListener

void unbindConnectionListener(ConnectionId localEndpointIdentifier)
Closes a listener on the local machine which was previously opened via the bindConnectionListener(ConnectionId) method.

Parameters:
localEndpointIdentifier - The localEndpointIdentifier previously used to bind the connection

getConnectionListenerIdentifiers

Collection<ConnectionId> getConnectionListenerIdentifiers()
Returns the set of ConnectionIds for the currently bound listeners.

Returns:
The set of ConnectionIds for the currently bound listeners

getConnectionIds

Collection<ConnectionId> getConnectionIds()
Returns the set of ConnectionIds for the currently open connections.

Returns:
The set of ConnectionIds for the currently open connections


Copyright © 2016. All rights reserved.