bd306351ee
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4360 542714f4-19e9-0310-aa3c-eee0fc999fb1
53 lines
1.5 KiB
ActionScript
53 lines
1.5 KiB
ActionScript
package com.threerings.presents.net {
|
|
|
|
import com.threerings.io.Streamable;
|
|
import com.threerings.io.ObjectInputStream;
|
|
import com.threerings.io.ObjectOutputStream;
|
|
|
|
import com.threerings.util.JavaConstants;
|
|
|
|
public /* abstract */ class UpstreamMessage
|
|
implements Streamable
|
|
{
|
|
/** This is a unique (within the context of a reasonable period
|
|
* of time) identifier assigned to each upstream message. The message ids
|
|
* are used to correlate a downstream response message to the
|
|
* appropriate upstream request message. */
|
|
public var messageId :int;
|
|
|
|
/**
|
|
* Construct an upstream message.
|
|
*/
|
|
public function UpstreamMessage ()
|
|
{
|
|
// automatically generate a valid message id
|
|
this.messageId = nextMessageId();
|
|
}
|
|
|
|
// documentation inherited from interface Streamable
|
|
public function writeObject (out :ObjectOutputStream) :void
|
|
{
|
|
out.writeShort(messageId);
|
|
}
|
|
|
|
// documentation inherited from interface Streamable
|
|
public final function readObject (ins :ObjectInputStream) :void
|
|
{
|
|
throw new Error(); // abstract: not needed
|
|
}
|
|
|
|
/**
|
|
* Returns the next message id suitable for use by an upstream message./
|
|
*/
|
|
protected static function nextMessageId () :int
|
|
{
|
|
_nextMessageId = (_nextMessageId + 1) % JavaConstants.SHORT_MAX_VALUE;
|
|
return _nextMessageId;
|
|
}
|
|
|
|
/** This is used to generate monotonically increasing message ids on the
|
|
* client as new messages are generated. */
|
|
protected static var _nextMessageId :int;
|
|
}
|
|
}
|