|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.presents.server.PresentsSession
public class PresentsSession
Represents a client session in the server. It is associated with a connection instance (while the client is connected) and acts as the intermediary for the remote client in terms of passing along events forwarded by the client, ensuring that subscriptions are maintained on behalf of the client and that events are forwarded to the client.
A note on synchronization: the client object is structured so that its
Subscriber implementation (which is called from the dobjmgr thread) can proceed
without synchronization. This does not overlap with its other client duties which are called
from the conmgr thread and therefore also need not be synchronized.
| Nested Class Summary | |
|---|---|
protected class |
PresentsSession.ClientProxy
Used to track information about an object subscription. |
protected static class |
PresentsSession.CompoundDispatcher
Processes compound messages. |
protected static class |
PresentsSession.ForwardEventDispatcher
Processes forward event requests. |
protected static class |
PresentsSession.LogoffDispatcher
Processes logoff requests. |
protected static interface |
PresentsSession.MessageDispatcher
Message dispatchers are used to dispatch each different type of message. |
protected static class |
PresentsSession.PingDispatcher
Processes ping requests. |
protected static class |
PresentsSession.SubscribeDispatcher
Processes subscribe requests. |
protected static class |
PresentsSession.ThrottleUpdatedDispatcher
Processes throttle updated messages. |
protected static class |
PresentsSession.TransmitDatagramsDispatcher
Processes datagram transmission requests. |
protected static class |
PresentsSession.UnsubscribeDispatcher
Processes unsubscribe requests. |
static interface |
PresentsSession.UserChangeListener
Used by setUsername(com.threerings.util.Name, com.threerings.presents.server.PresentsSession.UserChangeListener) to report success or failure. |
| Field Summary | |
|---|---|
protected AuthRequest |
_areq
|
protected Object |
_authdata
|
protected Name |
_authname
|
protected ClientManager |
_clmgr
|
protected ClientObject |
_clobj
|
protected CompoundDownstreamMessage |
_compound
Message in which we're currently compounding messages to send, or null if we're sending them straight on. |
protected int |
_compoundDepth
The count of startCompoundMessage calls that have occurred without a finishCompoundMessage. |
protected ConnectionManager |
_conmgr
|
protected PresentsConnection |
_conn
|
protected int |
_connectTime
The total number of seconds for which the user was connected to the server in this session. |
protected HashSet<Integer> |
_destroyedSubs
The Oids of objects that have been destroyed while we were subscribed. |
protected static Map<Class<?>,PresentsSession.MessageDispatcher> |
_disps
A mapping of message dispatchers. |
protected InvocationManager |
_invmgr
|
protected ClassLoader |
_loader
|
protected int |
_messagesDropped
|
protected int |
_messagesIn
|
protected int |
_messagesOut
|
protected int |
_messagesPerSec
The configured throttle setting (resent to reconnecting clients). |
protected long |
_networkStamp
The time at which this client most recently connected or disconnected. |
protected PresentsDObjectMgr |
_omgr
|
protected List<Integer> |
_pendingThrottles
Used to keep throttles around until we know the client is ready for us to apply them. |
protected long |
_sessionStamp
The time at which this client started their session. |
protected IntMap<PresentsSession.ClientProxy> |
_subscrips
|
protected Throttle |
_throttle
Prevent the client from sending too many messages too frequently. |
protected static long |
DEFAULT_FLUSH_TIME
Default period a user is allowed after disconn before their session is forcibly ended. |
protected static boolean |
PING_DEBUG
|
| Constructor Summary | |
|---|---|
PresentsSession()
|
|
| Method Summary | |
|---|---|
boolean |
checkExpired(long now)
Returns true if this session has been disconnected for sufficiently long that it should be forcibly ended. |
protected void |
clearSubscrips(boolean verbose)
Clears out the tracked client subscriptions. |
protected void |
clientObjectDidChange(ClientObject newClobj)
Called after the new client object has been committed to this client due to a call to setUsername(com.threerings.util.Name, com.threerings.presents.server.PresentsSession.UserChangeListener). |
protected void |
clientObjectWillChange(ClientObject oldClobj,
ClientObject newClobj)
Called when setUsername(com.threerings.util.Name, com.threerings.presents.server.PresentsSession.UserChangeListener) has been called and the new client object is about to be
applied to this client. |
void |
clientResolved(Name username,
ClientObject clobj)
Called when resolution completed successfully. |
protected void |
connectionFailed(IOException fault)
Called by the connection manager when this client's connection fails. |
protected BootstrapData |
createBootstrapData()
Derived client classes can override this member to create derived bootstrap data classes that contain extra bootstrap information, if desired. |
protected Throttle |
createIncomingMessageThrottle()
Creates our incoming message throttle. |
protected PresentsSession.ClientProxy |
createProxySubscriber()
Creates a properly initialized inner-class proxy subscriber. |
protected void |
dispatchMessage(Message message)
Processes a message without throttling. |
void |
endSession()
Forcibly terminates a client's session. |
protected void |
finishCompoundMessage()
Sends the compound message created in startCompoundMessage. |
protected void |
finishResumeSession()
This is called from the dobjmgr thread to complete the session resumption. |
Name |
getAuthName()
Returns the username with which this client authenticated. |
ClientObject |
getClientObject()
returns the client object that is associated with this client. |
protected PresentsConnection |
getConnection()
The connection instance must be accessed via this member function because it is read from both the dobjmgr and conmgr threads and is modified by the conmgr thread. |
Credentials |
getCredentials()
Returns the credentials used to authenticate this session. |
protected long |
getFlushTime()
Returns the duration (in milliseconds) after which a disconnected session will be terminated and flushed. |
InetAddress |
getInetAddress()
Returns the address of the connected client or null if this client is not connected. |
long |
getNetworkStamp()
Returns the time at which this client most recently connected or disconnected. |
byte[] |
getSecret()
Returns the shared secret for this session. |
long |
getSessionStamp()
Returns the time at which this client started their network session. |
TimeZone |
getTimeZone()
Returns the time zone in which the client is operating. |
boolean |
getTransmitDatagrams()
Checks whether the client has requested that datagram transmission be enabled. |
void |
handleMessage(Message message)
Called when a complete message has been parsed from incoming network data. |
protected void |
handleThrottleExceeded()
Called when a client exceeds their allotted incoming messages per second throttle. |
protected void |
populateBootstrapData(BootstrapData data)
Derived client classes can override this member to populate the bootstrap data with additional information. |
protected boolean |
postMessage(DownstreamMessage msg,
PresentsConnection expect)
Queues a message for delivery to the client. |
void |
resolutionFailed(Name username,
Exception reason)
Called when resolution fails. |
protected void |
resumeSession(AuthRequest req,
PresentsConnection conn)
Called by the client manager when a new connection arrives that authenticates as this already established client. |
protected void |
safeEndSession()
Queues up a runnable on the object manager thread where we can safely end the session. |
protected void |
safePostMessage(DownstreamMessage msg)
Callable from non-dobjmgr thread, this queues up a runnable on the dobjmgr thread to post the supplied message to this client. |
protected void |
safePostMessage(DownstreamMessage msg,
PresentsConnection expect)
Callable from non-dobjmgr thread, this queues up a runnable on the dobjmgr thread to post the supplied message to this client. |
protected void |
sendBootstrap()
This is called once we have a handle on the client distributed object. |
protected void |
sendThrottleUpdate()
Sends the throttle update to the client. |
protected void |
sessionConnectionClosed()
Called on the dobjmgr thread when the connection associated with this session has been closed and unmapped. |
protected void |
sessionDidEnd()
Called when the client session ends (either because the client logged off or because the server forcibly terminated the session). |
protected void |
sessionWillResume()
Called when the client resumes a session (after having disconnected and reconnected). |
protected void |
sessionWillStart()
Called when the client session is first started. |
void |
setClassLoader(ClassLoader loader)
Configures this session with a custom class loader that will be used when unserializing classes from the network. |
protected void |
setConnection(PresentsConnection conn)
Sets our connection reference in a thread safe way. |
void |
setIncomingMessageThrottle(int messagesPerSec)
Configures the rate at which incoming messages are throttled for this client. |
void |
setUsername(Name username,
PresentsSession.UserChangeListener ucl)
Danger: this method is not for general consumption. |
void |
shutdown()
This is called when the server is shut down in the middle of a client session. |
protected void |
startCompoundMessage()
Collects downstream messages in a compound message until finishCompoundMessage is called. |
protected void |
startSession(Name authname,
AuthRequest req,
PresentsConnection conn,
Object authdata)
Initializes this client instance with the specified username, connection instance and client object and begins a client session. |
protected void |
subscribedToObject(DObject object)
Called to inform derived classes when the client has subscribed to a distributed object. |
protected void |
throttleUpdated()
Notifies this client that its throttle was updated. |
String |
toString()
|
protected void |
toString(StringBuilder buf)
Derived classes override this to augment stringification. |
protected void |
unmapSubscrip(int oid)
Makes a note that this client is no longer subscribed to this object. |
protected void |
unsubscribedFromObject(DObject object)
Called to inform derived classes when the client has unsubscribed from a distributed object. |
boolean |
updateUsername(Name username)
Double Danger: this method is not for general consumption. |
protected void |
wasUnmapped()
Called by the connection manager when this client's connection is unmapped. |
protected String |
who()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
@Inject protected ClientManager _clmgr
@Inject protected ConnectionManager _conmgr
@Inject protected PresentsDObjectMgr _omgr
@Inject protected InvocationManager _invmgr
protected AuthRequest _areq
protected Object _authdata
protected Name _authname
protected PresentsConnection _conn
protected ClientObject _clobj
protected IntMap<PresentsSession.ClientProxy> _subscrips
protected CompoundDownstreamMessage _compound
protected int _compoundDepth
protected HashSet<Integer> _destroyedSubs
protected ClassLoader _loader
protected long _sessionStamp
protected long _networkStamp
protected int _connectTime
protected int _messagesPerSec
protected Throttle _throttle
protected List<Integer> _pendingThrottles
protected int _messagesIn
protected int _messagesOut
protected int _messagesDropped
protected static Map<Class<?>,PresentsSession.MessageDispatcher> _disps
protected static final long DEFAULT_FLUSH_TIME
protected static final boolean PING_DEBUG
| Constructor Detail |
|---|
public PresentsSession()
| Method Detail |
|---|
public Credentials getCredentials()
public TimeZone getTimeZone()
public byte[] getSecret()
public boolean checkExpired(long now)
public long getSessionStamp()
public long getNetworkStamp()
public Name getAuthName()
setUsername(com.threerings.util.Name, com.threerings.presents.server.PresentsSession.UserChangeListener) has
been called this may differ from getClientObject().username.
public InetAddress getInetAddress()
public boolean getTransmitDatagrams()
public void setClassLoader(ClassLoader loader)
public void setIncomingMessageThrottle(int messagesPerSec)
Note: this means that a hacked client can refuse to ACK message rate reductions and continue to use the most generous rate ever assigned to it. Don't increase the throttle beyond the default for untrusted clients. This mechanism exists so that trusted clients can have their throttle relaxed in a robust manner which will not result in disconnects if the client happens to be at or near the throttle limit when the throttle is reduced.
public void setUsername(Name username,
PresentsSession.UserChangeListener ucl)
It exists to support systems wherein a user logs in with an account username and then chooses a "screen name" by which they will play (often from a small set of available "characters" available per account). This will take care of remapping the username to client object mappings that were made by the Presents services when the user logs on, but anything else that has had its grubby mits on the username will be left to its own devices, hence the care that must be exercised when using this method.
ucl - an entity that will (optionally) be notified when the username conversion process
is complete.public boolean updateUsername(Name username)
#setUsername, this changes the username of the client, but unlike setUsername, it
does it in the existing client object. Care must be taken to ensure that any client or
server code either doesn't map things based on username before this call, or that it's
updated to reflect the change.
public ClientObject getClientObject()
public void endSession()
public void shutdown()
endSession() will not be called and so any persistent data
that might normally be flushed at the end of a client's session should likely be flushed
here.
public void clientResolved(Name username,
ClientObject clobj)
ClientResolutionListener
clientResolved in interface ClientResolutionListener
public void resolutionFailed(Name username,
Exception reason)
ClientResolutionListener
resolutionFailed in interface ClientResolutionListenerpublic void handleMessage(Message message)
PresentsConnection.MessageHandler
handleMessage in interface PresentsConnection.MessageHandlerprotected void dispatchMessage(Message message)
protected void clientObjectWillChange(ClientObject oldClobj,
ClientObject newClobj)
setUsername(com.threerings.util.Name, com.threerings.presents.server.PresentsSession.UserChangeListener) has been called and the new client object is about to be
applied to this client. The old client object will not yet have been destroyed, so any final
events can be sent along prior to the new object being put into effect.
protected void clientObjectDidChange(ClientObject newClobj)
setUsername(com.threerings.util.Name, com.threerings.presents.server.PresentsSession.UserChangeListener).
protected void startSession(Name authname,
AuthRequest req,
PresentsConnection conn,
Object authdata)
protected void resumeSession(AuthRequest req,
PresentsConnection conn)
protected void finishResumeSession()
protected void sendThrottleUpdate()
protected void safeEndSession()
protected Throttle createIncomingMessageThrottle()
setIncomingMessageThrottle(int) to adjust the
throttle for running clients.
protected void handleThrottleExceeded()
protected void unmapSubscrip(int oid)
protected void clearSubscrips(boolean verbose)
protected void sessionWillStart()
super.sessionWillStart.
Note: This function will be called on the dobjmgr thread which means that object manipulations are OK, but client instance manipulations must done carefully.
protected void sessionWillResume()
super.sessionWillResume.
Note: This function will be called on the dobjmgr thread which means that object manipulations are OK, but client instance manipulations must done carefully.
protected void sessionDidEnd()
super.sessionDidEnd.
Note: This function will be called on the dobjmgr thread which means that object manipulations are OK, but client instance manipulations must done carefully.
protected void subscribedToObject(DObject object)
protected void unsubscribedFromObject(DObject object)
protected void sendBootstrap()
protected BootstrapData createBootstrapData()
protected void populateBootstrapData(BootstrapData data)
super.populateBootstrapData
before doing their own populating, however.
Note: This function will be called on the dobjmgr thread which means that object manipulations are OK, but client instance manipulations must be done carefully.
protected void wasUnmapped()
connectionFailed) or it may be because of an orderly closing of the
connection. In either case, the client can deal with its lack of a connection in this
method. This is invoked by the conmgr thread and should behave accordingly.
protected void sessionConnectionClosed()
sessionDidEnd().
protected void connectionFailed(IOException fault)
protected void setConnection(PresentsConnection conn)
protected PresentsConnection getConnection()
protected final void safePostMessage(DownstreamMessage msg)
protected final void safePostMessage(DownstreamMessage msg,
PresentsConnection expect)
protected void startCompoundMessage()
protected void finishCompoundMessage()
protected boolean postMessage(DownstreamMessage msg,
PresentsConnection expect)
protected void throttleUpdated()
public String toString()
toString in class Objectprotected String who()
protected long getFlushTime()
protected void toString(StringBuilder buf)
protected PresentsSession.ClientProxy createProxySubscriber()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||