Added simple mechanism to resolve a client, apply some operation to it and
release it back into the wild. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2010 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ClientManager.java,v 1.27 2002/11/26 02:14:25 mdb Exp $
|
// $Id: ClientManager.java,v 1.28 2002/11/29 23:40:32 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.presents.server;
|
package com.threerings.presents.server;
|
||||||
|
|
||||||
@@ -33,6 +33,22 @@ import com.threerings.presents.server.util.SafeInterval;
|
|||||||
public class ClientManager
|
public class ClientManager
|
||||||
implements ConnectionObserver, PresentsServer.Reporter
|
implements ConnectionObserver, PresentsServer.Reporter
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Used by {@link #applyToClient}.
|
||||||
|
*/
|
||||||
|
public static interface ClientOp
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Called with the resolved client object.
|
||||||
|
*/
|
||||||
|
public void apply (ClientObject clobj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called if the client resolution fails.
|
||||||
|
*/
|
||||||
|
public void resolutionFailed (Exception e);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a client manager that will interact with the supplied
|
* Constructs a client manager that will interact with the supplied
|
||||||
* connection manager.
|
* connection manager.
|
||||||
@@ -130,6 +146,15 @@ public class ClientManager
|
|||||||
return username.toLowerCase();
|
return username.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the specified client, applies the supplied client
|
||||||
|
* operation to them and releases the client.
|
||||||
|
*/
|
||||||
|
public void applyToClient (String username, ClientOp clop)
|
||||||
|
{
|
||||||
|
resolveClientObject(username, new ClientOpResolver(clop));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests that the client object for the specified user be resolved.
|
* Requests that the client object for the specified user be resolved.
|
||||||
* If the client object is already resolved, the request will be
|
* If the client object is already resolved, the request will be
|
||||||
@@ -366,6 +391,40 @@ public class ClientManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Used by {@link #applyToClient}. */
|
||||||
|
protected class ClientOpResolver
|
||||||
|
implements ClientResolutionListener
|
||||||
|
{
|
||||||
|
public ClientOpResolver (ClientOp clop)
|
||||||
|
{
|
||||||
|
_clop = clop;
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited from interface
|
||||||
|
public void clientResolved (String username, ClientObject clobj)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
_clop.apply(clobj);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.warning("Client op failed [username=" + username +
|
||||||
|
", clop=" + _clop + "].");
|
||||||
|
Log.logStackTrace(e);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
releaseClientObject(username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited from interface
|
||||||
|
public void resolutionFailed (String username, Exception reason)
|
||||||
|
{
|
||||||
|
_clop.resolutionFailed(reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ClientOp _clop;
|
||||||
|
}
|
||||||
|
|
||||||
/** A mapping from usernames to client instances. */
|
/** A mapping from usernames to client instances. */
|
||||||
protected HashMap _usermap = new HashMap();
|
protected HashMap _usermap = new HashMap();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user