com.googlecode.mobilityrpc.network.impl
Class ConnectionManagerImpl

java.lang.Object
  extended by com.googlecode.mobilityrpc.network.impl.ConnectionManagerImpl
All Implemented Interfaces:
Destroyable, Initializable, Managed, ConnectionManager, ConnectionManagerInternal, ConnectionStateListener

public class ConnectionManagerImpl
extends Object
implements ConnectionManagerInternal, ConnectionStateListener

Author:
Niall Gallagher

Constructor Summary
ConnectionManagerImpl(MobilityControllerImpl mobilityController)
           
 
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.
 void destroy()
          Destroys (closes/shuts down) the resource(s) managed by the object, closing connections, stopping threads etc.
 Connection getConnection(ConnectionId identifier)
          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 init()
          Does nothing in the current implementation.
 boolean isConnectionRegistered(ConnectionId connectionId)
           
 void notifyConnectionClosed(ConnectionInternal connection)
          Called when the supplied connection has been closed.
 void notifyConnectionOpened(ConnectionInternal connection)
          Called when the supplied connection has been opened.
 void unbindConnectionListener(ConnectionId localEndpointIdentifier)
          Closes a listener on the local machine which was previously opened via the ConnectionManager.bindConnectionListener(ConnectionId) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionManagerImpl

public ConnectionManagerImpl(MobilityControllerImpl mobilityController)
Method Detail

getConnection

public Connection getConnection(ConnectionId identifier)
Description copied from interface: ConnectionManager
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.

Specified by:
getConnection in interface ConnectionManager
Parameters:
identifier - Identifies a remote machine (address and port) to which a connection is required
Returns:
A connection to the remote machine

notifyConnectionOpened

public void notifyConnectionOpened(ConnectionInternal connection)
Description copied from interface: ConnectionStateListener
Called when the supplied connection has been opened.

Specified by:
notifyConnectionOpened in interface ConnectionStateListener
Parameters:
connection - The connection which has been opened

notifyConnectionClosed

public void notifyConnectionClosed(ConnectionInternal connection)
Description copied from interface: ConnectionStateListener
Called when the supplied connection has been closed.

Specified by:
notifyConnectionClosed in interface ConnectionStateListener
Parameters:
connection - The connection which has been closed

isConnectionRegistered

public boolean isConnectionRegistered(ConnectionId connectionId)
Specified by:
isConnectionRegistered in interface ConnectionStateListener
Parameters:
connectionId - The connection id to check
Returns:
Allows the sender of notifications to query the destination to see if a specific connection is registered (typically used to check if primary connection is up)

bindConnectionListener

public void bindConnectionListener(ConnectionId localEndpointIdentifier)
Description copied from interface: ConnectionManager
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.

Specified by:
bindConnectionListener in interface ConnectionManager
Parameters:
localEndpointIdentifier - Identifies an address and port on the local machine

unbindConnectionListener

public void unbindConnectionListener(ConnectionId localEndpointIdentifier)
Description copied from interface: ConnectionManager
Closes a listener on the local machine which was previously opened via the ConnectionManager.bindConnectionListener(ConnectionId) method.

Specified by:
unbindConnectionListener in interface ConnectionManager
Parameters:
localEndpointIdentifier - The localEndpointIdentifier previously used to bind the connection

getConnectionListenerIdentifiers

public Collection<ConnectionId> getConnectionListenerIdentifiers()
Description copied from interface: ConnectionManager
Returns the set of ConnectionIds for the currently bound listeners.

Specified by:
getConnectionListenerIdentifiers in interface ConnectionManager
Returns:
The set of ConnectionIds for the currently bound listeners

getConnectionIds

public Collection<ConnectionId> getConnectionIds()
Description copied from interface: ConnectionManager
Returns the set of ConnectionIds for the currently open connections.

Specified by:
getConnectionIds in interface ConnectionManager
Returns:
The set of ConnectionIds for the currently open connections

init

public void init()
Does nothing in the current implementation.

Specified by:
init in interface Initializable

destroy

public void destroy()
Description copied from interface: Destroyable
Destroys (closes/shuts down) the resource(s) managed by the object, closing connections, stopping threads etc. as necessary.

Specified by:
destroy in interface Destroyable


Copyright © 2016. All rights reserved.