The great invocation services rethink of 2002! Rearchitected the remote

method invocation services and converted everything to the new style.
Could this be my biggest checkin ever?


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1642 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-08-14 19:08:01 +00:00
parent 4481c5f835
commit e54a4d41f4
161 changed files with 6083 additions and 2805 deletions
@@ -0,0 +1,52 @@
//
// $Id: ChatDispatcher.java,v 1.1 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.chat;
import com.threerings.crowd.chat.ChatMarshaller;
import com.threerings.crowd.chat.ChatService;
import com.threerings.crowd.chat.ChatService.TellListener;
import com.threerings.presents.client.Client;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.server.InvocationDispatcher;
import com.threerings.presents.server.InvocationException;
/**
* Dispatches requests to the {@link ChatProvider}.
*/
public class ChatDispatcher extends InvocationDispatcher
{
/**
* Creates a dispatcher that may be registered to dispatch invocation
* service requests for the specified provider.
*/
public ChatDispatcher (ChatProvider provider)
{
this.provider = provider;
}
// documentation inherited
public InvocationMarshaller createMarshaller ()
{
return new ChatMarshaller();
}
// documentation inherited
public void dispatchRequest (
ClientObject source, int methodId, Object[] args)
throws InvocationException
{
switch (methodId) {
case ChatMarshaller.TELL:
((ChatProvider)provider).tell(
source,
(String)args[0], (String)args[1], (TellListener)args[2]
);
return;
default:
super.dispatchRequest(source, methodId, args);
}
}
}
@@ -1,50 +1,70 @@
//
// $Id: ChatProvider.java,v 1.12 2002/07/22 22:54:03 ray Exp $
// $Id: ChatProvider.java,v 1.13 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.chat;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.dobj.MessageEvent;
import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationManager;
import com.threerings.presents.server.InvocationProvider;
import com.threerings.crowd.Log;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.server.CrowdServer;
import com.threerings.crowd.Log;
import com.threerings.crowd.chat.ChatService.TellListener;
/**
* The chat provider handles the server side of the chat-related
* invocation services.
*/
public class ChatProvider
extends InvocationProvider implements ChatCodes
implements ChatCodes, InvocationProvider
{
/**
* Initializes the chat services and registers a chat provider with
* the invocation manager.
*/
public static void init (InvocationManager invmgr, DObjectManager omgr)
{
_omgr = omgr;
// register a chat provider with the invocation manager
invmgr.registerDispatcher(new ChatDispatcher(
new ChatProvider()), true);
}
/**
* Processes a request from a client to deliver a tell message to
* another client.
*/
public void handleTellRequest (
BodyObject source, int invid, String target, String message)
public void tell (ClientObject caller, String target, String message,
TellListener listener)
throws InvocationException
{
// look up the target body object
// make sure the target user is online
BodyObject tobj = CrowdServer.lookupBody(target);
if (tobj == null) {
sendResponse(source, invid, TELL_FAILED_RESPONSE,
USER_NOT_ONLINE);
} else {
// deliver a tell notification to the target player
sendTellMessage(tobj.getOid(), source.username, null, message);
// let the teller know it went ok
sendResponse(source, invid, TELL_SUCCEEDED_RESPONSE);
throw new InvocationException(USER_NOT_ONLINE);
}
// deliver a tell notification to the target player
BodyObject source = (BodyObject)caller;
sendTellMessage(tobj, source.username, null, message);
// let the teller know it went ok
listener.tellSucceeded();
}
/**
* Delivers a tell notification to the specified target player,
* originating with the specified speaker.
*
* @param targetOid the body object id of the user that will receive
* the tell message.
* @param target the body object of the user that will receive the
* tell message.
* @param speaker the username of the user that generated the message
* (or some special speaker name for server messages).
* @param bundle the bundle identifier that will be used by the client
@@ -54,89 +74,11 @@ public class ChatProvider
* @param message the text of the chat message.
*/
public static void sendTellMessage (
int targetOid, String speaker, String bundle, String message)
BodyObject target, String speaker, String bundle, String message)
{
Object[] args = null;
if (bundle == null) {
args = new Object[] { speaker, message };
} else {
args = new Object[] { speaker, bundle, message };
}
CrowdServer.invmgr.sendNotification(
targetOid, MODULE_NAME, TELL_NOTIFICATION, args);
ChatSender.sendTell(target, speaker, bundle, message);
}
/**
* Sends a chat notification to the specified place object originating
* with the specified speaker (the speaker optionally being a server
* entity that wishes to fake a "speak" message) and with the supplied
* message content.
*
* @param placeOid the place to which to deliver the chat message.
* @param speaker the username of the user that generated the message
* (or some special speaker name for server messages).
* @param bundle null when the message originates from a real human,
* the bundle identifier that will be used by the client to translate
* the message text when the message originates from a server entity
* "faking" a chat message.
* @param message the text of the chat message.
*/
public static void sendChatMessage (
int placeOid, String speaker, String bundle, String message)
{
sendChatMessage(
placeOid, speaker, bundle, message, ChatCodes.DEFAULT_MODE);
}
/**
* Sends a chat notification to the specified place object originating
* with the specified speaker (the speaker optionally being a server
* entity that wishes to fake a "speak" message) and with the supplied
* message content.
*
* @param placeOid the place to which to deliver the chat message.
* @param speaker the username of the user that generated the message
* (or some special speaker name for server messages).
* @param bundle null when the message originates from a real human,
* the bundle identifier that will be used by the client to translate
* the message text when the message originates from a server entity
* "faking" a chat message.
* @param message the text of the chat message.
* @param mode the mode of the message, @see ChatCodes.DEFAULT_MODE
*/
public static void sendChatMessage (
int placeOid, String speaker, String bundle, String message,
byte mode)
{
Object[] outargs = null;
if (bundle == null) {
outargs = new Object[] { speaker, message, new Byte(mode) };
} else {
outargs = new Object[] { speaker, bundle, message, new Byte(mode) };
}
MessageEvent nevt = new MessageEvent(
placeOid, ChatService.SPEAK_NOTIFICATION, outargs);
CrowdServer.omgr.postEvent(nevt);
}
/**
* Sends a system message notification to the specified place object
* with the supplied message content. A system message is one that
* will be rendered where the chat messages are rendered, but in a way
* that makes it clear that it is a message from the server.
*
* @param placeOid the place to which to deliver the message.
* @param bundle the name of the localization bundle that should be
* used to translate this system message prior to displaying it to the
* client.
* @param message the text of the message.
*/
public static void sendSystemMessage (
int placeOid, String bundle, String message)
{
Object[] outargs = new Object[] { bundle, message };
MessageEvent nevt = new MessageEvent(
placeOid, ChatService.SYSTEM_NOTIFICATION, outargs);
CrowdServer.omgr.postEvent(nevt);
}
/** The distributed object manager used by the chat services. */
protected static DObjectManager _omgr;
}
@@ -0,0 +1,30 @@
//
// $Id: ChatSender.java,v 1.1 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.chat;
import com.threerings.crowd.chat.ChatDecoder;
import com.threerings.crowd.chat.ChatReceiver;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationSender;
/**
* Used to issue notifications to a {@link ChatReceiver} instance on a
* client.
*/
public class ChatSender extends InvocationSender
{
/**
* Issues a notification that will result in a call to {@link
* ChatReceiver#receivedTell} on a client.
*/
public static void sendTell (
ClientObject target, String arg1, String arg2, String arg3)
{
sendNotification(
target, ChatDecoder.RECEIVER_CODE, ChatDecoder.RECEIVED_TELL,
new Object[] { arg1, arg2, arg3 });
}
// Generated on 11:25:46 08/12/02.
}
@@ -0,0 +1,51 @@
//
// $Id: SpeakDispatcher.java,v 1.1 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.chat;
import com.threerings.crowd.chat.SpeakMarshaller;
import com.threerings.crowd.chat.SpeakService;
import com.threerings.presents.client.Client;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.server.InvocationDispatcher;
import com.threerings.presents.server.InvocationException;
/**
* Dispatches requests to the {@link SpeakProvider}.
*/
public class SpeakDispatcher extends InvocationDispatcher
{
/**
* Creates a dispatcher that may be registered to dispatch invocation
* service requests for the specified provider.
*/
public SpeakDispatcher (SpeakProvider provider)
{
this.provider = provider;
}
// documentation inherited
public InvocationMarshaller createMarshaller ()
{
return new SpeakMarshaller();
}
// documentation inherited
public void dispatchRequest (
ClientObject source, int methodId, Object[] args)
throws InvocationException
{
switch (methodId) {
case SpeakMarshaller.SPEAK:
((SpeakProvider)provider).speak(
source,
(String)args[0], ((Byte)args[1]).byteValue()
);
return;
default:
super.dispatchRequest(source, methodId, args);
}
}
}
@@ -0,0 +1,149 @@
//
// $Id: SpeakProvider.java,v 1.1 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.chat;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.MessageEvent;
import com.threerings.presents.server.InvocationProvider;
import com.threerings.crowd.Log;
import com.threerings.crowd.data.BodyObject;
/**
* Provides the back-end of the chat speaking facilities. A server entity
* can make "speech" available among the subscribers of a particular
* distributed object by constructing a speak provider and registering it
* with the invocation manager, then placing the resulting marshaller into
* the distributed object in question so that subscribers to that object
* can use it to generate "speak" requests on that object.
*/
public class SpeakProvider
implements InvocationProvider, ChatCodes
{
/**
* Used to prevent abitrary users from issuing speak requests.
*/
public static interface SpeakerValidator
{
/**
* Should return true if the supplied speaker is allowed to speak
* via the speak provider with which this validator was
* registered.
*/
public boolean isValidSpeaker (DObject speakObj, ClientObject speaker);
}
/**
* Creates a speak provider that will provide speech on the supplied
* distributed object.
*
* @param speakObj the object for which speech requests will be
* processed.
* @param validator an optional validator that can be used to prevent
* arbitrary users from using the speech services on this object.
*/
public SpeakProvider (DObject speakObj, SpeakerValidator validator)
{
_speakObj = speakObj;
_validator = validator;
}
/**
* Handles a {@link SpeakService#speak} request.
*/
public void speak (ClientObject caller, String message, byte mode)
{
// ensure that the speaker is valid
if (!_validator.isValidSpeaker(_speakObj, caller)) {
Log.warning("Refusing invalid speak request " +
"[caller=" + caller.who() +
", speakObj=" + _speakObj.which() +
", message=" + message + ", mode=" + mode + "].");
} else {
// issue the speak message on our speak object
sendSpeak(_speakObj, ((BodyObject)caller).username,
null, message, mode);
}
}
/**
* Sends a speak notification to the specified place object
* originating with the specified speaker (the speaker optionally
* being a server entity that wishes to fake a "speak" message) and
* with the supplied message content.
*
* @param speakObj the object on which to generate the speak message.
* @param speaker the username of the user that generated the message
* (or some special speaker name for server messages).
* @param bundle null when the message originates from a real human,
* the bundle identifier that will be used by the client to translate
* the message text when the message originates from a server entity
* "faking" a chat message.
* @param message the text of the speak message.
*/
public static void sendSpeak (DObject speakObj, String speaker,
String bundle, String message)
{
sendSpeak(speakObj, speaker, bundle, message, ChatCodes.DEFAULT_MODE);
}
/**
* Sends a speak notification to the specified place object
* originating with the specified speaker (the speaker optionally
* being a server entity that wishes to fake a "speak" message) and
* with the supplied message content.
*
* @param speakObj the object on which to generate the speak message.
* @param speaker the username of the user that generated the message
* (or some special speaker name for server messages).
* @param bundle null when the message originates from a real human,
* the bundle identifier that will be used by the client to translate
* the message text when the message originates from a server entity
* "faking" a chat message.
* @param message the text of the speak message.
* @param mode the mode of the message, see {@link
* ChatCodes#DEFAULT_MODE}.
*/
public static void sendSpeak (
DObject speakObj, String speaker,
String bundle, String message, byte mode)
{
Object[] outargs = null;
if (bundle == null) {
outargs = new Object[] { speaker, message, new Byte(mode) };
} else {
outargs = new Object[] { speaker, bundle, message, new Byte(mode) };
}
speakObj.postEvent(
new MessageEvent(speakObj.getOid(), SPEAK_NOTIFICATION, outargs));
}
/**
* Sends a system message notification to the specified object with
* the supplied message content. A system message is one that will be
* rendered where the speak messages are rendered, but in a way that
* makes it clear that it is a message from the server.
*
* @param speakObj the object on which to deliver the message.
* @param bundle the name of the localization bundle that should be
* used to translate this system message prior to displaying it to the
* client.
* @param message the text of the message.
*/
public static void sendSystemSpeak (
DObject speakObj, String bundle, String message)
{
speakObj.postEvent(
new MessageEvent(speakObj.getOid(), SYSTEM_NOTIFICATION,
new Object[] { bundle, message }));
}
/** Our speech object. */
protected DObject _speakObj;
/** The entity that will validate our speakers. */
protected SpeakerValidator _validator;
}