org.jdesktop.wonderland.server.comms
Class ProtocolSessionListener

java.lang.Object
  extended by org.jdesktop.wonderland.server.comms.ProtocolSessionListener
All Implemented Interfaces:
com.sun.sgs.app.ClientSessionListener, java.io.Serializable

public class ProtocolSessionListener
extends java.lang.Object
implements com.sun.sgs.app.ClientSessionListener, java.io.Serializable

This core session listener implements the basic Wonderland protocol selection mechanism. When a new client connects, they request a protcol using a ProtocolSelectionMessage. This listener handles the protcol selection message, either by sending an error or instantiating the listener associated with the given protocol type.

Once the session type has been successfully selected, this listener simply acts as a wrapper, passing all request on to the delegated listener.

TODO: these messages should be defined in binary and not as Java objects to allow connections from non-Java clients.

Author:
jkaplan
See Also:
Serialized Form

Nested Class Summary
protected static class ProtocolSessionListener.ProtocolClientMap
          A record of clients connected with the given protocol
 
Constructor Summary
ProtocolSessionListener(com.sun.sgs.app.ClientSession session)
          Create a new instance of WonderlandSessionListener for the given session
 
Method Summary
 void disconnected(boolean forced)
          Called when the delegate session is disconnected
static java.util.Set<com.sun.sgs.app.ClientSession> getClients(CommunicationsProtocol protocol)
          Get all clients using the given protocol
static CommunicationsProtocol getProtocol(com.sun.sgs.app.ClientSession session)
          Get the protocol in use by the given client
protected static ProtocolSessionListener.ProtocolClientMap getProtocolClientMap()
          Get the protocol client map, which maps from protocols to clients using that protocol
protected  com.sun.sgs.app.ClientSession getSession()
          Get the session this listener represents.
static void initialize()
          Initialize the session listener
 void receivedMessage(java.nio.ByteBuffer data)
          Called when the listener receives a message.
protected  void recordConnect(CommunicationsProtocol protocol, com.sun.sgs.app.ClientSession session)
          Record a client of the given type connecting
protected  void recordDisconnect(CommunicationsProtocol protocol, com.sun.sgs.app.ManagedReference<com.sun.sgs.app.ClientSession> sessionRef)
          Record a client of the given type disconnecting
protected  void sendError(MessageID messageID, java.lang.String error, java.lang.Throwable cause)
          Send an error to the session
protected  void sendError(Message source, java.lang.String error)
          Send an error to the session
protected  void sendToSession(Message message)
          Send a message to the session
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProtocolSessionListener

public ProtocolSessionListener(com.sun.sgs.app.ClientSession session)
Create a new instance of WonderlandSessionListener for the given session

Parameters:
session - the session connected to this listener
Method Detail

initialize

public static void initialize()
Initialize the session listener


receivedMessage

public void receivedMessage(java.nio.ByteBuffer data)
Called when the listener receives a message. If the wrapped session has not yet been defined, look for ProtocolSelectionMessages, otherwise simply forward the data to the delegate session

Specified by:
receivedMessage in interface com.sun.sgs.app.ClientSessionListener
Parameters:
data - the message data

disconnected

public void disconnected(boolean forced)
Called when the delegate session is disconnected

Specified by:
disconnected in interface com.sun.sgs.app.ClientSessionListener
Parameters:
forced - true if the disconnect was forced

getClients

public static java.util.Set<com.sun.sgs.app.ClientSession> getClients(CommunicationsProtocol protocol)
Get all clients using the given protocol

Parameters:
protocol - the protocol to get clients for
Returns:
a set of all clients connected with that protocol, or null if no clients are connected via the protocol

getProtocol

public static CommunicationsProtocol getProtocol(com.sun.sgs.app.ClientSession session)
Get the protocol in use by the given client

Parameters:
session - the session to get protocol information for
Returns:
the protocol used by that client, or null if the client is not registered

getSession

protected com.sun.sgs.app.ClientSession getSession()
Get the session this listener represents.

Returns:
the session connected to this listener

sendError

protected void sendError(Message source,
                         java.lang.String error)
Send an error to the session

Parameters:
message - the source message
error - the error to send

sendError

protected void sendError(MessageID messageID,
                         java.lang.String error,
                         java.lang.Throwable cause)
Send an error to the session

Parameters:
messageID - the messageID of the original error
error - the error message
cause - the underlying exception

sendToSession

protected void sendToSession(Message message)
Send a message to the session

Parameters:
message - the message to send

recordConnect

protected void recordConnect(CommunicationsProtocol protocol,
                             com.sun.sgs.app.ClientSession session)
Record a client of the given type connecting

Parameters:
protocol - the protocol the session connected with
session - the session that connected

recordDisconnect

protected void recordDisconnect(CommunicationsProtocol protocol,
                                com.sun.sgs.app.ManagedReference<com.sun.sgs.app.ClientSession> sessionRef)
Record a client of the given type disconnecting

Parameters:
protocol - the protocol the session connected with
sessionRef - a reference to the session that connected

getProtocolClientMap

protected static ProtocolSessionListener.ProtocolClientMap getProtocolClientMap()
Get the protocol client map, which maps from protocols to clients using that protocol

Returns:
the ProtocolClientMap


Open Wonderland - http://openwonderland.org