|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.presents.server.ClientManager
public class ClientManager
The client manager is responsible for managing client sessions which are slightly more than just connections. Clients persist in the absence of connections in case a user goes bye bye unintentionally and wants to reconnect and continue their session.
The client manager operates with thread safety because it is called both from the conmgr thread (to notify of connections showing up or going away) and from the dobjmgr thread (when clients are given the boot for application-defined reasons).
| Nested Class Summary | |
|---|---|
static interface |
ClientManager.ClientObserver
Used by entities that wish to track when clients initiate and end sessions on this server. |
static interface |
ClientManager.ClientOp
Used by applyToClient(com.threerings.util.Name, com.threerings.presents.server.ClientManager.ClientOp). |
static interface |
ClientManager.DetailedClientObserver
Methods for observing additional events in the session lifecycle. |
| Field Summary | |
|---|---|
protected ObserverList<ClientManager.ClientObserver> |
_clobservers
Tracks registered ClientManager.ClientObservers. |
protected Map<Connection,PresentsSession> |
_conmap
A mapping from connections to session instances. |
protected ObserverList<ClientManager.DetailedClientObserver> |
_dclobservers
Tracks registered ClientManager.DetailedClientObservers. |
protected List<SessionFactory> |
_factories
Lets us know what sort of session classes to use. |
protected com.google.inject.Injector |
_injector
Used to resolve dependencies in PresentsSession instances that we create. |
protected Map<Name,ClientObject> |
_objmap
A mapping from usernames to client object instances. |
protected PresentsDObjectMgr |
_omgr
|
protected Map<Name,ClientResolver> |
_penders
A mapping of pending client resolvers. |
protected Map<Name,PresentsSession> |
_usermap
A mapping from auth username to session instances. |
protected static long |
SESSION_FLUSH_INTERVAL
The frequency with which we check for expired sessions. |
| Constructor Summary | |
|---|---|
ClientManager(ReportManager repmgr,
Lifecycle cycle)
Constructs a client manager that will interact with the supplied connection manager. |
|
| Method Summary | |
|---|---|
void |
addClientObserver(ClientManager.ClientObserver observer)
Registers an observer that will be notified when clients start and end their sessions. |
void |
addSessionFactory(SessionFactory factory)
Adds a session factory to the chain. |
void |
appendReport(StringBuilder report,
long now,
long sinceLast,
boolean reset)
Requests that this reporter append its report to the supplied string buffer. |
void |
applyToClient(Name username,
ClientManager.ClientOp clop)
Resolves the specified client, applies the supplied client operation to them and releases the client. |
protected void |
clearSession(PresentsSession session)
Called by PresentsSession to let us know that we can clear it entirely out of the system. |
Iterable<ClientObject> |
clientObjects()
Returns an iterable over all active client objects. |
void |
clientResolved(Name username,
ClientObject clobj)
Called when resolution completed successfully. |
protected void |
clientSessionDidEnd(PresentsSession session)
Called by PresentsSession when it has ended its session. |
protected void |
clientSessionDidStart(PresentsSession session)
Called by PresentsSession when it has started its session. |
protected void |
clientSessionWillEnd(PresentsSession session)
Called by PresentsSession when it is about to end its session. |
void |
connectionClosed(Connection conn)
Called by the connection manager to let us know when a connection has been closed. |
void |
connectionEstablished(PresentsConnection conn,
Name authname,
AuthRequest req,
AuthResponse rsp)
Called by the connection manager to let us know when a new connection has been established. |
void |
connectionFailed(Connection conn,
IOException fault)
Called by the connection manager to let us know when a connection has failed. |
Iterator<ClientObject> |
enumerateClientObjects()
Enumerates all active client objects. |
protected void |
flushSessions()
Called once per minute to check for sessions that have been disconnected too long and forcibly end their sessions. |
PresentsSession |
getClient(Name authUsername)
Returns the client instance that manages the client session for the specified authentication username or null if that client is not currently connected to the server. |
int |
getClientCount()
Returns the number of client sessions (some may be disconnected). |
ClientObject |
getClientObject(Name username)
Returns the client object associated with the specified username. |
int |
getConnectionCount()
Returns the number of connected clients. |
int |
getOutstandingResolutionCount()
Return the number of client resolutions are currently happening. |
List<PresentsSession> |
getSessionsForAddress(byte[] addr)
Returns all sessions logged in from the given IP in the form returned from InetAddress.getAddress(). |
void |
init()
|
void |
releaseClientObject(Name username)
Releases a client object that was obtained via a call to resolveClientObject(com.threerings.util.Name, com.threerings.presents.server.ClientResolutionListener). |
void |
removeClientObserver(ClientManager.ClientObserver observer)
Removes an observer previously registered with addClientObserver(com.threerings.presents.server.ClientManager.ClientObserver). |
protected boolean |
renameClientObject(Name oldname,
Name newname)
Renames a currently connected client from oldname to newname. |
void |
resolutionFailed(Name username,
Exception reason)
Called when resolution fails. |
void |
resolveClientObject(Name username,
ClientResolutionListener listener)
Requests that the client object for the specified user be resolved. |
void |
setDefaultSessionFactory(SessionFactory factory)
Configures the default factory for creating PresentsSession and ClientResolver classes for authenticated client connections. |
void |
setInjector(com.google.inject.Injector injector)
Configures the injector we'll use to resolve dependencies for PresentsSession
instances. |
void |
shutdown()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected com.google.inject.Injector _injector
PresentsSession instances that we create.
protected Map<Name,PresentsSession> _usermap
protected Map<Connection,PresentsSession> _conmap
protected Map<Name,ClientObject> _objmap
protected Map<Name,ClientResolver> _penders
protected List<SessionFactory> _factories
protected ObserverList<ClientManager.ClientObserver> _clobservers
ClientManager.ClientObservers.
protected ObserverList<ClientManager.DetailedClientObserver> _dclobservers
ClientManager.DetailedClientObservers.
@Inject protected PresentsDObjectMgr _omgr
protected static final long SESSION_FLUSH_INTERVAL
| Constructor Detail |
|---|
@Inject
public ClientManager(ReportManager repmgr,
Lifecycle cycle)
| Method Detail |
|---|
public void setInjector(com.google.inject.Injector injector)
PresentsSession
instances.
public void setDefaultSessionFactory(SessionFactory factory)
PresentsSession and ClientResolver classes for authenticated client connections. All factories added via addSessionFactory(com.threerings.presents.server.SessionFactory) will be offered a chance to handle sessions before this factory of last
resort.
public void addSessionFactory(SessionFactory factory)
public int getOutstandingResolutionCount()
public int getClientCount()
public List<PresentsSession> getSessionsForAddress(byte[] addr)
InetAddress.getAddress().
public int getConnectionCount()
public Iterable<ClientObject> clientObjects()
public Iterator<ClientObject> enumerateClientObjects()
public void addClientObserver(ClientManager.ClientObserver observer)
public void removeClientObserver(ClientManager.ClientObserver observer)
addClientObserver(com.threerings.presents.server.ClientManager.ClientObserver).
public PresentsSession getClient(Name authUsername)
public ClientObject getClientObject(Name username)
public void applyToClient(Name username,
ClientManager.ClientOp clop)
public void resolveClientObject(Name username,
ClientResolutionListener listener)
releaseClientObject(com.threerings.util.Name) when the caller is
finished with the client object.
public void releaseClientObject(Name username)
resolveClientObject(com.threerings.util.Name, com.threerings.presents.server.ClientResolutionListener). If
this caller is the last reference, the object will be flushed and destroyed.
public void init()
init in interface Lifecycle.InitComponentpublic void shutdown()
shutdown in interface Lifecycle.ShutdownComponent
protected boolean renameClientObject(Name oldname,
Name newname)
oldname to newname.
public void clientResolved(Name username,
ClientObject clobj)
ClientResolutionListener
clientResolved in interface ClientResolutionListener
public void resolutionFailed(Name username,
Exception reason)
ClientResolutionListener
resolutionFailed in interface ClientResolutionListener
public void connectionEstablished(PresentsConnection conn,
Name authname,
AuthRequest req,
AuthResponse rsp)
public void connectionFailed(Connection conn,
IOException fault)
public void connectionClosed(Connection conn)
public void appendReport(StringBuilder report,
long now,
long sinceLast,
boolean reset)
ReportManager.Reporter
appendReport in interface ReportManager.Reporterreport - the string buffer to which the report text should be appended.now - the time at which the report generation began, in epoch millis.sinceLast - number of milliseconds since the last time we generated a report.reset - if true, all accumulating stats should be reset, if false they should be
allowed to continue to accumulate.protected void clientSessionDidStart(PresentsSession session)
protected void clientSessionWillEnd(PresentsSession session)
protected void clientSessionDidEnd(PresentsSession session)
protected void clearSession(PresentsSession session)
protected void flushSessions()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||