Rethink! Instead of hacking up the peer ClientInfo system for the one thing

that actually needs to look clients up by visible name (chat forwarding), we'll
just leave things as is (as in mapped by auth username) and take care of our
own shit in ClientPeerManager.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5683 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2009-03-11 17:47:35 +00:00
parent 8f05b41c6a
commit 4a7cb2c82f
4 changed files with 61 additions and 27 deletions
@@ -32,14 +32,4 @@ public class CrowdClientInfo extends ClientInfo
{
/** The client's visible name, which is used for chatting. */
public Name visibleName;
@Override // documentation inherited
public Comparable<?> getKey ()
{
// the PeerManager works in such a way that we can override our client
// info key and things still work properly; all inter-server
// communication regarding users will be based on visible name so this
// makes lookups much more efficient
return visibleName;
}
}
@@ -21,6 +21,9 @@
package com.threerings.crowd.peer.server;
import java.util.Map;
import com.google.common.collect.Maps;
import com.google.inject.Inject;
import com.threerings.util.Name;
@@ -77,13 +80,20 @@ public class CrowdPeerManager extends PeerManager
public boolean forwardTell (UserMessage message, Name target,
ChatService.TellListener listener)
{
// look up their auth username from their visible name
Name username = _viztoauth.get(target);
if (username == null) {
return false; // sorry kid, don't know ya
}
// look through our peers to see if the target user is online on one of them
for (PeerNode peer : _peers.values()) {
CrowdNodeObject cnobj = (CrowdNodeObject)peer.nodeobj;
if (cnobj == null) {
continue;
}
CrowdClientInfo cinfo = (CrowdClientInfo)cnobj.clients.get(target);
// we have to use auth username to look up their ClientInfo
CrowdClientInfo cinfo = (CrowdClientInfo)cnobj.clients.get(username);
if (cinfo != null) {
cnobj.crowdPeerService.deliverTell(peer.getClient(), message, target, listener);
return true;
@@ -103,7 +113,7 @@ public class CrowdPeerManager extends PeerManager
}
}
@Override // documentation inherited
@Override // from PeerManager
public void shutdown ()
{
super.shutdown();
@@ -117,19 +127,19 @@ public class CrowdPeerManager extends PeerManager
_chatprov.setChatForwarder(null);
}
@Override // documentation inherited
@Override // from PeerManager
protected NodeObject createNodeObject ()
{
return new CrowdNodeObject();
}
@Override // documentation inherited
@Override // from PeerManager
protected ClientInfo createClientInfo ()
{
return new CrowdClientInfo();
}
@Override // documentation inherited
@Override // from PeerManager
protected void initClientInfo (PresentsSession client, ClientInfo info)
{
super.initClientInfo(client, info);
@@ -137,7 +147,7 @@ public class CrowdPeerManager extends PeerManager
((BodyObject)client.getClientObject()).getVisibleName();
}
@Override // documentation inherited
@Override // from PeerManager
protected void didInit ()
{
super.didInit();
@@ -150,6 +160,33 @@ public class CrowdPeerManager extends PeerManager
_chatprov.setChatForwarder(this);
}
@Override // from PeerManager
protected void clientLoggedOn (String nodeName, ClientInfo clinfo)
{
super.clientLoggedOn(nodeName, clinfo);
// keep a mapping from visibleName to auth username
if (clinfo instanceof CrowdClientInfo) {
CrowdClientInfo ccinfo = (CrowdClientInfo)clinfo;
_viztoauth.put(ccinfo.visibleName, ccinfo.username);
}
}
@Override // from PeerManager
protected void clientLoggedOff (String nodeName, ClientInfo clinfo)
{
super.clientLoggedOff(nodeName, clinfo);
// update our mapping from visibleName to auth username
if (clinfo instanceof CrowdClientInfo) {
CrowdClientInfo ccinfo = (CrowdClientInfo)clinfo;
_viztoauth.remove(ccinfo.visibleName);
}
}
/** A mapping of visible name to username for all clients on all *remote* nodes. */
protected Map<Name, Name> _viztoauth = Maps.newHashMap();
@Inject protected InvocationManager _invmgr;
@Inject protected ChatProvider _chatprov;
}
@@ -986,7 +986,7 @@ public abstract class PeerManager
/**
* Called when we hear about a client logging on to another node.
*/
protected void clientLoggedOnOtherNode (String nodeName, ClientInfo clinfo)
protected void clientLoggedOn (String nodeName, ClientInfo clinfo)
{
PresentsSession session = _clmgr.getClient(clinfo.username);
if (session != null) {
@@ -996,6 +996,14 @@ public abstract class PeerManager
}
}
/**
* Called when we hear about a client logging off of another node.
*/
protected void clientLoggedOff (String nodeName, ClientInfo clinfo)
{
// nothing to do by default
}
/**
* Called when a peer connects to this server.
*/
@@ -255,8 +255,7 @@ public class PeerNode
implements AttributeChangeListener, SetListener<DSet.Entry>
{
// documentation inherited from interface AttributeChangeListener
public void attributeChanged (AttributeChangedEvent event)
{
public void attributeChanged (AttributeChangedEvent event) {
String name = event.getName();
if (name.equals(NodeObject.ACQUIRING_LOCK)) {
NodeObject.Lock lock = nodeobj.acquiringLock;
@@ -299,24 +298,24 @@ public class PeerNode
}
// documentation inherited from interface SetListener
public void entryAdded (EntryAddedEvent<DSet.Entry> event)
{
public void entryAdded (EntryAddedEvent<DSet.Entry> event) {
String name = event.getName();
if (NodeObject.CLIENTS.equals(name)) {
_peermgr.clientLoggedOnOtherNode(getNodeName(), (ClientInfo)event.getEntry());
_peermgr.clientLoggedOn(getNodeName(), (ClientInfo)event.getEntry());
}
}
// documentation inherited from interface SetListener
public void entryUpdated (EntryUpdatedEvent<DSet.Entry> event)
{
public void entryUpdated (EntryUpdatedEvent<DSet.Entry> event) {
// nada
}
// documentation inherited from interface SetListener
public void entryRemoved (EntryRemovedEvent<DSet.Entry> event)
{
// nada
public void entryRemoved (EntryRemovedEvent<DSet.Entry> event) {
String name = event.getName();
if (NodeObject.CLIENTS.equals(name)) {
_peermgr.clientLoggedOff(getNodeName(), (ClientInfo)event.getOldEntry());
}
}
} // END: class NodeObjectListener