Crowd peer services now forward broadcasts as well as tells. We must get the

word to the people, all the people.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4816 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-08-16 22:38:40 +00:00
parent 3204cc6266
commit d92f81af78
6 changed files with 83 additions and 28 deletions
@@ -64,8 +64,8 @@ public class ChatProvider
public void sentTell (BodyObject teller, BodyObject tellee, String message); public void sentTell (BodyObject teller, BodyObject tellee, String message);
} }
/** Used to forward tells between servers in a multi-server setup. */ /** Used to forward certain types of chat messages between servers in a multi-server setup. */
public static interface TellForwarder public static interface ChatForwarder
{ {
/** /**
* Requests that the supplied tell message be delivered to the appropriate destination. * Requests that the supplied tell message be delivered to the appropriate destination.
@@ -73,6 +73,11 @@ public class ChatProvider
* @return true if the tell was delivered, false otherwise. * @return true if the tell was delivered, false otherwise.
*/ */
public boolean forwardTell (UserMessage message, Name target, TellListener listener); public boolean forwardTell (UserMessage message, Name target, TellListener listener);
/**
* Requests that the supplied broadcast message be delivered on other servers.
*/
public void forwardBroadcast (Name from, String bundle, String msg, boolean attention);
} }
/** /**
@@ -99,12 +104,12 @@ public class ChatProvider
} }
/** /**
* Configures the tell forwarded for the chat provider. This is used by the Crowd peer services * Configures the chat forwarder. This is used by the Crowd peer services to forward messages
* to forward tells between servers in a multi-server cluster. * between servers in a multi-server cluster.
*/ */
public void setTellForwarder (TellForwarder forwarder) public void setChatForwarder (ChatForwarder forwarder)
{ {
_tellForwarder = forwarder; _chatForwarder = forwarder;
} }
/** /**
@@ -151,7 +156,7 @@ public class ChatProvider
if (errmsg != null) { if (errmsg != null) {
throw new InvocationException(errmsg); throw new InvocationException(errmsg);
} }
broadcast(body.getVisibleName(), null, message, false); broadcast(body.getVisibleName(), null, message, false, true);
} }
/** /**
@@ -166,16 +171,17 @@ public class ChatProvider
} }
/** /**
* Broadcast the specified message to all places in the game. * Broadcasts the specified message to all place objects in the system.
* *
* @param from the user the broadcast is from, or null to send the message as a system message. * @param from the user the broadcast is from, or null to send the message as a system message.
* @param bundle the bundle, or null if the message needs no translation. * @param bundle the bundle, or null if the message needs no translation.
* @param msg the content of the message to broadcast. * @param msg the content of the message to broadcast.
* @param attention if true, the message is sent as ATTENTION level, otherwise as INFO. Ignored * @param attention if true, the message is sent as ATTENTION level, otherwise as INFO. Ignored
* if from is non-null. * if from is non-null.
* @param forward if true, forward this broadcast on to any registered chat forwarder, if
* false, deliver it only locally on this server.
*/ */
public void broadcast (Name from, String bundle, String msg, public void broadcast (Name from, String bundle, String msg, boolean attention, boolean forward)
boolean attention)
{ {
if (_broadcastObject != null) { if (_broadcastObject != null) {
broadcastTo(_broadcastObject, from, bundle, msg, attention); broadcastTo(_broadcastObject, from, bundle, msg, attention);
@@ -189,6 +195,10 @@ public class ChatProvider
} }
} }
} }
if (forward && _chatForwarder != null) {
_chatForwarder.forwardBroadcast(from, bundle, msg, attention);
}
} }
/** /**
@@ -202,8 +212,7 @@ public class ChatProvider
BodyObject tobj = CrowdServer.lookupBody(target); BodyObject tobj = CrowdServer.lookupBody(target);
if (tobj == null) { if (tobj == null) {
// if we have a forwarder configured, try forwarding the tell // if we have a forwarder configured, try forwarding the tell
if (_tellForwarder != null && if (_chatForwarder != null && _chatForwarder.forwardTell(message, target, listener)) {
_tellForwarder.forwardTell(message, target, listener)) {
return; return;
} }
throw new InvocationException(USER_NOT_ONLINE); throw new InvocationException(USER_NOT_ONLINE);
@@ -273,8 +282,8 @@ public class ChatProvider
/** Generates auto-responses to tells. May be null. */ /** Generates auto-responses to tells. May be null. */
protected TellAutoResponder _autoRespond; protected TellAutoResponder _autoRespond;
/** Forwards tells between servers. May be null. */ /** Forwards chat between servers. May be null. */
protected TellForwarder _tellForwarder; protected ChatForwarder _chatForwarder;
/** An alternative object to which broadcasts should be sent. */ /** An alternative object to which broadcasts should be sent. */
protected DObject _broadcastObject; protected DObject _broadcastObject;
@@ -35,9 +35,15 @@ import com.threerings.crowd.chat.data.UserMessage;
public interface CrowdPeerService extends InvocationService public interface CrowdPeerService extends InvocationService
{ {
/** /**
* Used to forward a tell request to the server on which the destination * Used to forward a tell request to the server on which the destination user actually
* user actually occupies. * occupies.
*/ */
public void deliverTell (Client client, UserMessage message, Name target, public void deliverTell (Client client, UserMessage message, Name target,
ChatService.TellListener listener); ChatService.TellListener listener);
/**
* Dispatches a broadcast message on this peer.
*/
public void deliverBroadcast (
Client client, Name from, String bundle, String msg, boolean attention);
} }
@@ -40,8 +40,19 @@ import com.threerings.util.Name;
public class CrowdPeerMarshaller extends InvocationMarshaller public class CrowdPeerMarshaller extends InvocationMarshaller
implements CrowdPeerService implements CrowdPeerService
{ {
/** The method id used to dispatch {@link #deliverBroadcast} requests. */
public static final int DELIVER_BROADCAST = 1;
// from interface CrowdPeerService
public void deliverBroadcast (Client arg1, Name arg2, String arg3, String arg4, boolean arg5)
{
sendRequest(arg1, DELIVER_BROADCAST, new Object[] {
arg2, arg3, arg4, Boolean.valueOf(arg5)
});
}
/** The method id used to dispatch {@link #deliverTell} requests. */ /** The method id used to dispatch {@link #deliverTell} requests. */
public static final int DELIVER_TELL = 1; public static final int DELIVER_TELL = 2;
// from interface CrowdPeerService // from interface CrowdPeerService
public void deliverTell (Client arg1, UserMessage arg2, Name arg3, ChatService.TellListener arg4) public void deliverTell (Client arg1, UserMessage arg2, Name arg3, ChatService.TellListener arg4)
@@ -59,6 +59,13 @@ public class CrowdPeerDispatcher extends InvocationDispatcher
throws InvocationException throws InvocationException
{ {
switch (methodId) { switch (methodId) {
case CrowdPeerMarshaller.DELIVER_BROADCAST:
((CrowdPeerProvider)provider).deliverBroadcast(
source,
(Name)args[0], (String)args[1], (String)args[2], ((Boolean)args[3]).booleanValue()
);
return;
case CrowdPeerMarshaller.DELIVER_TELL: case CrowdPeerMarshaller.DELIVER_TELL:
((CrowdPeerProvider)provider).deliverTell( ((CrowdPeerProvider)provider).deliverTell(
source, source,
@@ -47,9 +47,9 @@ import com.threerings.crowd.peer.data.CrowdPeerMarshaller;
* Extends the standard peer manager and bridges certain Crowd services. * Extends the standard peer manager and bridges certain Crowd services.
*/ */
public class CrowdPeerManager extends PeerManager public class CrowdPeerManager extends PeerManager
implements CrowdPeerProvider, ChatProvider.TellForwarder implements CrowdPeerProvider, ChatProvider.ChatForwarder
{ {
// documentation inherited from interface CrowdPeerProvider // from interface CrowdPeerProvider
public void deliverTell (ClientObject caller, UserMessage message, public void deliverTell (ClientObject caller, UserMessage message,
Name target, ChatService.TellListener listener) Name target, ChatService.TellListener listener)
throws InvocationException throws InvocationException
@@ -58,12 +58,19 @@ public class CrowdPeerManager extends PeerManager
CrowdServer.chatprov.deliverTell(message, target, listener); CrowdServer.chatprov.deliverTell(message, target, listener);
} }
// documentation inherited from interface ChatProvider.TellForwarder // from interface CrowdPeerProvider
public void deliverBroadcast (ClientObject caller, Name from, String bundle, String msg,
boolean attention)
{
// deliver the broadcast locally on this server
CrowdServer.chatprov.broadcast(from, bundle, msg, attention, false);
}
// from interface ChatProvider.ChatForwarder
public boolean forwardTell (UserMessage message, Name target, public boolean forwardTell (UserMessage message, Name target,
ChatService.TellListener listener) ChatService.TellListener listener)
{ {
// look through our peer objects to see if the target user is online on // look through our peers to see if the target user is online on one of them
// one of the other servers
for (PeerNode peer : _peers.values()) { for (PeerNode peer : _peers.values()) {
CrowdNodeObject cnobj = (CrowdNodeObject)peer.nodeobj; CrowdNodeObject cnobj = (CrowdNodeObject)peer.nodeobj;
if (cnobj == null) { if (cnobj == null) {
@@ -71,14 +78,24 @@ public class CrowdPeerManager extends PeerManager
} }
CrowdClientInfo cinfo = (CrowdClientInfo)cnobj.clients.get(target); CrowdClientInfo cinfo = (CrowdClientInfo)cnobj.clients.get(target);
if (cinfo != null) { if (cinfo != null) {
cnobj.crowdPeerService.deliverTell( cnobj.crowdPeerService.deliverTell(peer.getClient(), message, target, listener);
peer.getClient(), message, target, listener);
return true; return true;
} }
} }
return false; return false;
} }
// from interface ChatProvider.ChatForwarder
public void forwardBroadcast (Name from, String bundle, String msg, boolean attention)
{
for (PeerNode peer : _peers.values()) {
if (peer.nodeobj != null) {
((CrowdNodeObject)peer.nodeobj).crowdPeerService.deliverBroadcast(
peer.getClient(), from, bundle, msg, attention);
}
}
}
@Override // documentation inherited @Override // documentation inherited
public void shutdown () public void shutdown ()
{ {
@@ -89,8 +106,8 @@ public class CrowdPeerManager extends PeerManager
CrowdServer.invmgr.clearDispatcher(((CrowdNodeObject)_nodeobj).crowdPeerService); CrowdServer.invmgr.clearDispatcher(((CrowdNodeObject)_nodeobj).crowdPeerService);
} }
// clear our tell forwarder registration // clear our chat forwarder registration
CrowdServer.chatprov.setTellForwarder(null); CrowdServer.chatprov.setChatForwarder(null);
} }
@Override // documentation inherited @Override // documentation inherited
@@ -124,7 +141,7 @@ public class CrowdPeerManager extends PeerManager
(CrowdPeerMarshaller)CrowdServer.invmgr.registerDispatcher( (CrowdPeerMarshaller)CrowdServer.invmgr.registerDispatcher(
new CrowdPeerDispatcher(this))); new CrowdPeerDispatcher(this)));
// register ourselves as a tell forwarder // register ourselves as a chat forwarder
CrowdServer.chatprov.setTellForwarder(this); CrowdServer.chatprov.setChatForwarder(this);
} }
} }
@@ -36,6 +36,11 @@ import com.threerings.util.Name;
*/ */
public interface CrowdPeerProvider extends InvocationProvider public interface CrowdPeerProvider extends InvocationProvider
{ {
/**
* Handles a {@link CrowdPeerService#deliverBroadcast} request.
*/
public void deliverBroadcast (ClientObject caller, Name arg1, String arg2, String arg3, boolean arg4);
/** /**
* Handles a {@link CrowdPeerService#deliverTell} request. * Handles a {@link CrowdPeerService#deliverTell} request.
*/ */