Get the transport specification out of the construction path, since it's not a

streamed property of the event. It turns out to be cleaner to just set it in
the places where we know that we want a specific transport anyway.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6581 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2011-04-02 00:01:46 +00:00
parent 22330e955b
commit fc7706c79d
29 changed files with 73 additions and 121 deletions
@@ -52,10 +52,7 @@ public class AdminMarshaller extends InvocationMarshaller
// from interface ConfigInfoMarshaller
public void gotConfigInfo (String[] arg1, int[] arg2)
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, GOT_CONFIG_INFO,
new Object[] { arg1, arg2 }, transport));
sendResponse(GOT_CONFIG_INFO, new Object[] { arg1, arg2 });
}
@Override // from InvocationMarshaller
@@ -54,10 +54,7 @@ public class ChatMarshaller extends InvocationMarshaller
// from interface TellMarshaller
public void tellSucceeded (long arg1, String arg2)
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, TELL_SUCCEEDED,
new Object[] { Long.valueOf(arg1), arg2 }, transport));
sendResponse(TELL_SUCCEEDED, new Object[] { Long.valueOf(arg1), arg2 });
}
@Override // from InvocationMarshaller
@@ -52,10 +52,7 @@ public class LocationMarshaller extends InvocationMarshaller
// from interface MoveMarshaller
public void moveSucceeded (PlaceConfig arg1)
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, MOVE_SUCCEEDED,
new Object[] { arg1 }, transport));
sendResponse(MOVE_SUCCEEDED, new Object[] { arg1 });
}
@Override // from InvocationMarshaller
@@ -227,8 +227,8 @@ public class InvocationDirector
}
// create an invocation request event
InvocationRequestEvent event =
new InvocationRequestEvent(invOid, invCode, methodId, args, transport);
InvocationRequestEvent event = new InvocationRequestEvent(invOid, invCode, methodId, args);
event.setTransport(transport);
// because invocation directors are used on the server, we set the source oid here so that
// invocation requests are properly attributed to the right client object when created by
@@ -95,9 +95,7 @@ public class InvocationMarshaller
// documentation inherited from interface
public void requestFailed (String cause)
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, REQUEST_FAILED_RSPID, new Object[] { cause }, transport));
sendResponse(REQUEST_FAILED_RSPID, cause);
}
/**
@@ -134,6 +132,16 @@ public class InvocationMarshaller
}
}
/**
* Handles sending a response to our requester.
*/
protected void sendResponse (int methodId, Object... args)
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(callerOid, requestId, methodId, args).
setTransport(transport));
}
/**
* Performs type casts in a way that works for parameterized types as well as simple types.
*/
@@ -161,7 +169,8 @@ public class InvocationMarshaller
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, REQUEST_PROCESSED, null, transport));
callerOid, requestId, REQUEST_PROCESSED, null).
setTransport(transport));
}
@Override
@@ -192,7 +201,8 @@ public class InvocationMarshaller
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, REQUEST_PROCESSED, new Object[] { result }, transport));
callerOid, requestId, REQUEST_PROCESSED, new Object[] { result }).
setTransport(transport));
}
@Override
@@ -51,10 +51,7 @@ public class TimeBaseMarshaller extends InvocationMarshaller
// from interface GotTimeBaseMarshaller
public void gotTimeOid (int arg1)
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, GOT_TIME_OID,
new Object[] { Integer.valueOf(arg1) }, transport));
sendResponse(GOT_TIME_OID, new Object[] { Integer.valueOf(arg1) });
}
@Override // from InvocationMarshaller
@@ -25,8 +25,6 @@ import java.lang.reflect.Array;
import com.samskivert.util.StringUtil;
import com.threerings.presents.net.Transport;
/**
* An attribute changed event is dispatched when a single attribute of a distributed object has
* changed. It can also be constructed to request an attribute change on an object and posted to
@@ -151,12 +149,10 @@ public class AttributeChangedEvent extends NamedEvent
* @param name the name of the attribute (data member) that has changed.
* @param value the new value of the attribute (in the case of primitive types, the
* reflection-defined object-alternative is used).
* @param transport a hint as to the type of transport desired for the event.
*/
protected AttributeChangedEvent (
int targetOid, String name, Object value, Object oldValue, Transport transport)
protected AttributeChangedEvent (int targetOid, String name, Object value, Object oldValue)
{
super(targetOid, name, transport);
super(targetOid, name);
_value = value;
_oldValue = oldValue;
}
@@ -40,7 +40,7 @@ public class CompoundEvent extends DEvent
*/
public CompoundEvent (DObject target, DObjectManager omgr)
{
super(target.getOid(), Transport.DEFAULT);
super(target.getOid());
// sanity check
if (omgr == null) {
@@ -56,7 +56,7 @@ public class CompoundEvent extends DEvent
/** Used when unserializing. */
public CompoundEvent ()
{
super(0, Transport.DEFAULT);
super(0);
}
/**
@@ -143,12 +143,13 @@ public class CompoundEvent extends DEvent
}
@Override
public void setTransport (Transport transport)
public DEvent setTransport (Transport transport)
{
super.setTransport(transport);
for (int ii = 0, nn = _events.size(); ii < nn; ii++) {
_events.get(ii).setTransport(transport);
}
return this;
}
@Override
@@ -41,10 +41,9 @@ public abstract class DEvent implements Streamable
*
* @param transport a hint as to the type of transport desired for the event.
*/
public DEvent (int targetOid, Transport transport)
public DEvent (int targetOid)
{
_toid = targetOid;
_transport = transport;
}
/**
@@ -124,9 +123,10 @@ public abstract class DEvent implements Streamable
* mode of transport over which the event was received. When an event is sent over the
* network, these act as a hint as to the type of transport desired.
*/
public void setTransport (Transport transport)
public DEvent setTransport (Transport transport)
{
_transport = transport;
return this;
}
/**
@@ -558,7 +558,7 @@ public class DObject
*/
public void postMessage (Transport transport, String name, Object... args)
{
postEvent(new MessageEvent(_oid, name, args, transport));
postEvent(new MessageEvent(_oid, name, args).setTransport(transport));
}
/**
@@ -871,7 +871,7 @@ public class DObject
String name, Object value, Object oldValue, Transport transport)
{
// dispatch an attribute changed event
postEvent(new AttributeChangedEvent(_oid, name, value, oldValue, transport));
postEvent(new AttributeChangedEvent(_oid, name, value, oldValue).setTransport(transport));
}
/**
@@ -889,8 +889,8 @@ public class DObject
String name, int index, Object value, Object oldValue, Transport transport)
{
// dispatch an attribute changed event
postEvent(new ElementUpdatedEvent(
_oid, name, value, oldValue, index, transport));
postEvent(new ElementUpdatedEvent(_oid, name, value, oldValue, index).
setTransport(transport));
}
/**
@@ -989,7 +989,7 @@ public class DObject
}
}
// dispatch an entry updated event
postEvent(new EntryUpdatedEvent<T>(_oid, name, entry, oldEntry, transport));
postEvent(new EntryUpdatedEvent<T>(_oid, name, entry, oldEntry).setTransport(transport));
}
protected boolean isAuthoritative ()
@@ -26,8 +26,6 @@ import java.lang.reflect.Field;
import com.samskivert.util.StringUtil;
import com.threerings.presents.net.Transport;
/**
* An element updated event is dispatched when an element of an array field in a distributed object
* is updated. It can also be constructed to request the update of an entry and posted to the
@@ -48,12 +46,10 @@ public class ElementUpdatedEvent extends NamedEvent
* @param ovalue the previous value of the element (in the case of primitive types, the
* reflection-defined object-alternative is used).
* @param index the index in the array of the updated element.
* @param transport a hint as to the type of transport desired for the event.
*/
public ElementUpdatedEvent (
int targetOid, String name, Object value, Object ovalue, int index, Transport transport)
public ElementUpdatedEvent (int targetOid, String name, Object value, Object ovalue, int index)
{
super(targetOid, name, transport);
super(targetOid, name);
_value = value;
_oldValue = ovalue;
_index = index;
@@ -23,8 +23,6 @@ package com.threerings.presents.dobj;
import com.samskivert.util.StringUtil;
import com.threerings.presents.net.Transport;
/**
* An entry added event is dispatched when an entry is added to a {@link DSet} attribute of a
* distributed entry. It can also be constructed to request the addition of an entry to a set and
@@ -47,7 +45,7 @@ public class EntryAddedEvent<T extends DSet.Entry> extends EntryEvent<T>
*/
public EntryAddedEvent (int targetOid, String name, T entry)
{
super(targetOid, name, Transport.DEFAULT);
super(targetOid, name);
_entry = entry;
}
@@ -21,8 +21,6 @@
package com.threerings.presents.dobj;
import com.threerings.presents.net.Transport;
/**
* A common parent class for DSet entry events.
*/
@@ -33,11 +31,10 @@ public abstract class EntryEvent<T extends DSet.Entry> extends NamedEvent
*
* @param targetOid the object id of the object in question.
* @param name the name associated with this event.
* @param transport a hint as to the type of transport desired for the event.
*/
public EntryEvent (int targetOid, String name, Transport transport)
public EntryEvent (int targetOid, String name)
{
super(targetOid, name, transport);
super(targetOid, name);
}
/**
@@ -21,8 +21,6 @@
package com.threerings.presents.dobj;
import com.threerings.presents.net.Transport;
import static com.threerings.presents.Log.log;
/**
@@ -48,7 +46,7 @@ public class EntryRemovedEvent<T extends DSet.Entry> extends EntryEvent<T>
*/
public EntryRemovedEvent (int targetOid, String name, Comparable<?> key, T oldEntry)
{
super(targetOid, name, Transport.DEFAULT);
super(targetOid, name);
_key = key;
_oldEntry = oldEntry;
}
@@ -23,8 +23,6 @@ package com.threerings.presents.dobj;
import com.samskivert.util.StringUtil;
import com.threerings.presents.net.Transport;
import static com.threerings.presents.Log.log;
/**
@@ -46,11 +44,10 @@ public class EntryUpdatedEvent<T extends DSet.Entry> extends EntryEvent<T>
* @param name the name of the attribute in which to update the specified entry.
* @param entry the entry to update.
* @param oldEntry the previous value of the entry.
* @param transport a hint as to the type of transport desired for the event.
*/
public EntryUpdatedEvent (int targetOid, String name, T entry, T oldEntry, Transport transport)
public EntryUpdatedEvent (int targetOid, String name, T entry, T oldEntry)
{
super(targetOid, name, transport);
super(targetOid, name);
_entry = entry;
_oldEntry = oldEntry;
}
@@ -23,8 +23,6 @@ package com.threerings.presents.dobj;
import com.samskivert.util.StringUtil;
import com.threerings.presents.net.Transport;
/**
* Used to dispatch an invocation notification from the server to a client.
*
@@ -41,12 +39,10 @@ public class InvocationNotificationEvent extends DEvent
* @param methodId the id of the method to be invoked.
* @param args the arguments for the method. This array should contain only values of valid
* distributed object types.
* @param transport a hint as to the type of transport desired for the event.
*/
public InvocationNotificationEvent (
int targetOid, short receiverId, int methodId, Object[] args, Transport transport)
public InvocationNotificationEvent (int targetOid, short receiverId, int methodId, Object[] args)
{
super(targetOid, transport);
super(targetOid);
_receiverId = receiverId;
_methodId = (byte)methodId;
_args = args;
@@ -23,8 +23,6 @@ package com.threerings.presents.dobj;
import com.samskivert.util.StringUtil;
import com.threerings.presents.net.Transport;
/**
* Used to dispatch an invocation request from the client to the server.
*
@@ -41,12 +39,10 @@ public class InvocationRequestEvent extends DEvent
* @param methodId the id of the method to be invoked.
* @param args the arguments for the method. This array should contain only values of valid
* distributed object types.
* @param transport a hint as to the type of transport desired for the event.
*/
public InvocationRequestEvent (
int targetOid, int invCode, int methodId, Object[] args, Transport transport)
public InvocationRequestEvent (int targetOid, int invCode, int methodId, Object[] args)
{
super(targetOid, transport);
super(targetOid);
_invCode = invCode;
_methodId = (byte)methodId;
_args = args;
@@ -22,7 +22,6 @@
package com.threerings.presents.dobj;
import com.samskivert.util.StringUtil;
import com.threerings.presents.net.Transport;
/**
@@ -41,17 +40,23 @@ public class InvocationResponseEvent extends DEvent
* @param methodId the method to be invoked.
* @param args the arguments for the method. This array should contain only values of valid
* distributed object types.
* @param transport a hint as to the type of transport desired for the event.
*/
public InvocationResponseEvent (
int targetOid, int requestId, int methodId, Object[] args, Transport transport)
public InvocationResponseEvent (int targetOid, int requestId, int methodId, Object[] args)
{
super(targetOid, transport);
super(targetOid);
_requestId = (short)requestId;
_methodId = (byte)methodId;
_args = args;
}
/** @deprecated Regenerate your services. */
@Deprecated
public InvocationResponseEvent (int targetOid, int requestId, int methodId, Object[] args,
Transport transport)
{
this(targetOid, requestId, methodId, args);
}
/**
* Returns the invocation request id associated with this response.
*/
@@ -23,8 +23,6 @@ package com.threerings.presents.dobj;
import com.samskivert.util.StringUtil;
import com.threerings.presents.net.Transport;
/**
* A message event is used to dispatch a message to all subscribers of a distributed object without
* actually changing any of the fields of the object. A message has a name, by which different
@@ -43,11 +41,10 @@ public class MessageEvent extends NamedEvent
* @param name the name of the message event.
* @param args the arguments for this message. This array should contain only values of valid
* distributed object types.
* @param transport a hint as to the type of transport desired for the event.
*/
public MessageEvent (int targetOid, String name, Object[] args, Transport transport)
public MessageEvent (int targetOid, String name, Object[] args)
{
super(targetOid, name, transport);
super(targetOid, name);
_args = args;
}
@@ -21,8 +21,6 @@
package com.threerings.presents.dobj;
import com.threerings.presents.net.Transport;
/**
* A common parent class for all events that are associated with a name
* (in some cases a field name, in other cases just an identifying name).
@@ -35,11 +33,10 @@ public abstract class NamedEvent extends DEvent
*
* @param targetOid the object id of the object in question.
* @param name the name associated with this event.
* @param transport a hint as to the type of transport desired for the event.
*/
public NamedEvent (int targetOid, String name, Transport transport)
public NamedEvent (int targetOid, String name)
{
super(targetOid, transport);
super(targetOid);
_name = name;
}
@@ -21,8 +21,6 @@
package com.threerings.presents.dobj;
import com.threerings.presents.net.Transport;
/**
* An object added event is dispatched when an object is added to an <code>OidList</code> attribute
* of a distributed object. It can also be constructed to request the addition of an oid to an
@@ -42,7 +40,7 @@ public class ObjectAddedEvent extends NamedEvent
*/
public ObjectAddedEvent (int targetOid, String name, int oid)
{
super(targetOid, name, Transport.DEFAULT);
super(targetOid, name);
_oid = oid;
}
@@ -21,8 +21,6 @@
package com.threerings.presents.dobj;
import com.threerings.presents.net.Transport;
/**
* An object destroyed event is dispatched when an object has been removed
* from the distributed object system. It can also be constructed to
@@ -39,7 +37,7 @@ public class ObjectDestroyedEvent extends DEvent
*/
public ObjectDestroyedEvent (int targetOid)
{
super(targetOid, Transport.DEFAULT);
super(targetOid);
}
@Override
@@ -21,8 +21,6 @@
package com.threerings.presents.dobj;
import com.threerings.presents.net.Transport;
/**
* An object removed event is dispatched when an object is removed from an <code>OidList</code>
* attribute of a distributed object. It can also be constructed to request the removal of an oid
@@ -42,7 +40,7 @@ public class ObjectRemovedEvent extends NamedEvent
*/
public ObjectRemovedEvent (int targetOid, String name, int oid)
{
super(targetOid, name, Transport.DEFAULT);
super(targetOid, name);
_oid = oid;
}
@@ -21,8 +21,6 @@
package com.threerings.presents.dobj;
import com.threerings.presents.net.Transport;
/**
* A release lock event is dispatched at the end of a chain of events to release a lock that is
* intended to prevent some application defined activity from happening until those events have
@@ -44,7 +42,7 @@ public class ReleaseLockEvent extends NamedEvent
*/
public ReleaseLockEvent (int targetOid, String name)
{
super(targetOid, name, Transport.DEFAULT);
super(targetOid, name);
}
@Override
@@ -21,8 +21,6 @@
package com.threerings.presents.dobj;
import com.threerings.presents.net.Transport;
/**
* A message event that only goes to the server. If generated on the server then it never leaves
* the server.
@@ -40,7 +38,7 @@ public class ServerMessageEvent extends MessageEvent
*/
public ServerMessageEvent (int targetOid, String name, Object[] args)
{
super(targetOid, name, args, Transport.DEFAULT);
super(targetOid, name, args);
}
@Override
@@ -63,9 +63,9 @@ public abstract class InvocationSender
// "methodId", methodId, "args", args);
// create and dispatch an invocation notification event
target.postEvent(
new InvocationNotificationEvent(
target.getOid(), rreg.receiverId, methodId, args, transport));
target.postEvent(new InvocationNotificationEvent(
target.getOid(), rreg.receiverId, methodId, args).
setTransport(transport));
}
}
}
@@ -53,7 +53,6 @@ import com.threerings.presents.dobj.ObjectRemovedEvent;
import com.threerings.presents.dobj.OidList;
import com.threerings.presents.dobj.RootDObjectManager;
import com.threerings.presents.dobj.Subscriber;
import com.threerings.presents.net.Transport;
import static com.threerings.presents.Log.log;
@@ -927,7 +926,7 @@ public class PresentsDObjectMgr
public AccessObjectEvent (int oid, Subscriber<T> target, int action)
{
super(DUMMY_OID, Transport.DEFAULT); // target the bogus object
super(DUMMY_OID); // target the bogus object
_oid = oid;
_target = target;
_action = action;
@@ -32,10 +32,7 @@ public class {{name}}Marshaller extends InvocationMarshaller
// from interface {{listenerName}}Marshaller
public void {{method.name}} ({{getArgList}})
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, {{code}},
new Object[] { {{getWrappedArgList}} }, transport));
sendResponse({{code}}, new Object[] { {{getWrappedArgList}} });
}
{{/methods}}
@@ -53,10 +53,7 @@ public class TestMarshaller extends InvocationMarshaller
// from interface TestFuncMarshaller
public void testSucceeded (String arg1, int arg2)
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, TEST_SUCCEEDED,
new Object[] { arg1, Integer.valueOf(arg2) }, transport));
sendResponse(TEST_SUCCEEDED, new Object[] { arg1, Integer.valueOf(arg2) });
}
@Override // from InvocationMarshaller
@@ -88,10 +85,7 @@ public class TestMarshaller extends InvocationMarshaller
// from interface TestOidMarshaller
public void gotTestOid (int arg1)
{
_invId = null;
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, GOT_TEST_OID,
new Object[] { Integer.valueOf(arg1) }, transport));
sendResponse(GOT_TEST_OID, new Object[] { Integer.valueOf(arg1) });
}
@Override // from InvocationMarshaller