org.jdesktop.wonderland.client.comms
Class WonderlandSessionImpl

java.lang.Object
  extended by org.jdesktop.wonderland.client.comms.WonderlandSessionImpl
All Implemented Interfaces:
WonderlandSession
Direct Known Subclasses:
CellClientSession

public class WonderlandSessionImpl
extends java.lang.Object
implements WonderlandSession

This class provides an extensible base for clients that want to connect to a Wonderland server. The base client handles logging in to the server, selecting a protocol using the Wonderland protocol selection mechanism, sending data to the server, as well as a listener framework for channel join/leave and messages from the server.

Extensions of this listener provide protocol-specific services. The ClientConnection is the main client used by the Wonderland 3D application.

Author:
kaplanj

Nested Class Summary
protected  class WonderlandSessionImpl.ClientRecord
          The record for an connected client
protected static class WonderlandSessionImpl.SessionInternalHandler
          Handle traffic over the session channel
 
Nested classes/interfaces inherited from interface org.jdesktop.wonderland.client.comms.WonderlandSession
WonderlandSession.Status
 
Constructor Summary
WonderlandSessionImpl(ServerSessionManager sessionManager, WonderlandServerInfo server)
          Create a new client to log in to the given server
WonderlandSessionImpl(ServerSessionManager sessionManager, WonderlandServerInfo server, java.lang.ClassLoader classLoader)
          Create a new client to log in to the given server.
 
Method Summary
protected  WonderlandSessionImpl.ClientRecord addClientRecord(ClientConnection client)
          Add a client record to the map
 void addSessionStatusListener(SessionStatusListener listener)
          Add a listener that will be notified when the status of this session changes.
 void connect(ClientConnection client)
          Connect a new client to this session, with no properties.
 void connect(ClientConnection client, java.util.Properties properties)
          Connect a new client to this session.
 void disconnect(ClientConnection client)
          Disconnect a previously connected client from this session.
protected  void fireClientStatusChanged(WonderlandSession.Status status)
          Notify any registered status listeners of a status change
protected  void fireSessionMessageReceived(java.nio.ByteBuffer data)
          Fire when a message is received over the session channel
protected  java.lang.ClassLoader getClassLoader()
          Get the classloader to use while deserializing received messages
protected  WonderlandSessionImpl.ClientRecord getClientRecord(ClientConnection client)
          Get the client record for a given client
protected  WonderlandSessionImpl.ClientRecord getClientRecord(ConnectionType type)
          Get the client record for a given client
protected  WonderlandSessionImpl.ClientRecord getClientRecord(short clientID)
          Get the client record with the given id
 ClientConnection getConnection(ConnectionType type)
          Get the connected ClientConnection for the given ConnectionType.
<T extends ClientConnection>
T
getConnection(ConnectionType type, java.lang.Class<T> clazz)
          Get the attched ClientConnection for the given ConnectionType.
 java.util.Collection<ClientConnection> getConnections()
          Get all clients connected to this session
 java.math.BigInteger getID()
          Get the ID of this session.
protected  WonderlandSessionImpl.SessionInternalHandler getInternalClient()
          Get the default client for handling traffic over the session channel
protected  java.lang.String getName()
          Get a user-printable name for this session
protected  java.lang.String getProtocolName()
          Get the name of the protocol to connect with
protected  ProtocolVersion getProtocolVersion()
          Get the version of the protocol to connect with
 WonderlandServerInfo getServerInfo()
          Get the server this client is connected to
 ServerSessionManager getSessionManager()
          Get the session manager that handles login for this session.
 com.sun.sgs.client.simple.SimpleClient getSimpleClient()
          Get the simple client connected to the Darkstar server.
 WonderlandSession.Status getStatus()
          Get the status of this client.
 WonderlandIdentity getUserID()
          Get the user ID associated with this session.
 void login(LoginParameters loginParams)
          Log in to the server.
 void logout()
          Logout from the server.
protected  WonderlandSessionImpl.ClientRecord removeClientRecord(ClientConnection client)
          Remove a client record
 void removeSessionStatusListener(SessionStatusListener listener)
          Remove a listener that will be notified when the status of this session changes.
 void send(ClientConnection client, Message message)
          Send a message to the server over the session channel on behalf of the given client.
protected  void setClientID(WonderlandSessionImpl.ClientRecord record, short clientID)
          Set the client id of a given client
protected  void setStatus(WonderlandSession.Status status)
          Set the status of this client.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WonderlandSessionImpl

public WonderlandSessionImpl(ServerSessionManager sessionManager,
                             WonderlandServerInfo server)
Create a new client to log in to the given server

Parameters:
sessionManager - the session manager that created this session
server - the server to connect to

WonderlandSessionImpl

public WonderlandSessionImpl(ServerSessionManager sessionManager,
                             WonderlandServerInfo server,
                             java.lang.ClassLoader classLoader)
Create a new client to log in to the given server. Use the provided classloader to resolve the class of any messages that are received.

Parameters:
sessionManager - the session manager that created this session
server - the server to connect to
classloader - the classloader to resolve messages with, or null to use the system classloader.
Method Detail

getSessionManager

public ServerSessionManager getSessionManager()
Description copied from interface: WonderlandSession
Get the session manager that handles login for this session.

Specified by:
getSessionManager in interface WonderlandSession
Returns:
the session manager

getServerInfo

public WonderlandServerInfo getServerInfo()
Description copied from interface: WonderlandSession
Get the server this client is connected to

Specified by:
getServerInfo in interface WonderlandSession
Returns:
the server

getStatus

public WonderlandSession.Status getStatus()
Description copied from interface: WonderlandSession
Get the status of this client.

Specified by:
getStatus in interface WonderlandSession
Returns:
the current status of the client

setStatus

protected void setStatus(WonderlandSession.Status status)
Set the status of this client.

Parameters:
status - the current status of the client

getSimpleClient

public com.sun.sgs.client.simple.SimpleClient getSimpleClient()
Description copied from interface: WonderlandSession
Get the simple client connected to the Darkstar server. This will only be valid after the login method succeeds.

Specified by:
getSimpleClient in interface WonderlandSession
Returns:
the darkstar client

login

public void login(LoginParameters loginParams)
           throws LoginFailureException
Description copied from interface: WonderlandSession
Log in to the server. This will connect to the given server, and wait for the login to succeed. If the login succeeds, negotiate a protocol using the Wonderland protocol negotiation mechanism. This method blocks until both the login and protocol selection have been verified by the server.

If this method returns normally, then the login and protocol selection succeeded. If it throws a LoginFailureException, the login has failed.

Specified by:
login in interface WonderlandSession
Parameters:
loginParams - the parameters required for login
Throws:
LoginFailureException - if the login fails

logout

public void logout()
Description copied from interface: WonderlandSession
Logout from the server.

Specified by:
logout in interface WonderlandSession

getID

public java.math.BigInteger getID()
Description copied from interface: WonderlandSession
Get the ID of this session. The ID is a unique identifier for this particular session that is globally unique across all sessions attached to the same server.

The ID is only valid when the client status is CONNECTED. Attempting to read the ID when the status is anything else will cause an IllegalStateException.

The ID is generated on the server and communicated as part of the login process. It is available at the time that the client is notified of the state change.

Specified by:
getID in interface WonderlandSession

getUserID

public WonderlandIdentity getUserID()
Description copied from interface: WonderlandSession
Get the user ID associated with this session. This ID is maintained byt the server based on the user's login credentials.

The ID is generated on the server and communicated as part of the login process. It is available at the time that the client is notified of the state change.

Specified by:
getUserID in interface WonderlandSession

connect

public void connect(ClientConnection client)
             throws ConnectionFailureException
Description copied from interface: WonderlandSession
Connect a new client to this session, with no properties. This is identical to calling connect(client, null).

Specified by:
connect in interface WonderlandSession
Parameters:
client - the client to connect
Throws:
ConnectionFailureException - of the connection fails
See Also:
connect(ClientConnect, Properties)

connect

public void connect(ClientConnection client,
                    java.util.Properties properties)
             throws ConnectionFailureException
Description copied from interface: WonderlandSession
Connect a new client to this session. When a client is connected to this session, it will interact with the server associated with this session.

Only one client of any given ConnectionType may be connected to the server at any time. Attempting to connect a second client of the same type will result in an ConnectionFailureException.

Clients may only be connected when a session is in the DISCONNECTED state. If the session is in any other state, an ConnectionFailureException will be thrown. When a session disconnects, all clients are disconnected, and must be re-connected to start working again.

A client may optionally specify properties to use when making the given connection. If properties are specified, the client will send the properties to the server, where they will be available in the ClientConnectionManager.clientConnected(). If null is passed in for the properties argument, and empty properties will be sent to the server.

Specified by:
connect in interface WonderlandSession
Parameters:
client - the client to connect
properties - the properties object to send to the server
Throws:
ConnectionFailureException - of the connection fails

getConnection

public ClientConnection getConnection(ConnectionType type)
Description copied from interface: WonderlandSession
Get the connected ClientConnection for the given ConnectionType.

Specified by:
getConnection in interface WonderlandSession
Parameters:
type - the client type to get
Returns:
the connected client for the given type, or null if no client of the given type is connected

getConnection

public <T extends ClientConnection> T getConnection(ConnectionType type,
                                                    java.lang.Class<T> clazz)
Description copied from interface: WonderlandSession
Get the attched ClientConnection for the given ConnectionType.

Specified by:
getConnection in interface WonderlandSession
Parameters:
type - the client type to get
clazz - the class of client to return
Returns:
the connected client for the given type, or null if no client of the given type is connected

getConnections

public java.util.Collection<ClientConnection> getConnections()
Description copied from interface: WonderlandSession
Get all clients connected to this session

Specified by:
getConnections in interface WonderlandSession
Returns:
the clients connected to this session

disconnect

public void disconnect(ClientConnection client)
Description copied from interface: WonderlandSession
Disconnect a previously connected client from this session.

Specified by:
disconnect in interface WonderlandSession
Parameters:
client - the client to logout

send

public void send(ClientConnection client,
                 Message message)
Description copied from interface: WonderlandSession
Send a message to the server over the session channel on behalf of the given client. The client must be successfully connected to this session in order for the send to work.

Specified by:
send in interface WonderlandSession
Parameters:
client - the client that is sending the message
message - the message to send

addSessionStatusListener

public void addSessionStatusListener(SessionStatusListener listener)
Description copied from interface: WonderlandSession
Add a listener that will be notified when the status of this session changes.

Specified by:
addSessionStatusListener in interface WonderlandSession
Parameters:
listener - the listener to add

removeSessionStatusListener

public void removeSessionStatusListener(SessionStatusListener listener)
Description copied from interface: WonderlandSession
Remove a listener that will be notified when the status of this session changes.

Specified by:
removeSessionStatusListener in interface WonderlandSession
Parameters:
listener - the listener to remove

fireSessionMessageReceived

protected void fireSessionMessageReceived(java.nio.ByteBuffer data)
Fire when a message is received over the session channel

Parameters:
data - the message that was received

fireClientStatusChanged

protected void fireClientStatusChanged(WonderlandSession.Status status)
Notify any registered status listeners of a status change

Parameters:
session - the session that changed
status - the new status

getProtocolName

protected java.lang.String getProtocolName()
Get the name of the protocol to connect with

Returns:
the name of the protocol to connect with

getProtocolVersion

protected ProtocolVersion getProtocolVersion()
Get the version of the protocol to connect with

Returns:
the version of the protocol to connect with

getClassLoader

protected java.lang.ClassLoader getClassLoader()
Get the classloader to use while deserializing received messages

Returns:
the deserialization classloader

getInternalClient

protected WonderlandSessionImpl.SessionInternalHandler getInternalClient()
Get the default client for handling traffic over the session channel

Returns:
the default client

addClientRecord

protected WonderlandSessionImpl.ClientRecord addClientRecord(ClientConnection client)
Add a client record to the map

Parameters:
client - the client to add a record for
Returns:
the newly added record

setClientID

protected void setClientID(WonderlandSessionImpl.ClientRecord record,
                           short clientID)
Set the client id of a given client

Parameters:
record - the record to set the id for
clientID - the id to set

getClientRecord

protected WonderlandSessionImpl.ClientRecord getClientRecord(ClientConnection client)
Get the client record for a given client

Parameters:
client - the client to get a record for
Returns:
the ClientRecord for the given client, or null if the given client is not connected to this session

getClientRecord

protected WonderlandSessionImpl.ClientRecord getClientRecord(ConnectionType type)
Get the client record for a given client

Parameters:
type - the type of client to get a record for
Returns:
the ClientRecord for the given client, or null if the given client is not connected to this session

getClientRecord

protected WonderlandSessionImpl.ClientRecord getClientRecord(short clientID)
Get the client record with the given id

Parameters:
clientID - the client to get a record for
Returns:
the ClientRecord for the given client, or null if the given client is not connected to this session

removeClientRecord

protected WonderlandSessionImpl.ClientRecord removeClientRecord(ClientConnection client)
Remove a client record

Parameters:
client - the client to remove a record for
Returns:
the client record that was removed, or null if no record was removed

getName

protected java.lang.String getName()
Get a user-printable name for this session

Returns:
a name for this session

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Open Wonderland - http://openwonderland.org