Got compiling working under Linux, now correcting various errors.

Checkpoint.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3866 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-02-20 02:38:56 +00:00
parent f8c8f6e983
commit 7a80c5cb43
41 changed files with 453 additions and 141 deletions
+8
View File
@@ -80,3 +80,11 @@ Notes
I will play around with trying to just use a Timer with a 1ms interval, I will play around with trying to just use a Timer with a 1ms interval,
and see if the frequency is limited to the actual framerate. and see if the frequency is limited to the actual framerate.
- All methods must be marked with the 'override' keyword if they override
a method in their parent, except for toString(), even though it's defined
for Object. Ya got me...
- 'protected' doesn't mean the same thing in ActionScript: it means that
ONLY subclasses can access a field/method, other classes in the same
package cannot access it.
@@ -92,7 +92,7 @@ public class ObjectInputStream
} }
_current = obj; _current = obj;
_streamer = steamer; _streamer = streamer;
try { try {
_streamer.readObject(obj, this); _streamer.readObject(obj, this);
@@ -134,13 +134,13 @@ public class ObjectInputStream
} }
public function readBytes (bytes :ByteArray, offset :uint = 0, public function readBytes (bytes :ByteArray, offset :uint = 0,
length :uint = undefined) :void length :uint = 0) :void
//throws IOError //throws IOError
{ {
// IDataInput reads all available bytes if a length is not passed // IDataInput reads all available bytes if a length is not passed
// in. Protect against an easy error to make by using the length of // in. Protect against an easy error to make by using the length of
// the array // the array
if (length === undefined) { if (length === 0) {
length = bytes.length; length = bytes.length;
} }
_source.readBytes(bytes, offset, length); _source.readBytes(bytes, offset, length);
@@ -1,5 +1,7 @@
package com.threerings.io { package com.threerings.io {
import flash.util.trace;
import flash.util.ByteArray; import flash.util.ByteArray;
import flash.util.IDataOutput; import flash.util.IDataOutput;
+2
View File
@@ -1,5 +1,7 @@
package com.threerings.io { package com.threerings.io {
import flash.util.trace;
import flash.util.ByteArray; import flash.util.ByteArray;
import com.threerings.util.SimpleMap; import com.threerings.util.SimpleMap;
@@ -1,5 +1,7 @@
package com.threerings.presents.client { package com.threerings.presents.client {
import flash.util.trace;
import flash.events.EventDispatcher; import flash.events.EventDispatcher;
import flash.events.TimerEvent; import flash.events.TimerEvent;
import flash.util.Timer; import flash.util.Timer;
@@ -65,6 +67,11 @@ public class Client extends EventDispatcher
return _authData; return _authData;
} }
public function setAuthResponseData (data :AuthResponseData) :void
{
_authData = data;
}
public function getDObjectManager () :DObjectManager public function getDObjectManager () :DObjectManager
{ {
return _omgr; return _omgr;
@@ -216,7 +223,7 @@ public class Client extends EventDispatcher
notifyObservers(ClientEvent.CLIENT_OBJECT_CHANGED); notifyObservers(ClientEvent.CLIENT_OBJECT_CHANGED);
} }
protected function cleanup (logonError :Error) :void internal function cleanup (logonError :Error) :void
{ {
// clear out our references // clear out our references
_comm = null; _comm = null;
@@ -238,7 +245,7 @@ public class Client extends EventDispatcher
/** /**
* Called by the omgr when we receive a pong packet. * Called by the omgr when we receive a pong packet.
*/ */
protected function gotPong (pong :PongResponse) :void public function gotPong (pong :PongResponse) :void
{ {
// TODO: compute time delta bowl-shit // TODO: compute time delta bowl-shit
} }
@@ -247,7 +254,7 @@ public class Client extends EventDispatcher
* Convenience method to dispatch a client event to any listeners * Convenience method to dispatch a client event to any listeners
* and return the result of dispatchEvent. * and return the result of dispatchEvent.
*/ */
protected function notifyObservers (evtCode :String, cause :Error = null) public function notifyObservers (evtCode :String, cause :Error = null)
:Boolean :Boolean
{ {
return dispatchEvent(new ClientEvent(evtCode, this, cause)); return dispatchEvent(new ClientEvent(evtCode, this, cause));
@@ -24,12 +24,27 @@ package com.threerings.presents.client {
import flash.events.TimerEvent; import flash.events.TimerEvent;
import flash.util.Timer; import flash.util.Timer;
import flash.util.trace;
import mx.collections.IList; import mx.collections.IList;
import com.threerings.util.ClassUtil;
import com.threerings.util.SimpleMap; import com.threerings.util.SimpleMap;
import com.threerings.presents.dobj.DEvent;
import com.threerings.presents.dobj.DObject; import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DObjectManager; import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.dobj.ObjectDestroyedEvent;
import com.threerings.presents.dobj.Subscriber;
import com.threerings.presents.net.BootstrapNotification;
import com.threerings.presents.net.EventNotification;
import com.threerings.presents.net.DownstreamMessage;
import com.threerings.presents.net.FailureResponse;
import com.threerings.presents.net.ForwardEventRequest;
import com.threerings.presents.net.ObjectResponse;
import com.threerings.presents.net.PongResponse;
import com.threerings.presents.net.UnsubscribeResponse;
/** /**
* The client distributed object manager manages a set of proxy objects * The client distributed object manager manages a set of proxy objects
@@ -202,7 +217,7 @@ public class ClientDObjectMgr
notifyFailure(oid); notifyFailure(oid);
} else if (obj is PongResponse) { } else if (obj is PongResponse) {
_client.gotPong(obj); _client.gotPong(obj as PongResponse);
} else if (obj is ObjectAction) { } else if (obj is ObjectAction) {
var act :ObjectAction = (obj as ObjectAction); var act :ObjectAction = (obj as ObjectAction);
@@ -223,7 +238,7 @@ public class ClientDObjectMgr
// if this is a compound event, we need to process its contained // if this is a compound event, we need to process its contained
// events in order // events in order
if (event is CompoundEvent) { if (event is CompoundEvent) {
var events :IList = event.getEvents(); var events :IList = (event as CompoundEvent).getEvents();
var ecount :int = events.length; var ecount :int = events.length;
for (var ii :int = 0; ii < ecount; ii++) { for (var ii :int = 0; ii < ecount; ii++) {
dispatchEvent(events.getItemAt(ii)); dispatchEvent(events.getItemAt(ii));
@@ -404,7 +419,7 @@ public class ClientDObjectMgr
var rec :FlushRecord = _flushes[oid]; var rec :FlushRecord = _flushes[oid];
if (rec.expire <= now) { if (rec.expire <= now) {
_flushes[oid] = undefined; _flushes[oid] = undefined;
flushObject(rec.object); flushObject(rec.obj);
} }
} }
} }
@@ -436,7 +451,7 @@ public class ClientDObjectMgr
/** Flushes objects every now and again. */ /** Flushes objects every now and again. */
protected var _flushInterval :Timer; protected var _flushInterval :Timer;
protected var _flushInterval :Timer; protected var _actionInterval :Timer;
/** Flush expired objects every 30 seconds. */ /** Flush expired objects every 30 seconds. */
protected static const FLUSH_INTERVAL :Number = 30 * 1000; protected static const FLUSH_INTERVAL :Number = 30 * 1000;
@@ -447,27 +462,27 @@ public class ClientDObjectMgr
* The object action is used to queue up a subscribe or unsubscribe * The object action is used to queue up a subscribe or unsubscribe
* request. * request.
*/ */
protected class ObjectAction class ObjectAction
{ {
public var oid :int; public var oid :int;
public var target :Subscriber; public var target :com.threerings.presents.dobj.Subscriber;
public var subscribe :Boolean; public var subscribe :Boolean;
public function ObjectAction ( public function ObjectAction (
oid :int, target :Subscriber, subscribe :Boolean) oid :int, target :com.threerings.presents.dobj.Subscriber, subscribe :Boolean)
{ {
this.oid = oid; this.oid = oid;
this.target = target; this.target = target;
this.subscribe = subscribe; this.subscribe = subscribe;
} }
public override function toString () :String public function toString () :String
{ {
return "oid=" + oid + ", target=" + target + ", subscribe=" + subscribe; return "oid=" + oid + ", target=" + target + ", subscribe=" + subscribe;
} }
} }
protected class PendingRequest class PendingRequest
{ {
public var oid :int; public var oid :int;
public var targets :Array = new Array(); public var targets :Array = new Array();
@@ -477,24 +492,24 @@ protected class PendingRequest
this.oid = oid; this.oid = oid;
} }
public function addTarget (target :Subscriber) :void public function addTarget (target :com.threerings.presents.dobj.Subscriber) :void
{ {
targets.push(target); targets.push(target);
} }
} }
/** Used to manage pending object flushes. */ /** Used to manage pending object flushes. */
protected class FlushRecord class FlushRecord
{ {
/** The object to be flushed. */ /** The object to be flushed. */
public var obj :DObject; public var obj :com.threerings.presents.dobj.DObject;
/** The time at which we flush it. */ /** The time at which we flush it. */
public var expire :Number; public var expire :Number;
public function FlushRecord (obj :DObject, expire :Number) public function FlushRecord (obj :com.threerings.presents.dobj.DObject, expire :Number)
{ {
this.object = object; this.obj = obj;
this.expire = expire; this.expire = expire;
} }
} }
@@ -1,5 +1,10 @@
package com.threerings.presents.client { package com.threerings.presents.client {
import flash.util.trace;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.Socket; import flash.net.Socket;
import flash.util.ByteArray; import flash.util.ByteArray;
@@ -10,6 +15,13 @@ import com.threerings.io.FrameReader;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
import com.threerings.presents.net.AuthRequest;
import com.threerings.presents.net.AuthResponse;
import com.threerings.presents.net.AuthResponseData;
import com.threerings.presents.net.DownstreamMessage;
import com.threerings.presents.net.LogoffRequest;
import com.threerings.presents.net.UpstreamMessage;
public class Communicator public class Communicator
{ {
public function Communicator (client :Client) public function Communicator (client :Client)
@@ -50,6 +62,11 @@ public class Communicator
shutdown(null); shutdown(null);
} }
public function postMessage (msg :UpstreamMessage) :void
{
sendMessage(msg); // send it now: we have no out queue (TODO?)
}
protected function shutdown (logonError :Error) :void protected function shutdown (logonError :Error) :void
{ {
if (_socket != null) { if (_socket != null) {
@@ -132,7 +149,7 @@ public class Communicator
// logon success // logon success
_omgr = new ClientDObjectMgr(this, _client); _omgr = new ClientDObjectMgr(this, _client);
_client._authData = data; _client.setAuthResponseData(data);
} }
/** /**
@@ -160,17 +177,18 @@ public class Communicator
*/ */
protected function socketClosed (event :Event) :void protected function socketClosed (event :Event) :void
{ {
_client.notifyObserver(ClientEvent.CLIENT_CONNECTION_FAILED); _client.notifyObservers(ClientEvent.CLIENT_CONNECTION_FAILED);
shutdown(null); shutdown(null);
} }
protected var _client :Client; protected var _client :Client;
protected var _omgr :ClientDObjectManager; protected var _omgr :ClientDObjectMgr;
protected var _outBuffer :ByteArray; protected var _outBuffer :ByteArray;
protected var _outStream :ObjectOutputStream; protected var _outStream :ObjectOutputStream;
protected var _inStream :ObjectInputStream; protected var _inStream :ObjectInputStream;
protected var _frameReader :FrameReader;
protected var _socket :Socket; protected var _socket :Socket;
@@ -1,7 +1,11 @@
package com.threerings.presents.client { package com.threerings.presents.client {
import flash.util.trace;
import com.threerings.presents.dobj.DObjectManager; import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.data.ClientObject;
public class InvocationDirector public class InvocationDirector
{ {
public function init (omgr :DObjectManager, cloid :int, client :Client) :void public function init (omgr :DObjectManager, cloid :int, client :Client) :void
@@ -0,0 +1,129 @@
//
// $Id: InvocationService.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.presents.client {
/**
* Serves as the base interface for invocation services. An invocation
* service can be defined by extending this interface and defining service
* methods, as well as response listeners (which must extend {@link
* InvocationListener}). For example:
*
* <pre>
* public interface LocationService extends InvocationService
* {
*
* // Used to communicate responses to moveTo() requests.
* public interface MoveListener extends InvocationListener
* {
* // Called in response to a successful moveTo() request.
* public void moveSucceeded (PlaceConfig config);
* }
*
* // Requests that this client's body be moved to the specified
* // location.
* //
* // @param placeId the object id of the place object to which the
* // body should be moved.
* // @param listener the listener that will be informed of success or
* // failure.
* public void moveTo (int placeId, MoveListener listener);
* }
* </pre>
*
* From this interface, a <code>LocationProvider</code> interface will be
* generated which should be implemented by whatever server entity that
* will actually provide the server side of this invocation service. That
* provider interface would look like the following:
*
* <pre>
* public interface LocationProvider extends InvocationProvider
* {
* // Requests that this client's body be moved to the specified
* // location.
* //
* // @param caller the client object of the client that invoked this
* // remotely callable method.
* // @param placeId the object id of the place object to which the
* // body should be moved.
* // @param listener the listener that should be informed of success
* // or failure.
* public void moveTo (ClientObject caller, int placeId,
* MoveListener listener)
* throws InvocationException;
* }
* </pre>
*/
public interface InvocationService
{
/**
* Invocation service methods that require a response should take a
* listener argument that can be notified of request success or
* failure. The listener argument should extend this interface so that
* generic failure can be reported in all cases. For example:
*
* <pre>
* // Used to communicate responses to <code>moveTo</code> requests.
* public interface MoveListener extends InvocationListener
* {
* // Called in response to a successful <code>moveTo</code>
* // request.
* public void moveSucceeded (PlaceConfig config);
* }
* </pre>
*/
// public static interface InvocationListener
// {
/**
* Called to report request failure. If the invocation services
* system detects failure of any kind, it will report it via this
* callback. Particular services may also make use of this
* callback to report failures of their own, or they may opt to
* define more specific failure callbacks.
*/
// public void requestFailed (String cause);
// }
/**
* Extends the {@link InvocationListener} with a basic success
* callback.
*/
// public static interface ConfirmListener extends InvocationListener
// {
/**
* Indicates that the request was successfully processed.
*/
// public void requestProcessed ();
// }
/**
* Extends the {@link InvocationListener} with a basic success
* callback that delivers a result object.
*/
// public static interface ResultListener extends InvocationListener
// {
/**
* Indicates that the request was successfully processed.
*/
// public void requestProcessed (Object result);
// }
}
}
@@ -0,0 +1,62 @@
//
// $Id: ClientObject.java 3300 2005-01-08 22:05:00Z ray $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.presents.data {
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DSet;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
/**
* 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 var receivers :DSet;
/**
* Returns a short string identifying this client.
*/
public function who () :String
{
return "(" + getOid() + ")";
}
public override function writeObject (out :ObjectOutputStream) :void
{
super.writeObject(out);
out.writeObject(receivers);
}
public override function readObject (ins :ObjectInputStream) :void
{
super.readObject(ins);
receivers = ins.readObject();
}
}
}
@@ -59,7 +59,7 @@ public class AttributeChangedEvent extends NamedEvent
* primitive types, the reflection-defined object-alternative is * primitive types, the reflection-defined object-alternative is
* used). * used).
*/ */
protected function AttributeChangedEvent ( public function AttributeChangedEvent (
targetOid :int, name :String, value :*, oldValue :*) targetOid :int, name :String, value :*, oldValue :*)
{ {
super(targetOid, name); super(targetOid, name);
@@ -76,10 +76,10 @@ public class AttributeChangedEvent extends NamedEvent
} }
// documentation inherited // documentation inherited
protected override function toString (buf :StringBuilder) :void protected override function toStringBuf (buf :StringBuilder) :void
{ {
buf.append("CHANGE:"); buf.append("CHANGE:");
super.toString(buf); super.toStringBuf(buf);
buf.append(", value=", _value); buf.append(", value=", _value);
} }
@@ -41,7 +41,7 @@ public class CompoundEvent extends DEvent
/** /**
* Constructs a compound event and prepares it for operation. * Constructs a compound event and prepares it for operation.
*/ */
public CompoundEvent (target :DObject, omgr :DObjectManager) public function CompoundEvent (target :DObject, omgr :DObjectManager)
{ {
super(target.getOid()); super(target.getOid());
@@ -112,18 +112,6 @@ public class CompoundEvent extends DEvent
_events.removeAll(); _events.removeAll();
} }
/**
* We need to propagate our source oid to our constituent events.
*/
public override function setSourceOid (sourceOid :int) :void
{
super.setSourceOid(sourceOid);
for (var ii :int = 0; ii < _events.length; ii++) {
_events.getItemAt(ii).setSourceOid(sourceOid);
}
}
/** /**
* Nothing to apply here. * Nothing to apply here.
*/ */
@@ -145,10 +133,10 @@ public class CompoundEvent extends DEvent
} }
// documentation inherited // documentation inherited
protected override function toString (buf :StringBuilder) :void protected override function toStringBuf (buf :StringBuilder) :void
{ {
buf.append("COMPOUND:"); buf.append("COMPOUND:");
super.toString(buf); super.toStringBuf(buf);
for (var ii :int = 0; ii < _events.length; ii++) { for (var ii :int = 0; ii < _events.length; ii++) {
buf.append(", ", _events.getItemAt(ii)); buf.append(", ", _events.getItemAt(ii));
+21 -22
View File
@@ -1,19 +1,18 @@
package com.threerings.presents.dobj { package com.threerings.presents.dobj {
import flash.util.StringBuilder; import flash.util.StringBuilder;
import flash.util.trace;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
import com.threerings.util.Comparable;
public class DEvent public class DEvent
implements Streamable implements Streamable
{ {
public function DEvent () public function DEvent (targetOid :int)
{
}
public function DEvent (int targetOid)
{ {
_toid = targetOid; _toid = targetOid;
} }
@@ -50,18 +49,6 @@ public class DEvent
// the default is to do nothing // the default is to do nothing
} }
/**
* Constructs and returns a string representation of this event.
*/
public override function toString () :String
{
StringBuilder buf = new StringBuilder();
buf.append("[");
toString(buf);
buf.append("]");
return buf.toString();
}
// documentation inherited from interface Streamable // documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void public function writeObject (out :ObjectOutputStream) :void
{ {
@@ -74,12 +61,24 @@ public class DEvent
_toid = ins.readInt(); _toid = ins.readInt();
} }
/**
* Constructs and returns a string representation of this event.
*/
public function toString () :String
{
var buf :StringBuilder = new StringBuilder();
buf.append("[");
toStringBuf(buf);
buf.append("]");
return buf.toString();
}
/** /**
* This should be overridden by derived classes (which should be sure * This should be overridden by derived classes (which should be sure
* to call <code>super.toString()</code>) to append the derived class * to call <code>super.toString()</code>) to append the derived class
* specific event information to the string buffer. * specific event information to the string buffer.
*/ */
protected function toString (buf :StringBuilder) :void protected function toStringBuf (buf :StringBuilder) :void
{ {
buf.append("targetOid=", _toid); buf.append("targetOid=", _toid);
} }
@@ -91,18 +90,18 @@ public class DEvent
} }
} }
class DummyEntry implements DSetEntry class DummyEntry implements com.threerings.presents.dobj.DSetEntry
{ {
public function getKey () :Comparable public function getKey () :com.threerings.util.Comparable
{ {
return null; return null;
} }
public function writeObject (out :ObjectOutputStream) :void public function writeObject (out :com.threerings.io.ObjectOutputStream) :void
{ {
} }
public function readObject (ins :ObjectInputStream) :void public function readObject (ins :com.threerings.io.ObjectInputStream) :void
{ {
} }
} }
@@ -1,9 +1,12 @@
package com.threerings.presents.dobj { package com.threerings.presents.dobj {
import flash.events.EventDispatcher; import flash.events.EventDispatcher;
import flash.util.trace;
import mx.collections.ArrayCollection; import mx.collections.ArrayCollection;
import com.threerings.util.Comparable;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
@@ -140,7 +143,7 @@ public class DObject // extends EventDispatcher
/** /**
* Calls by derived instances when a set adder method was called. * Calls by derived instances when a set adder method was called.
*/ */
protected function requestEntryAdd (name :String, entry :DSet.Entry) :void protected function requestEntryAdd (name :String, entry :DSetEntry) :void
{ {
// dispatch an entry added event // dispatch an entry added event
postEvent(new EntryAddedEvent(_oid, name, entry, false)); postEvent(new EntryAddedEvent(_oid, name, entry, false));
@@ -158,7 +161,7 @@ public class DObject // extends EventDispatcher
/** /**
* Calls by derived instances when a set updater method was called. * Calls by derived instances when a set updater method was called.
*/ */
protected function requestEntryUpdate (name :String, entry :DSet.Entry) protected function requestEntryUpdate (name :String, entry :DSetEntry)
{ {
// dispatch an entry updated event // dispatch an entry updated event
postEvent(new EntryUpdatedEvent(_oid, name, entry, null)); postEvent(new EntryUpdatedEvent(_oid, name, entry, null));
+5 -2
View File
@@ -1,11 +1,14 @@
package com.threerings.presents.dobj { package com.threerings.presents.dobj {
import flash.util.StringBuilder; import flash.util.StringBuilder;
import flash.util.trace;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
import com.threerings.util.Comparable;
/** /**
* The distributed set class provides a means by which an unordered set of * The distributed set class provides a means by which an unordered set of
@@ -230,9 +233,9 @@ public class DSet
/** /**
* Generates a string representation of this set instance. * Generates a string representation of this set instance.
*/ */
public override function toString () :String public function toString () :String
{ {
StringBuilder buf = new StringBuilder("("); var buf :StringBuilder = new StringBuilder("(");
buf.append(_entries.toString()); buf.append(_entries.toString());
buf.append(")"); buf.append(")");
return buf.toString(); return buf.toString();
@@ -2,6 +2,8 @@ package com.threerings.presents.dobj {
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
import com.threerings.util.Comparable;
public interface DSetEntry extends Streamable public interface DSetEntry extends Streamable
{ {
function getKey () :Comparable; function getKey () :Comparable;
@@ -30,7 +30,7 @@ public class ElementUpdatedEvent extends NamedEvent
* used). * used).
* @param index the index in the array of the updated element. * @param index the index in the array of the updated element.
*/ */
public ElementUpdatedEvent ( public function ElementUpdatedEvent (
targetOid :int, name :String, value :*, oldValue :*, index :int) targetOid :int, name :String, value :*, oldValue :*, index :int)
{ {
super(targetOid, name); super(targetOid, name);
@@ -102,10 +102,10 @@ public class ElementUpdatedEvent extends NamedEvent
} }
// documentation inherited // documentation inherited
protected override function toString (buf :StringBuilder) :void protected override function toStringBuf (buf :StringBuilder) :void
{ {
buf.append("UPDATE:"); buf.append("UPDATE:");
super.toString(buf); super.toStringBuf(buf);
buf.append(", value=", _value); buf.append(", value=", _value);
buf.append(", index=", _index); buf.append(", index=", _index);
} }
@@ -1,6 +1,7 @@
package com.threerings.presents.dobj { package com.threerings.presents.dobj {
import flash.util.StringBuilder; import flash.util.StringBuilder;
import flash.util.trace;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
@@ -61,10 +62,10 @@ public class EntryAddedEvent extends NamedEvent
} }
// documentation inherited // documentation inherited
protected override function toString (StringBuilder buf) protected override function toStringBuf (buf :StringBuilder)
{ {
buf.append("ELADD:"); buf.append("ELADD:");
super.toString(buf); super.toStringBuf(buf);
buf.append(", entry=", _entry); buf.append(", entry=", _entry);
} }
@@ -1,10 +1,12 @@
package com.threerings.presents.dobj { package com.threerings.presents.dobj {
import flash.util.StringBuilder; import flash.util.StringBuilder;
import flash.util.trace;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
import com.threerings.util.Comparable;
/** /**
* An entry removed event is dispatched when an entry is removed from a * An entry removed event is dispatched when an entry is removed from a
@@ -80,10 +82,10 @@ public class EntryRemovedEvent extends NamedEvent
} }
// documentation inherited // documentation inherited
protected override function toString (buf :StringBuilder) protected override function toStringBuf (buf :StringBuilder)
{ {
buf.append("ELREM:"); buf.append("ELREM:");
super.toString(buf); super.toStringBuf(buf);
buf.append(", key=", _key); buf.append(", key=", _key);
} }
@@ -1,5 +1,7 @@
package com.threerings.presents.dobj { package com.threerings.presents.dobj {
import flash.util.trace;
import flash.util.StringBuilder; import flash.util.StringBuilder;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
@@ -63,7 +65,7 @@ public class EntryUpdatedEvent extends NamedEvent
if (_oldEntry == null) { if (_oldEntry == null) {
// complain if we didn't update anything // complain if we didn't update anything
trace("No matching entry to update [entry=" + this + trace("No matching entry to update [entry=" + this +
", set=" + set + "]."); ", set=" + dset + "].");
return false; return false;
} }
} }
@@ -79,10 +81,10 @@ public class EntryUpdatedEvent extends NamedEvent
} }
// documentation inherited // documentation inherited
protected override function toString (buf :StringBuilder) :void protected override function toStringBuf (buf :StringBuilder) :void
{ {
buf.append("ELUPD:"); buf.append("ELUPD:");
super.toString(buf); super.toStringBuf(buf);
buf.append(", entry=", _entry); buf.append(", entry=", _entry);
} }
@@ -69,10 +69,10 @@ public class MessageEvent extends NamedEvent
} }
// documentation inherited // documentation inherited
protected override function toString (buf :StringBuilder) :void protected override function toStringBuf (buf :StringBuilder) :void
{ {
buf.append("MSG:"); buf.append("MSG:");
super.toString(buf); super.toStringBuf(buf);
buf.append(", args=", _args); buf.append(", args=", _args);
} }
@@ -18,7 +18,7 @@ public class NamedEvent extends DEvent
* @param targetOid the object id of the object in question. * @param targetOid the object id of the object in question.
* @param name the name associated with this event. * @param name the name associated with this event.
*/ */
public NamedEvent (targetOid :int, name :String) public function NamedEvent (targetOid :int, name :String)
{ {
super(targetOid); super(targetOid);
_name = name; _name = name;
@@ -32,9 +32,9 @@ public class NamedEvent extends DEvent
return _name; return _name;
} }
protected override function toString (buf :StringBuilder) :void protected override function toStringBuf (buf :StringBuilder) :void
{ {
super.toString(buf); super.toStringBuf(buf);
buf.append(", name=", _name); buf.append(", name=", _name);
} }
@@ -71,10 +71,10 @@ public class ObjectAddedEvent extends NamedEvent
} }
// documentation inherited // documentation inherited
protected override function toString (buf :StringBuilder) :void protected override function toStringBuf (buf :StringBuilder) :void
{ {
buf.append("OBJADD:"); buf.append("OBJADD:");
super.toString(buf); super.toStringBuf(buf);
buf.append(", oid=", _oid); buf.append(", oid=", _oid);
} }
@@ -19,7 +19,9 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.presents.dobj; package com.threerings.presents.dobj {
import flash.util.StringBuilder;
/** /**
* An object destroyed event is dispatched when an object has been removed * An object destroyed event is dispatched when an object has been removed
@@ -36,22 +38,14 @@ public class ObjectDestroyedEvent extends DEvent
* *
* @param targetOid the object id of the object that will be destroyed. * @param targetOid the object id of the object that will be destroyed.
*/ */
public ObjectDestroyedEvent (int targetOid) public function ObjectDestroyedEvent (targetOid :int)
{ {
super(targetOid); super(targetOid);
} }
/**
* Constructs a blank instance of this event in preparation for
* unserialization from the network.
*/
public ObjectDestroyedEvent ()
{
}
// documentation inherited // documentation inherited
public boolean applyToObject (DObject target) public override function applyToObject (target :DObject) :Boolean
throws ObjectAccessException //throws ObjectAccessException
{ {
// nothing to do in preparation for destruction, the omgr will // nothing to do in preparation for destruction, the omgr will
// have to recognize this type of event and do the right thing // have to recognize this type of event and do the right thing
@@ -59,17 +53,18 @@ public class ObjectDestroyedEvent extends DEvent
} }
// documentation inherited // documentation inherited
protected void notifyListener (Object listener) protected override function notifyListener (listener :Object) :void
{ {
if (listener instanceof ObjectDeathListener) { if (listener is ObjectDeathListener) {
((ObjectDeathListener)listener).objectDestroyed(this); listener.objectDestroyed(this);
} }
} }
// documentation inherited // documentation inherited
protected void toString (StringBuffer buf) protected override function toStringBuf (buf :StringBuilder) :void
{ {
buf.append("DESTROY:"); buf.append("DESTROY:");
super.toString(buf); super.toStringBuf(buf);
} }
} }
}
@@ -94,10 +94,10 @@ public class ObjectRemovedEvent extends NamedEvent
} }
// documentation inherited // documentation inherited
protected override function toString (buf :StringBuilder) :void protected override function toStringBuf (buf :StringBuilder) :void
{ {
buf.append("OBJREM:"); buf.append("OBJREM:");
super.toString(buf); super.toStringBuf(buf);
buf.append(", oid=", _oid); buf.append(", oid=", _oid);
} }
+15 -18
View File
@@ -1,5 +1,7 @@
package com.threerings.presents.dobj { package com.threerings.presents.dobj {
import flash.util.trace;
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
@@ -27,7 +29,7 @@ public class OidList
*/ */
public function size () :int public function size () :int
{ {
return _size; return _oids.length;
} }
/** /**
@@ -40,19 +42,14 @@ public class OidList
public function add (oid :int) :Boolean public function add (oid :int) :Boolean
{ {
// check for existence // check for existence
for (int i = 0; i < _size; i++) { for (var ii :int = 0; ii < _oids.length; ii++) {
if (_oids[i] == oid) { if (_oids[ii] == oid) {
return false; return false;
} }
} }
// make room if necessary
if (_size+1 >= _oids.length) {
expand();
}
// add the oid // add the oid
_oids[_size++] = oid; _oids[_oids.length] = oid;
return true; return true;
} }
@@ -62,13 +59,13 @@ public class OidList
* @return true if the oid was in the list and was removed, false * @return true if the oid was in the list and was removed, false
* otherwise. * otherwise.
*/ */
public boolean remove (int oid) public function remove (oid :int) :Boolean
{ {
// scan for the oid in question // scan for the oid in question
for (int i = 0; i < _size; i++) { for (var ii :int = 0; ii < _oids.length; ii++) {
if (_oids[i] == oid) { if (_oids[ii] == oid) {
// shift the rest of the list back one // shift the rest of the list back one
System.arraycopy(_oids, i+1, _oids, i, --_size-i); _oids.splice(ii, 1);
return true; return true;
} }
} }
@@ -79,10 +76,10 @@ public class OidList
/** /**
* Returns true if the specified oid is in the list, false if not. * Returns true if the specified oid is in the list, false if not.
*/ */
public boolean contains (int oid) public function contains (oid :int) :Boolean
{ {
for (int i = 0; i < _size; i++) { for (var ii :int = 0; ii < _oids.length; ii++) {
if (_oids[i] == oid) { if (_oids[ii] == oid) {
return true; return true;
} }
} }
@@ -118,9 +115,9 @@ public class OidList
} }
public override function toString () :String public function toString () :String
{ {
StringBuilder buf = new StringBuilder(); var buf :StringBuilder = new StringBuilder();
buf.append("{"); buf.append("{");
buf.append(_oids.toString()); buf.append(_oids.toString());
buf.append("}"); buf.append("}");
@@ -19,7 +19,7 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.presents.dobj; package com.threerings.presents.dobj {
/** /**
* Implemented by entites which wish to hear about changes that occur to * Implemented by entites which wish to hear about changes that occur to
@@ -36,7 +36,7 @@ public interface SetListener extends ChangeListener
* *
* @param event The event that was dispatched on the object. * @param event The event that was dispatched on the object.
*/ */
public void entryAdded (EntryAddedEvent event); function entryAdded (event :EntryAddedEvent) :void;
/** /**
* Called when an entry updated event has been dispatched on an * Called when an entry updated event has been dispatched on an
@@ -45,7 +45,7 @@ public interface SetListener extends ChangeListener
* *
* @param event The event that was dispatched on the object. * @param event The event that was dispatched on the object.
*/ */
public void entryUpdated (EntryUpdatedEvent event); function entryUpdated (event :EntryUpdatedEvent) :void;
/** /**
* Called when an entry removed event has been dispatched on an * Called when an entry removed event has been dispatched on an
@@ -54,5 +54,6 @@ public interface SetListener extends ChangeListener
* *
* @param event The event that was dispatched on the object. * @param event The event that was dispatched on the object.
*/ */
public void entryRemoved (EntryRemovedEvent event); function entryRemoved (event :EntryRemovedEvent) :void;
}
} }
@@ -0,0 +1,63 @@
//
// $Id: Subscriber.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.presents.dobj {
/**
* A subscriber is an entity that has access to a distributed object. The
* process of obtaining access to a distributed object is an asynchronous
* one, and changes made to an object are delivered asynchronously. By
* registering as a subscriber to an object, an entity can react to
* changes made to an object and ensure that their object is kept up to
* date.
*
* <p> To actually receive callbacks when events are dispatched on a
* distributed object, an entity should register itself as a listener on
* the object once it has received its object reference.
*
* @see EventListener
* @see AttributeChangeListener
* @see SetListener
* @see OidListListener
*/
public interface Subscriber
{
/**
* Called when a subscription request has succeeded and the object is
* available. If the object was requested for subscription, the
* subscriber can subsequently receive notifications by registering
* itself as a listener of some sort (see {@link
* DObject#addListener}).
*
* @see DObjectManager#subscribeToObject
*/
function objectAvailable (obj :DObject) :void;
/**
* Called when a subscription request has failed. The nature of the
* failure will be communicated via the supplied
* <code>ObjectAccessException</code>.
*
* @see DObjectManager#subscribeToObject
*/
function requestFailed (oid :int, cause :ObjectAccessError) :void;
}
}
@@ -5,20 +5,14 @@ import com.threerings.io.ObjectOutputStream;
public class AuthRequest extends UpstreamMessage public class AuthRequest extends UpstreamMessage
{ {
public function AuthRequest ()
{
super();
}
public function AuthRequest (creds :Credentials, version :String) public function AuthRequest (creds :Credentials, version :String)
{ {
super();
_creds = creds; _creds = creds;
_version = version; _version = version;
} }
// documentation inherited // documentation inherited
public function writeObject (out :ObjectOutputStream) :void public override function writeObject (out :ObjectOutputStream) :void
{ {
super.writeObject(out); super.writeObject(out);
@@ -27,7 +21,7 @@ public class AuthRequest extends UpstreamMessage
} }
// documentation inherited // documentation inherited
public function readObject (ins :ObjectInputStream) :void public override function readObject (ins :ObjectInputStream) :void
{ {
super.readObject(ins); super.readObject(ins);
_creds = ins.readObject(); _creds = ins.readObject();
@@ -10,7 +10,7 @@ public class AuthResponse extends DownstreamMessage
return _data; return _data;
} }
public function readObject (ins :ObjectInputStream) :void public override function readObject (ins :ObjectInputStream) :void
{ {
super.readObject(ins); super.readObject(ins);
_data = ins.readObject(); _data = ins.readObject();
@@ -1,5 +1,7 @@
package com.threerings.presents.net { package com.threerings.presents.net {
import flash.util.trace;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
@@ -9,7 +9,7 @@ public class BootstrapNotification extends DownstreamMessage
return _data; return _data;
} }
public function readObject (ins :ObjectInputStream) :void public override function readObject (ins :ObjectInputStream) :void
{ {
super.readObject(ins); super.readObject(ins);
_data = ins.readObject(); _data = ins.readObject();
@@ -1,5 +1,7 @@
package com.threerings.presents.net { package com.threerings.presents.net {
import flash.util.trace;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
@@ -32,7 +32,7 @@ public class EventNotification extends DownstreamMessage
return _event; return _event;
} }
public override function toString () :String public function toString () :String
{ {
return "[type=EVT, evt=" + _event + "]"; return "[type=EVT, evt=" + _event + "]";
} }
@@ -41,6 +41,6 @@ public class FailureResponse extends DownstreamMessage
_oid = ins.readInt(); _oid = ins.readInt();
} }
protected int _oid; protected var _oid :int;
} }
} }
@@ -56,7 +56,7 @@ public class ForwardEventRequest extends UpstreamMessage
_event = ins.readObject(); _event = ins.readObject();
} }
public override function toString () :String public function toString () :String
{ {
return "[type=FWD, evt=" + _event + "]"; return "[type=FWD, evt=" + _event + "]";
} }
@@ -40,7 +40,7 @@ public class UnsubscribeResponse extends DownstreamMessage
return "[type=UNACK, msgid=" + messageId + ", oid=" + _oid + "]"; return "[type=UNACK, msgid=" + messageId + ", oid=" + _oid + "]";
} }
public function readObject (ins :ObjectInputStream) :void public override function readObject (ins :ObjectInputStream) :void
{ {
super.readObject(ins); super.readObject(ins);
_oid = ins.readInt(); _oid = ins.readInt();
@@ -1,5 +1,7 @@
package com.threerings.presents.net { package com.threerings.presents.net {
import flash.util.trace;
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
@@ -55,9 +55,9 @@ public class UsernamePasswordCreds extends Credentials
} }
// documentation inherited // documentation inherited
protected override function toString (buf :StringBuilder) protected override function toStringBuf (buf :StringBuilder)
{ {
super.toString(buf); super.toStringBuf(buf);
buf.append(", password=", _password); buf.append(", password=", _password);
} }
+7
View File
@@ -0,0 +1,7 @@
package com.threerings.util {
public interface Comparable
{
function compareTo (other :Object) :int;
}
}
+2
View File
@@ -2,6 +2,8 @@ package com.threerings.util {
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;
/** /**
* TODO: stuff. * TODO: stuff.