Starting to wire up client/server dobj stuff.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@22 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-06-02 01:30:37 +00:00
parent 2c3e4d9528
commit 1c6b292edc
18 changed files with 320 additions and 64 deletions
@@ -1,11 +1,13 @@
//
// $Id: ClientManager.java,v 1.1 2001/06/01 22:12:03 mdb Exp $
// $Id: ClientManager.java,v 1.2 2001/06/02 01:30:37 mdb Exp $
package com.threerings.cocktail.cher.server;
import java.io.IOException;
import java.util.HashMap;
import com.threerings.cocktail.cher.Log;
import com.threerings.cocktail.cher.net.Credentials;
import com.threerings.cocktail.cher.server.net.*;
/**
@@ -13,6 +15,11 @@ import com.threerings.cocktail.cher.server.net.*;
* surprise) 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.
*
* <p> 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).
*/
public class ClientManager implements ConnectionObserver
{
@@ -29,9 +36,22 @@ public class ClientManager implements ConnectionObserver
*
* @param conn The newly established connection.
*/
public void connectionEstablished (Connection conn)
public synchronized
void connectionEstablished (Connection conn, Credentials creds)
{
Log.info("Connection established: " + conn);
String username = creds.getUsername();
// see if there's a client already registered with this username
Client client = (Client)_clients.get(username);
if (client != null) {
Log.info("Session resumed [username=" + username +
", conn=" + conn + "].");
} else {
Log.info("Session initiated [username=" + username +
", conn=" + conn + "].");
}
}
/**
@@ -43,7 +63,8 @@ public class ClientManager implements ConnectionObserver
* @param conn The connection in that failed.
* @param fault The exception associated with the failure.
*/
public void connectionFailed (Connection conn, IOException fault)
public synchronized
void connectionFailed (Connection conn, IOException fault)
{
Log.info("Connection failed: " + conn + ": " + fault);
}
@@ -53,8 +74,10 @@ public class ClientManager implements ConnectionObserver
*
* @param conn The recently closed connection.
*/
public void connectionClosed (Connection conn)
public synchronized void connectionClosed (Connection conn)
{
Log.info("Connection closed: " + conn);
}
protected HashMap _clients = new HashMap();
}