More work on things.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3900 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
package com.threerings.presents.client {
|
||||
|
||||
import mx.collections.IViewCursor;
|
||||
import mx.collections.ListCollectionView;
|
||||
|
||||
import com.threerings.util.SimpleMap;
|
||||
|
||||
import com.threerings.presents.data.ListenerMarshaller;
|
||||
|
||||
import com.threerings.presents.dobj.DEvent;
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
import com.threerings.presents.dobj.DObjectManager;
|
||||
import com.threerings.presents.dobj.DSet;
|
||||
import com.threerings.presents.dobj.EventListener;
|
||||
import com.threerings.presents.dobj.InvocationRequestEvent;
|
||||
import com.threerings.presents.dobj.ObjectAccessError;
|
||||
import com.threerings.presents.dobj.Subscriber;
|
||||
|
||||
@@ -31,9 +39,12 @@ public class InvocationDirector
|
||||
|
||||
public function cleanup () :void
|
||||
{
|
||||
// wipe our client object, receiver mappings and listener mappings
|
||||
_clobj = null;
|
||||
|
||||
// TODO: lots more
|
||||
// also reset our counters
|
||||
_requestId = 0;
|
||||
_receiverId = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +53,7 @@ public class InvocationDirector
|
||||
*/
|
||||
public function registerReceiver (decoder :InvocationDecoder) :void
|
||||
{
|
||||
_reclist.push(decoder);
|
||||
_reclist.addItem(decoder);
|
||||
|
||||
// if we're already online, assign a recevier id now
|
||||
if (_clobj != null) {
|
||||
@@ -50,10 +61,36 @@ public class InvocationDirector
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited from interface EventListener
|
||||
public function eventReceived (event :DEvent) :void
|
||||
/**
|
||||
* Removes a receiver registration.
|
||||
*/
|
||||
public function unregisterReceiver (receiverCode :String) :void
|
||||
{
|
||||
// TODO
|
||||
// remove the receiver from the list
|
||||
for (var iter :IViewCursor = _reclist.getCursor(); iter.moveNext(); ) {
|
||||
var decoder :InvocationDecoder =
|
||||
(iter.current as InvocationDecoder);
|
||||
if (decoder.getReceiverCode() === receiverCode) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// if we're logged on, clear out any receiver id mapping
|
||||
if (_clobj != null) {
|
||||
var rreg :InvocationRegistration =
|
||||
(_clobj.receivers.getByKey(receiverCode)
|
||||
as InvocationRegistration);
|
||||
if (rreg == null) {
|
||||
Log.warning("Receiver unregistered for which we have no " +
|
||||
"id to code mapping [code=" + receiverCode + "].");
|
||||
} else {
|
||||
var decoder :Object = _receivers.remove(rreg.receiverId);
|
||||
// Log.info("Cleared receiver " +
|
||||
// StringUtil.shortClassName(decoder) +
|
||||
// " " + rreg + ".");
|
||||
}
|
||||
_clobj.removeFromReceivers(receiverCode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +99,10 @@ public class InvocationDirector
|
||||
*/
|
||||
internal function assignReceiverId (decoder :InvocationDecoder) :void
|
||||
{
|
||||
// TODO
|
||||
var reg :InvocationRegistration = new InvocationRegistration(
|
||||
decoder.getReceiverCode(), nextReceiverId());
|
||||
_clobj.addToReceivers(reg);
|
||||
_receivers[reg.receiverId] = decoder;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +121,63 @@ public class InvocationDirector
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the specified invocation request be packaged up and
|
||||
* sent to the supplied invocation oid.
|
||||
*/
|
||||
public function sendRequest (
|
||||
invOid :int, invCode :int, methodId :int, args :Array) :void
|
||||
{
|
||||
// configure any invocation listener marshallers among the args
|
||||
for each (var arg :Object in args) {
|
||||
if (arg is ListenerMarshaller) {
|
||||
var lm :ListenerMarshaller = (arg as ListenerMarshaller);
|
||||
lm.callerOid = _clobj.getOid();
|
||||
lm.requestId = nextRequestId();
|
||||
lm.mapStamp = new Date().getTime();
|
||||
|
||||
// create a mapping for this marshaller so that we can
|
||||
// properly dispatch responses sent to it
|
||||
_listeners[lm.requestId] = lm;
|
||||
}
|
||||
}
|
||||
|
||||
// create an invocation request event
|
||||
var event :InvocationRequestEvent =
|
||||
new InvocationRequestEvent(invOid, invCode, methodId, args);
|
||||
|
||||
// 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
|
||||
// server-side entities only sort of pretending to be a client
|
||||
event.setSourceOid(_clobj.getOid());
|
||||
|
||||
// now, dispatch the event
|
||||
_omgr.postEvent(event);
|
||||
}
|
||||
|
||||
// documentation inherited from interface EventListener
|
||||
public function eventReceived (event :DEvent) :void
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to generate monotonically increasing invocation request ids.
|
||||
*/
|
||||
protected function nextRequestId () :int
|
||||
{
|
||||
return _requestId++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to generate monotonically increasing invocation receiver ids.
|
||||
*/
|
||||
protected function nextReceiverId () :int
|
||||
{
|
||||
return _receiverId++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the ClientSubscriber helper class when the client object
|
||||
* has been returned by the server.
|
||||
@@ -106,15 +203,32 @@ public class InvocationDirector
|
||||
_client.getClientObjectFailed(cause);
|
||||
}
|
||||
|
||||
/** The distributed object manager with which we interact. */
|
||||
internal var _omgr :DObjectManager;
|
||||
|
||||
/** The client for whom we're working. */
|
||||
internal var _client :Client;
|
||||
|
||||
/** Our client object; invocation responses and notifications are
|
||||
* received on this object. */
|
||||
internal var _clobj :ClientObject;
|
||||
|
||||
/** Used to generate monotonically increasing request ids. */
|
||||
protected var _requestId :int;
|
||||
|
||||
/** Used to generate monotonically increasing receiver ids. */
|
||||
protected var _receiverId :int;
|
||||
|
||||
/** Used to keep track of invocation service listeners which will
|
||||
* receive responses from invocation service requests. */
|
||||
protected var _listeners :SimpleMap = new SimpleMap();
|
||||
|
||||
/** Used to keep track of invocation notification receivers. */
|
||||
protected var _receivers :SimpleMap = new SimpleMap();
|
||||
|
||||
/** All registered receivers are maintained in a list so that we can
|
||||
* assign receiver ids to them when we go online. */
|
||||
internal var _reclist :Array = new Array();
|
||||
internal var _reclist :ListCollectionView = new ListCollectionView();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user