PresentsClient -> PresentsSession (Jamie's suggestion) and associated changes
on down the client. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5508 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -26,15 +26,15 @@ import com.threerings.util.Name;
|
||||
import com.threerings.presents.net.AuthRequest;
|
||||
|
||||
/**
|
||||
* Used to determine what type of {@link PresentsClient} to use to manage an authenticated client
|
||||
* Used to determine what type of {@link PresentsSession} to use to manage an authenticated client
|
||||
* as well the type of {@link ClientResolver} to use when resolving clients' runtime data.
|
||||
*/
|
||||
public interface ClientFactory
|
||||
{
|
||||
/** The default client factory. */
|
||||
public static ClientFactory DEFAULT = new ClientFactory() {
|
||||
public Class<? extends PresentsClient> getClientClass (AuthRequest areq) {
|
||||
return PresentsClient.class;
|
||||
public Class<? extends PresentsSession> getClientClass (AuthRequest areq) {
|
||||
return PresentsSession.class;
|
||||
}
|
||||
public Class<? extends ClientResolver> getClientResolverClass (Name username) {
|
||||
return ClientResolver.class;
|
||||
@@ -42,10 +42,10 @@ public interface ClientFactory
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the {@link PresentsClient} derived class to use for the session that authenticated
|
||||
* Returns the {@link PresentsSession} derived class to use for the session that authenticated
|
||||
* with the supplied request.
|
||||
*/
|
||||
Class<? extends PresentsClient> getClientClass (AuthRequest areq);
|
||||
Class<? extends PresentsSession> getClientClass (AuthRequest areq);
|
||||
|
||||
/**
|
||||
* Returns the {@link ClientResolver} derived class to use to resolve a client with the
|
||||
|
||||
@@ -88,13 +88,13 @@ public class ClientManager
|
||||
/**
|
||||
* Called when a client has authenticated and been resolved and has started their session.
|
||||
*/
|
||||
void clientSessionDidStart (PresentsClient client);
|
||||
void clientSessionDidStart (PresentsSession client);
|
||||
|
||||
/**
|
||||
* Called when a client has logged off or been forcibly logged off due to inactivity and
|
||||
* has thus ended their session.
|
||||
*/
|
||||
void clientSessionDidEnd (PresentsClient client);
|
||||
void clientSessionDidEnd (PresentsSession client);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +119,7 @@ public class ClientManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the injector we'll use to resolve dependencies for {@link PresentsClient}
|
||||
* Configures the injector we'll use to resolve dependencies for {@link PresentsSession}
|
||||
* instances.
|
||||
*/
|
||||
public void setInjector (Injector injector)
|
||||
@@ -134,7 +134,7 @@ public class ClientManager
|
||||
|
||||
// inform all of our clients that they are being shut down
|
||||
synchronized (_usermap) {
|
||||
for (PresentsClient pc : _usermap.values()) {
|
||||
for (PresentsSession pc : _usermap.values()) {
|
||||
try {
|
||||
pc.shutdown();
|
||||
} catch (Exception e) {
|
||||
@@ -146,7 +146,7 @@ public class ClientManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the client manager with a factory for creating {@link PresentsClient} and {@link
|
||||
* Configures the client manager with a factory for creating {@link PresentsSession} and {@link
|
||||
* ClientResolver} classes for authenticated client connections.
|
||||
*/
|
||||
public void setClientFactory (ClientFactory factory)
|
||||
@@ -216,7 +216,7 @@ public class ClientManager
|
||||
* 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.
|
||||
*/
|
||||
public PresentsClient getClient (Name authUsername)
|
||||
public PresentsSession getClient (Name authUsername)
|
||||
{
|
||||
synchronized (_usermap) {
|
||||
return _usermap.get(authUsername);
|
||||
@@ -375,7 +375,7 @@ public class ClientManager
|
||||
Name username = creds.getUsername();
|
||||
|
||||
// see if a client is already registered with these credentials
|
||||
PresentsClient client = getClient(username);
|
||||
PresentsSession client = getClient(username);
|
||||
|
||||
if (client != null) {
|
||||
log.info("Resuming session [username=" + username + ", conn=" + conn + "].");
|
||||
@@ -401,7 +401,7 @@ public class ClientManager
|
||||
public synchronized void connectionFailed (Connection conn, IOException fault)
|
||||
{
|
||||
// remove the client from the connection map
|
||||
PresentsClient client = _conmap.remove(conn);
|
||||
PresentsSession client = _conmap.remove(conn);
|
||||
if (client != null) {
|
||||
log.info("Unmapped failed client [client=" + client + ", conn=" + conn +
|
||||
", fault=" + fault + "].");
|
||||
@@ -419,7 +419,7 @@ public class ClientManager
|
||||
public synchronized void connectionClosed (Connection conn)
|
||||
{
|
||||
// remove the client from the connection map
|
||||
PresentsClient client = _conmap.remove(conn);
|
||||
PresentsSession client = _conmap.remove(conn);
|
||||
if (client != null) {
|
||||
log.debug("Unmapped client [client=" + client + ", conn=" + conn + "].");
|
||||
// let the client know the connection went away
|
||||
@@ -448,7 +448,7 @@ public class ClientManager
|
||||
* Called by the client instance when it has started its session. This is called from the
|
||||
* dobjmgr thread.
|
||||
*/
|
||||
protected void clientSessionDidStart (final PresentsClient client)
|
||||
protected void clientSessionDidStart (final PresentsSession client)
|
||||
{
|
||||
// let the observers know
|
||||
_clobservers.apply(new ObserverList.ObserverOp<ClientObserver>() {
|
||||
@@ -463,11 +463,11 @@ public class ClientManager
|
||||
* Called by the client instance when the client requests a logoff. This is called from the
|
||||
* dobjmgr thread.
|
||||
*/
|
||||
protected void clientSessionDidEnd (final PresentsClient client)
|
||||
protected void clientSessionDidEnd (final PresentsSession client)
|
||||
{
|
||||
// remove the client from the username map
|
||||
Name username = client.getCredentials().getUsername();
|
||||
PresentsClient rc;
|
||||
PresentsSession rc;
|
||||
synchronized (_usermap) {
|
||||
rc = _usermap.remove(username);
|
||||
}
|
||||
@@ -497,12 +497,12 @@ public class ClientManager
|
||||
*/
|
||||
protected void flushClients ()
|
||||
{
|
||||
List<PresentsClient> victims = Lists.newArrayList();
|
||||
List<PresentsSession> victims = Lists.newArrayList();
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
// first build a list of our victims
|
||||
synchronized (_usermap) {
|
||||
for (PresentsClient client : _usermap.values()) {
|
||||
for (PresentsSession client : _usermap.values()) {
|
||||
if (client.checkExpired(now)) {
|
||||
victims.add(client);
|
||||
}
|
||||
@@ -510,7 +510,7 @@ public class ClientManager
|
||||
}
|
||||
|
||||
// now end their sessions
|
||||
for (PresentsClient client : victims) {
|
||||
for (PresentsSession client : victims) {
|
||||
try {
|
||||
log.info("Client expired, ending session [client=" + client +
|
||||
", dtime=" + (now-client.getNetworkStamp()) + "ms].");
|
||||
@@ -549,14 +549,14 @@ public class ClientManager
|
||||
protected ClientOp _clop;
|
||||
}
|
||||
|
||||
/** Used to resolve dependencies in {@link PresentsClient} instances that we create. */
|
||||
/** Used to resolve dependencies in {@link PresentsSession} instances that we create. */
|
||||
protected Injector _injector;
|
||||
|
||||
/** A mapping from auth username to client instances. */
|
||||
protected Map<Name, PresentsClient> _usermap = Maps.newHashMap();
|
||||
protected Map<Name, PresentsSession> _usermap = Maps.newHashMap();
|
||||
|
||||
/** A mapping from connections to client instances. */
|
||||
protected Map<Connection, PresentsClient> _conmap = Maps.newHashMap();
|
||||
protected Map<Connection, PresentsSession> _conmap = Maps.newHashMap();
|
||||
|
||||
/** A mapping from usernames to client object instances. */
|
||||
protected Map<Name, ClientObject> _objmap = Maps.newHashMap();
|
||||
|
||||
@@ -575,7 +575,7 @@ public class PresentsDObjectMgr
|
||||
|
||||
/**
|
||||
* Tests if the event processing thread is still running. This is required by the
|
||||
* {@link ConnectionManager} to ensure messages posted just before or during shutdown are sent.
|
||||
* ConnectionManager to ensure messages posted just before or during shutdown are sent.
|
||||
*/
|
||||
public synchronized boolean isRunning ()
|
||||
{
|
||||
|
||||
@@ -74,8 +74,8 @@ public class PresentsObjectAccess
|
||||
{
|
||||
boolean allowed = true;
|
||||
// if the subscriber is a client, ensure that they are this same user
|
||||
if (PresentsClient.class.isInstance(sub)) {
|
||||
PresentsClient client = PresentsClient.class.cast(sub);
|
||||
if (PresentsSession.class.isInstance(sub)) {
|
||||
PresentsSession client = PresentsSession.class.cast(sub);
|
||||
allowed = (client.getClientObject() == object);
|
||||
if (!allowed) {
|
||||
log.warning("Refusing ClientObject subscription request " +
|
||||
|
||||
+14
-14
@@ -83,10 +83,10 @@ import static com.threerings.presents.Log.log;
|
||||
* 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.
|
||||
*/
|
||||
public class PresentsClient
|
||||
public class PresentsSession
|
||||
implements MessageHandler, ClientResolutionListener
|
||||
{
|
||||
/** Used by {@link PresentsClient#setUsername} to report success or failure. */
|
||||
/** Used by {@link PresentsSession#setUsername} to report success or failure. */
|
||||
public static interface UserChangeListener
|
||||
{
|
||||
/** Called when the new client object has been resolved and the new client object reported
|
||||
@@ -106,7 +106,7 @@ public class PresentsClient
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the credentials used to authenticate this client.
|
||||
* Returns the credentials used to authenticate this session.
|
||||
*/
|
||||
public Credentials getCredentials ()
|
||||
{
|
||||
@@ -114,7 +114,7 @@ public class PresentsClient
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time zone in which this client is operating.
|
||||
* Returns the time zone in which the client is operating.
|
||||
*/
|
||||
public TimeZone getTimeZone ()
|
||||
{
|
||||
@@ -122,8 +122,8 @@ public class PresentsClient
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this client has been disconnected for sufficiently long that its session
|
||||
* should be forcibly ended.
|
||||
* Returns true if this session has been disconnected for sufficiently long that it should be
|
||||
* forcibly ended.
|
||||
*/
|
||||
public boolean checkExpired (long now)
|
||||
{
|
||||
@@ -164,7 +164,7 @@ public class PresentsClient
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures this client with a custom class loader that will be used when unserializing
|
||||
* Configures this session with a custom class loader that will be used when unserializing
|
||||
* classes from the network.
|
||||
*/
|
||||
public void setClassLoader (ClassLoader loader)
|
||||
@@ -966,7 +966,7 @@ public class PresentsClient
|
||||
/**
|
||||
* Dispatch the supplied message for the specified client.
|
||||
*/
|
||||
void dispatch (PresentsClient client, UpstreamMessage mge);
|
||||
void dispatch (PresentsSession client, UpstreamMessage mge);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -974,7 +974,7 @@ public class PresentsClient
|
||||
*/
|
||||
protected static class SubscribeDispatcher implements MessageDispatcher
|
||||
{
|
||||
public void dispatch (PresentsClient client, UpstreamMessage msg)
|
||||
public void dispatch (PresentsSession client, UpstreamMessage msg)
|
||||
{
|
||||
SubscribeRequest req = (SubscribeRequest)msg;
|
||||
// log.info("Subscribing [client=" + client + ", oid=" + req.getOid() + "].");
|
||||
@@ -989,7 +989,7 @@ public class PresentsClient
|
||||
*/
|
||||
protected static class UnsubscribeDispatcher implements MessageDispatcher
|
||||
{
|
||||
public void dispatch (PresentsClient client, UpstreamMessage msg)
|
||||
public void dispatch (PresentsSession client, UpstreamMessage msg)
|
||||
{
|
||||
UnsubscribeRequest req = (UnsubscribeRequest)msg;
|
||||
int oid = req.getOid();
|
||||
@@ -1009,7 +1009,7 @@ public class PresentsClient
|
||||
*/
|
||||
protected static class ForwardEventDispatcher implements MessageDispatcher
|
||||
{
|
||||
public void dispatch (PresentsClient client, UpstreamMessage msg)
|
||||
public void dispatch (PresentsSession client, UpstreamMessage msg)
|
||||
{
|
||||
ForwardEventRequest req = (ForwardEventRequest)msg;
|
||||
DEvent fevt = req.getEvent();
|
||||
@@ -1036,7 +1036,7 @@ public class PresentsClient
|
||||
*/
|
||||
protected static class PingDispatcher implements MessageDispatcher
|
||||
{
|
||||
public void dispatch (PresentsClient client, UpstreamMessage msg)
|
||||
public void dispatch (PresentsSession client, UpstreamMessage msg)
|
||||
{
|
||||
// send a pong response using the transport with which the message was received
|
||||
PingRequest req = (PingRequest)msg;
|
||||
@@ -1049,7 +1049,7 @@ public class PresentsClient
|
||||
*/
|
||||
protected static class ThrottleUpdatedDispatcher implements MessageDispatcher
|
||||
{
|
||||
public void dispatch (final PresentsClient client, UpstreamMessage msg)
|
||||
public void dispatch (final PresentsSession client, UpstreamMessage msg)
|
||||
{
|
||||
log.debug("Client ACKed throttle update", "client", client);
|
||||
client.throttleUpdated();
|
||||
@@ -1061,7 +1061,7 @@ public class PresentsClient
|
||||
*/
|
||||
protected static class LogoffDispatcher implements MessageDispatcher
|
||||
{
|
||||
public void dispatch (final PresentsClient client, UpstreamMessage msg)
|
||||
public void dispatch (final PresentsSession client, UpstreamMessage msg)
|
||||
{
|
||||
log.debug("Client requested logoff", "client", client);
|
||||
client.safeEndSession();
|
||||
Reference in New Issue
Block a user