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,28 @@
//
// $Id: ClientObject.dobj,v 1.1 2002/08/14 19:07:54 mdb Exp $
package com.threerings.presents.data;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DSet;
/**
* Every client in the system has an associated client object to which
* only they subscribe. The client object can be used to deliver messages
* solely to a particular client as well as to publish client-specific
* data.
*/
public class ClientObject extends DObject
{
/** Used to publish all invocation service receivers registered on
* this client. */
public DSet receivers = new DSet();
/**
* Returns a short string identifying this client.
*/
public String who ()
{
return "(" + getOid() + ")";
}
}
@@ -1,9 +1,10 @@
//
// $Id: ClientObject.java,v 1.2 2001/10/11 04:07:52 mdb Exp $
// $Id: ClientObject.java,v 1.3 2002/08/14 19:07:54 mdb Exp $
package com.threerings.presents.data;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DSet;
/**
* Every client in the system has an associated client object to which
@@ -13,4 +14,64 @@ import com.threerings.presents.dobj.DObject;
*/
public class ClientObject extends DObject
{
/** The field name of the <code>receivers</code> field. */
public static final String RECEIVERS = "receivers";
/** Used to publish all invocation service receivers registered on
* this client. */
public DSet receivers = new DSet();
/**
* Returns a short string identifying this client.
*/
public String who ()
{
return "(" + getOid() + ")";
}
/**
* Requests that the specified entry be added to the
* <code>receivers</code> set. The set will not change until the event is
* actually propagated through the system.
*/
public void addToReceivers (DSet.Entry elem)
{
requestEntryAdd(RECEIVERS, elem);
}
/**
* Requests that the entry matching the supplied key be removed from
* the <code>receivers</code> set. The set will not change until the
* event is actually propagated through the system.
*/
public void removeFromReceivers (Object key)
{
requestEntryRemove(RECEIVERS, key);
}
/**
* Requests that the specified entry be updated in the
* <code>receivers</code> set. The set will not change until the event is
* actually propagated through the system.
*/
public void updateReceivers (DSet.Entry elem)
{
requestEntryUpdate(RECEIVERS, elem);
}
/**
* Requests that the <code>receivers</code> field be set to the
* specified value. Generally one only adds, updates and removes
* entries of a distributed set, but certain situations call for a
* complete replacement of the set value. The local value will be
* updated immediately and an event will be propagated through the
* system to notify all listeners that the attribute did
* change. Proxied copies of this object (on clients) will apply the
* value change when they received the attribute changed notification.
*/
public void setReceivers (DSet receivers)
{
this.receivers = receivers;
requestAttributeChange(RECEIVERS, receivers);
}
}
@@ -0,0 +1,156 @@
//
// $Id: InvocationMarshaller.java,v 1.1 2002/08/14 19:07:55 mdb Exp $
package com.threerings.presents.data;
import java.io.IOException;
import com.samskivert.util.StringUtil;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;
import com.threerings.presents.Log;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.dobj.InvocationResponseEvent;
/**
* Provides a base from which all invocation service marshallers extend.
* Handles functionality common to all marshallers.
*/
public class InvocationMarshaller
implements Streamable, InvocationService
{
/**
* Provides a base from which invocation listener marshallers extend.
*/
public static class ListenerMarshaller
implements Streamable, InvocationListener
{
/** The method id used to dispatch a {@link #requestFailed}
* response. */
public static final int REQUEST_FAILED_RSPID = 0;
/** The oid of the invocation service requester. */
public int callerOid;
/** The request id associated with this listener. */
public short requestId;
/** The actual invocation listener associated with this
* marshalling listener. This is only valid on the client. */
public transient InvocationListener listener;
/** The distributed object manager to use when dispatching proxied
* responses. This is only valid on the server. */
public transient DObjectManager omgr;
// documentation inherited from interface
public void requestFailed (String cause)
{
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, REQUEST_FAILED_RSPID,
new Object[] { cause }));
}
/**
* Called to dispatch an invocation response to our target
* listener.
*/
public void dispatchResponse (int methodId, Object[] args)
{
if (methodId == REQUEST_FAILED_RSPID) {
listener.requestFailed((String)args[0]);
} else {
Log.warning("Requested to dispatch unknown invocation " +
"response [listener=" + listener +
", methodId=" + methodId +
", args=" + StringUtil.toString(args) + "].");
}
}
/**
* Generates a string representation of this instance.
*/
public String toString ()
{
return "[callerOid=" + callerOid + ", reqId=" + requestId +
", type=" + getClass().getName() + "]";
}
}
/**
* Initializes this invocation marshaller instance with the requisite
* information to allow it to operate in the wide world. This is
* called by the invocation manager when an invocation provider is
* registered and should not be called otherwise.
*/
public void init (int invOid, int invCode)
{
_invOid = invOid;
_invCode = invCode;
}
/**
* Sets the invocation oid to which this marshaller should send its
* invocation service requests. This is called by the invocation
* manager in certain initialization circumstances.
*/
public void setInvocationOid (int invOid)
{
_invOid = invOid;
}
/**
* Called by generated invocation marshaller code; packages up and
* sends the specified invocation service request.
*/
protected void sendRequest (Client client, int methodId, Object[] args)
{
client.getInvocationDirector().sendRequest(
_invOid, _invCode, methodId, args);
}
/**
* Writes this instance to the supplied output stream.
*/
public void writeObject (ObjectOutputStream out)
throws IOException
{
out.writeInt(_invOid);
out.writeShort(_invCode);
}
/**
* Reads this instance from the supplied input stream.
*/
public void readObject (ObjectInputStream in)
throws IOException
{
_invOid = in.readInt();
_invCode = in.readShort();
}
/**
* Generates a string representation of this instance.
*/
public String toString ()
{
return "[invOid=" + _invOid + ", code=" + _invCode +
", type=" + getClass().getName() + "]";
}
/** The oid of the invocation object, where invocation service
* requests are sent. */
protected int _invOid;
/** The invocation service code assigned to this service when it was
* registered on the server. */
protected int _invCode;
}
@@ -1,5 +1,5 @@
//
// $Id: InvocationObject.java,v 1.3 2001/10/11 04:07:52 mdb Exp $
// $Id: InvocationObject.java,v 1.4 2002/08/14 19:07:55 mdb Exp $
package com.threerings.presents.data;
@@ -13,21 +13,4 @@ import com.threerings.presents.dobj.DObject;
*/
public class InvocationObject extends DObject
{
/**
* This constant is used to identify invocation requests sent to the
* server.
*/
public static final String REQUEST_NAME = "invreq";
/**
* This constant is used to identify invocation responses sent to the
* client.
*/
public static final String RESPONSE_NAME = "invrsp";
/**
* This constant is used to identify invocation notifications sent to
* the client.
*/
public static final String NOTIFICATION_NAME = "invnot";
}
@@ -1,23 +1,13 @@
//
// $Id: TimeBaseCodes.java,v 1.1 2002/05/28 23:14:06 mdb Exp $
// $Id: TimeBaseCodes.java,v 1.2 2002/08/14 19:07:55 mdb Exp $
package com.threerings.presents.data;
/**
* Codes and constants relating to the Presents time base services.
*/
public interface TimeBaseCodes
public interface TimeBaseCodes extends InvocationCodes
{
/** The module name for the time services. */
public static final String MODULE_NAME = "time";
/** The message identifier for a request to obtain a particular time
* object. */
public static final String GET_TIME_OID_REQUEST = "GetTimeOid";
/** A response generated for a successful getTimeOid request. */
public static final String TIME_OID_RESPONSE = "TimeOid";
/** An error response generated for GetTimeOid requests. */
public static final String NO_SUCH_TIME_BASE = "m.no_such_time_base";
}
@@ -0,0 +1,67 @@
//
// $Id: TimeBaseMarshaller.java,v 1.1 2002/08/14 19:07:55 mdb Exp $
package com.threerings.presents.data;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.TimeBaseService;
import com.threerings.presents.client.TimeBaseService.GotTimeBaseListener;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.dobj.InvocationResponseEvent;
/**
* Provides the implementation of the {@link TimeBaseService} interface
* that marshalls the arguments and delivers the request to the provider
* on the server. Also provides an implementation of the response listener
* interfaces that marshall the response arguments and deliver them back
* to the requesting client.
*/
public class TimeBaseMarshaller extends InvocationMarshaller
implements TimeBaseService
{
// documentation inherited
public static class GotTimeBaseMarshaller extends ListenerMarshaller
implements GotTimeBaseListener
{
/** The method id used to dispatch {@link #gotTimeOid}
* responses. */
public static final int GOT_TIME_OID = 0;
// documentation inherited from interface
public void gotTimeOid (int arg1)
{
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, GOT_TIME_OID,
new Object[] { new Integer(arg1) }));
}
// documentation inherited
public void dispatchResponse (int methodId, Object[] args)
{
switch (methodId) {
case GOT_TIME_OID:
((GotTimeBaseListener)listener).gotTimeOid(
((Integer)args[0]).intValue());
return;
default:
super.dispatchResponse(methodId, args);
}
}
}
/** The method id used to dispatch {@link #getTimeOid} requests. */
public static final int GET_TIME_OID = 1;
// documentation inherited from interface
public void getTimeOid (Client arg1, String arg2, GotTimeBaseListener arg3)
{
GotTimeBaseMarshaller listener3 = new GotTimeBaseMarshaller();
listener3.listener = arg3;
sendRequest(arg1, GET_TIME_OID, new Object[] {
arg2, listener3
});
}
// Class file generated on 00:26:01 08/11/02.
}