Much work on generalizing the notion of message "transport" and

allowing the use of annotations to customize transport for 
DObject fields and service/receiver methods.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5099 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2008-05-16 01:47:33 +00:00
parent e279133868
commit ee74481cad
39 changed files with 864 additions and 123 deletions
@@ -42,6 +42,8 @@ import com.threerings.presents.dobj.InvocationRequestEvent;
import com.threerings.presents.dobj.ObjectAccessException;
import com.threerings.presents.dobj.RootDObjectManager;
import com.threerings.presents.net.Transport;
/**
* The invocation services provide client to server invocations (service requests) and server to
* client invocations (responses and notifications). Via this mechanism, the client can make
@@ -183,7 +185,7 @@ public class InvocationManager
/**
* Get the class that is being used to dispatch the specified
* invocation code, for informational purposes.
*
*
* @return the Class, or null if no dispatcher is registered with
* the specified code.
*/
@@ -201,7 +203,7 @@ public class InvocationManager
if (event instanceof InvocationRequestEvent) {
InvocationRequestEvent ire = (InvocationRequestEvent)event;
dispatchRequest(ire.getSourceOid(), ire.getInvCode(),
ire.getMethodId(), ire.getArgs());
ire.getMethodId(), ire.getArgs(), ire.getTransport());
}
}
@@ -211,7 +213,7 @@ public class InvocationManager
* registered invocation dispatcher.
*/
protected void dispatchRequest (
int clientOid, int invCode, int methodId, Object[] args)
int clientOid, int invCode, int methodId, Object[] args, Transport transport)
{
// make sure the client is still around
ClientObject source = (ClientObject)_omgr.getObject(clientOid);
@@ -243,6 +245,7 @@ public class InvocationManager
if (arg instanceof ListenerMarshaller) {
ListenerMarshaller list = (ListenerMarshaller)arg;
list.omgr = _omgr;
list.transport = transport;
// keep track of the listener we'll inform if anything
// goes horribly awry
if (rlist == null) {
@@ -28,6 +28,8 @@ import com.threerings.presents.client.InvocationReceiver.Registration;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.dobj.InvocationNotificationEvent;
import com.threerings.presents.net.Transport;
/**
* Provides basic functionality used by all invocation sender classes.
*/
@@ -39,6 +41,16 @@ public abstract class InvocationSender
*/
public static void sendNotification (
ClientObject target, String receiverCode, int methodId, Object[] args)
{
sendNotification(target, receiverCode, methodId, args, Transport.DEFAULT);
}
/**
* Requests that the specified invocation notification be packaged up and sent to the supplied
* target client.
*/
public static void sendNotification (
ClientObject target, String receiverCode, int methodId, Object[] args, Transport transport)
{
// convert the receiver hash id into the code used on this
// specific client
@@ -55,7 +67,8 @@ public abstract class InvocationSender
// create and dispatch an invocation notification event
target.postEvent(
new InvocationNotificationEvent(target.getOid(), rreg.receiverId, methodId, args));
new InvocationNotificationEvent(
target.getOid(), rreg.receiverId, methodId, args, transport));
}
}
}
@@ -267,7 +267,7 @@ public class PresentsClient
* does it in the existing client object. Care must be taken to ensure that any client or
* server code either doesn't map things based on username before this call, or that it's
* updated to reflect the change.
*
*
* @return - true if the client was successfully renamed, false otherwise
*/
public boolean updateUsername (Name username)
@@ -978,11 +978,9 @@ public class PresentsClient
{
public void dispatch (PresentsClient client, UpstreamMessage msg)
{
// send a pong response
// send a pong response using the transport with which the message was received
PingRequest req = (PingRequest)msg;
PongResponse resp = new PongResponse(req.getUnpackStamp());
resp.datagram = req.datagram;
client.safePostMessage(resp);
client.safePostMessage(new PongResponse(req.getUnpackStamp(), req.getTransport()));
}
}
@@ -376,7 +376,6 @@ public abstract class Connection implements NetEventHandler
return; // received out of order
}
msg.received = when;
msg.datagram = true;
_handler.handleMessage(msg);
} catch (ClassNotFoundException cnfe) {
@@ -850,7 +850,7 @@ public class ConnectionManager extends LoopingThread
try {
// send it as a datagram if hinted and possible
if (msg.datagram && conn.getDatagramAddress() != null) {
if (!msg.getTransport().isReliable() && conn.getDatagramAddress() != null) {
postDatagram(conn, msg);
return;
}