com.googlecode.mobilityrpc.controller.impl
Class MobilityControllerImpl

java.lang.Object
  extended by com.googlecode.mobilityrpc.controller.impl.MobilityControllerImpl
All Implemented Interfaces:
Destroyable, MobilityControllerInternal, MobilityController, IncomingMessageHandler, OutgoingMessageHandler

public class MobilityControllerImpl
extends Object
implements MobilityControllerInternal

Author:
Niall Gallagher

Constructor Summary
MobilityControllerImpl()
           
 
Method Summary
 void destroy()
          Calls destroy() on the connection controller, which will unbind all connection listeners, disconnect all open connections and shut down the threads which were managing connections.
 ConnectionManager getConnectionManager()
          Returns the ConnectionManager which manages connections for this controller.
 MobilitySessionInternal getMessageHandlingSession(UUID sessionId)
           
 MobilitySession getSession(UUID sessionId)
          Returns the existing session with the specified id, or if no such session with the id exists, (re)creates a new session with the same id and adds it to the session registry.
 MobilitySession newSession()
          Creates a new session, with a newly generated UUID, and adds it to the session registry.
 void receiveIncomingMessage(ConnectionId connectionId, byte[] message)
          Supplies the message to the handler for it to be processed.
 void releaseSession(UUID sessionId)
          Releases the given session immediately, if it is registered.
 void sendOutgoingMessage(ConnectionId identifier, Object message)
          Serializes the supplied message object and submits it to the outgoing message queue of the connection indicated, such that it will be sent to the machine at the other end of the connection for processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MobilityControllerImpl

public MobilityControllerImpl()
Method Detail

receiveIncomingMessage

public void receiveIncomingMessage(ConnectionId connectionId,
                                   byte[] message)
Description copied from interface: IncomingMessageHandler
Supplies the message to the handler for it to be processed.

Specified by:
receiveIncomingMessage in interface IncomingMessageHandler
Parameters:
connectionId - Identifies the connection from which the message was received
message - The message to supply

sendOutgoingMessage

public void sendOutgoingMessage(ConnectionId identifier,
                                Object message)
Description copied from interface: OutgoingMessageHandler
Serializes the supplied message object and submits it to the outgoing message queue of the connection indicated, such that it will be sent to the machine at the other end of the connection for processing.

The object supplied must be an instance of one of the Java protocol message representations from the com.googlecode.mobilityrpc.protocol.pojo package, such that it can be serialized to its protobuf counterpart representation.

The object supplied will be serialized to protobuf format synchronously inside this method, by the thread calling this method. The method will only then submit the message in protobuf format to the connection's outgoing message queue, where it will be sent asynchronously.

As such if the object supplied cannot be serialized to protobuf format, this method will throw an exception to the code calling this method. This method does not block.

Specified by:
sendOutgoingMessage in interface OutgoingMessageHandler
Parameters:
identifier - Identifies the connection through which the message should be sent
message - A java object representation of a protocol message

getConnectionManager

public ConnectionManager getConnectionManager()
Description copied from interface: MobilityController
Returns the ConnectionManager which manages connections for this controller.

Specified by:
getConnectionManager in interface MobilityController
Returns:
The ConnectionManager which manages connections for this controller

destroy

public void destroy()
Calls destroy() on the connection controller, which will unbind all connection listeners, disconnect all open connections and shut down the threads which were managing connections.

Specified by:
destroy in interface Destroyable
Specified by:
destroy in interface MobilityController

getSession

public MobilitySession getSession(UUID sessionId)
Description copied from interface: MobilityController
Returns the existing session with the specified id, or if no such session with the id exists, (re)creates a new session with the same id and adds it to the session registry.

Specified by:
getSession in interface MobilityController
Parameters:
sessionId - The session id of the session to return
Returns:
The existing session with the specified id, or a new session initialised with this same id

newSession

public MobilitySession newSession()
Description copied from interface: MobilityController
Creates a new session, with a newly generated UUID, and adds it to the session registry.

Specified by:
newSession in interface MobilityController
Returns:
A new session

releaseSession

public void releaseSession(UUID sessionId)
Description copied from interface: MobilityController
Releases the given session immediately, if it is registered. If not registered, does nothing.

Note: the preferred way to release a session is via MobilitySession.release(), which includes logic to gracefully release sessions after threads which are using them have finished. This method would release sessions while they are in use, which could cause errors for requests executing in those sessions.

Specified by:
releaseSession in interface MobilityController
Parameters:
sessionId - The session id to release

getMessageHandlingSession

public MobilitySessionInternal getMessageHandlingSession(UUID sessionId)
Specified by:
getMessageHandlingSession in interface MobilityControllerInternal


Copyright © 2012. All Rights Reserved.