Finished up the basic peer system and wired up the tell forwarding. In theory

it all works, now to test it.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4249 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-07-05 22:48:32 +00:00
parent e492f09bee
commit 6be44f5a65
10 changed files with 342 additions and 48 deletions
@@ -21,11 +21,12 @@
package com.threerings.crowd.peer.client;
import com.threerings.util.Name;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.data.ChatMessage;
/**
* Bridges certain Crowd services between peers in a cluster configuration.
@@ -33,8 +34,9 @@ import com.threerings.crowd.chat.data.ChatMessage;
public interface CrowdPeerService extends InvocationService
{
/**
* Forwards a tell request to the server on which a user actually resides.
* Used to forward a tell request to the server on which the destination
* user actually occupies.
*/
public void deliverTell (
Client client, ChatMessage message, ChatService.TellListener listener);
public void deliverTell (Client client, Name teller, Name target,
String message, ChatService.TellListener listener);
}
@@ -32,4 +32,14 @@ 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;
}
}
@@ -23,11 +23,11 @@ package com.threerings.crowd.peer.data;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.data.ChatMarshaller;
import com.threerings.crowd.chat.data.ChatMessage;
import com.threerings.crowd.peer.client.CrowdPeerService;
import com.threerings.presents.client.Client;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.dobj.InvocationResponseEvent;
import com.threerings.util.Name;
/**
* Provides the implementation of the {@link CrowdPeerService} interface
@@ -43,12 +43,12 @@ public class CrowdPeerMarshaller extends InvocationMarshaller
public static final int DELIVER_TELL = 1;
// documentation inherited from interface
public void deliverTell (Client arg1, ChatMessage arg2, ChatService.TellListener arg3)
public void deliverTell (Client arg1, Name arg2, Name arg3, String arg4, ChatService.TellListener arg5)
{
ChatMarshaller.TellMarshaller listener3 = new ChatMarshaller.TellMarshaller();
listener3.listener = arg3;
ChatMarshaller.TellMarshaller listener5 = new ChatMarshaller.TellMarshaller();
listener5.listener = arg5;
sendRequest(arg1, DELIVER_TELL, new Object[] {
arg2, listener3
arg2, arg3, arg4, listener5
});
}
@@ -23,7 +23,6 @@ package com.threerings.crowd.peer.server;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.data.ChatMarshaller;
import com.threerings.crowd.chat.data.ChatMessage;
import com.threerings.crowd.peer.client.CrowdPeerService;
import com.threerings.crowd.peer.data.CrowdPeerMarshaller;
import com.threerings.presents.client.Client;
@@ -31,6 +30,7 @@ import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.server.InvocationDispatcher;
import com.threerings.presents.server.InvocationException;
import com.threerings.util.Name;
/**
* Dispatches requests to the {@link CrowdPeerProvider}.
@@ -61,7 +61,7 @@ public class CrowdPeerDispatcher extends InvocationDispatcher
case CrowdPeerMarshaller.DELIVER_TELL:
((CrowdPeerProvider)provider).deliverTell(
source,
(ChatMessage)args[0], (ChatService.TellListener)args[1]
(Name)args[0], (Name)args[1], (String)args[2], (ChatService.TellListener)args[3]
);
return;
@@ -25,15 +25,31 @@ import com.samskivert.io.PersistenceException;
import com.samskivert.jdbc.ConnectionProvider;
import com.samskivert.util.Invoker;
import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.PresentsClient;
import com.threerings.presents.peer.data.ClientInfo;
import com.threerings.presents.peer.data.NodeObject;
import com.threerings.presents.peer.server.PeerManager;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.data.ChatMessage;
import com.threerings.crowd.chat.server.ChatProvider;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.server.CrowdServer;
import com.threerings.crowd.peer.data.CrowdClientInfo;
import com.threerings.crowd.peer.data.CrowdNodeObject;
import com.threerings.crowd.peer.data.CrowdPeerMarshaller;
/**
* Extends the standard peer manager and bridges certain Crowd services.
*/
public class CrowdPeerManager extends PeerManager
implements CrowdPeerProvider, ChatProvider.TellForwarder
{
/**
* Creates a peer manager that integrates Crowd services across a cluster
@@ -45,9 +61,81 @@ public class CrowdPeerManager extends PeerManager
super(conprov, invoker);
}
// documentation inherited from interface CrowdPeerProvider
public void deliverTell (ClientObject caller, Name teller, Name target,
String message, ChatService.TellListener listener)
throws InvocationException
{
// the originating server has already permissions checked the teller,
// so we just forward the message as if it originated on this server
ChatProvider.deliverTell(teller, target, message, listener);
}
// documentation inherited from interface ChatProvider.TellForwarder
public boolean forwardTell (Name teller, Name target, String message,
ChatService.TellListener listener)
{
// look through our peer objects to see if the target user is online on
// one of the other servers
for (PeerNode peer : _peers.values()) {
CrowdNodeObject cnobj = (CrowdNodeObject)peer.nodeobj;
CrowdClientInfo cinfo = (CrowdClientInfo)cnobj.clients.get(target);
if (cinfo != null) {
cnobj.crowdPeerService.deliverTell(
peer.getClient(), teller, target, message, listener);
return true;
}
}
return false;
}
@Override // documentation inherited
public void shutdown ()
{
super.shutdown();
// unregister our invocation service
if (_nodeobj != null) {
CrowdServer.invmgr.clearDispatcher(
((CrowdNodeObject)_nodeobj).crowdPeerService);
}
// clear our tell forwarder registration
ChatProvider.setTellForwarder(null);
}
@Override // documentation inherited
protected void finishInit (NodeObject nodeobj)
{
super.finishInit(nodeobj);
// register and initialize our invocation service
CrowdNodeObject cnobj = (CrowdNodeObject)nodeobj;
cnobj.setCrowdPeerService(
(CrowdPeerMarshaller)CrowdServer.invmgr.registerDispatcher(
new CrowdPeerDispatcher(this), false));
// register ourselves as a tell forwarder
ChatProvider.setTellForwarder(this);
}
@Override // documentation inherited
protected Class<? extends NodeObject> getNodeObjectClass ()
{
return CrowdNodeObject.class;
}
@Override // documentation inherited
protected ClientInfo createClientInfo ()
{
return new CrowdClientInfo();
}
@Override // documentation inherited
protected void initClientInfo (PresentsClient client, ClientInfo info)
{
super.initClientInfo(client, info);
((CrowdClientInfo)info).visibleName =
((BodyObject)client.getClientObject()).getVisibleName();
}
}
@@ -23,12 +23,12 @@ package com.threerings.crowd.peer.server;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.data.ChatMarshaller;
import com.threerings.crowd.chat.data.ChatMessage;
import com.threerings.crowd.peer.client.CrowdPeerService;
import com.threerings.presents.client.Client;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationProvider;
import com.threerings.util.Name;
/**
* Defines the server-side of the {@link CrowdPeerService}.
@@ -38,6 +38,6 @@ public interface CrowdPeerProvider extends InvocationProvider
/**
* Handles a {@link CrowdPeerService#deliverTell} request.
*/
public void deliverTell (ClientObject caller, ChatMessage arg1, ChatService.TellListener arg2)
public void deliverTell (ClientObject caller, Name arg1, Name arg2, String arg3, ChatService.TellListener arg4)
throws InvocationException;
}