Packagecom.whirled.contrib
Classpublic class Chunker
InheritanceChunker Inheritance flash.events.EventDispatcher

Chunks data to other instances of the entity being used. Author: Ray Greenwell



Protected Properties
 PropertyDefined by
  _ctrl : EntityControl
The entity control we're using.
Chunker
  _inChunks : Object
Holds incomplete chunks being received.
Chunker
  _msgName : String
The message name we're using.
Chunker
  _nextSend : int
The time at which we should send the next chunk.
Chunker
  _outData : ByteArray
The data we're currently sending.
Chunker
  _outTokens : int
Some tokens describing the format of the _outData.
Chunker
  _thisId : String
The instance id of this instance of the chunker.
Chunker
  _timer : Timer
The Timer used to throttle sends.
Chunker
Public Methods
 MethodDefined by
  
Chunker(ctrl:EntityControl, msgName:String = "chunk", receivedCallback:Function = null)
Construct a Chunker.
Chunker
  
send(data:Object, compressStrategy:int):void
Send this data to all instances of this entity in chunked and throttled messages.
Chunker
Protected Methods
 MethodDefined by
  
Check to see if enough time has passed to send the next chunk.
Chunker
  
chunkReceived(id:String, inBytes:ByteArray):void
Handle a received chunk.
Chunker
  
countChunks(dataLength:int):int
[static] Counts the number of chunks to send data of the specified length.
Chunker
  
handleMessage(event:ControlEvent):void
Handles ControlEvent.MESSAGE_RECEIVED.
Chunker
  
handleUnload(event:Event):void
Handles Event.UNLOAD.
Chunker
  
sendChunk(... ignored):void
Send the next chunk.
Chunker
Events
 EventSummaryDefined by
   Dispatched when the chunks are reconstituted and ready to use.Chunker
Public Constants
 ConstantDefined by
  ALWAYS_COMPRESS : int = 0
[static] A compression strategy that always compresses the data, regardless of whether it saved any space.
Chunker
  NEVER_COMPRESS : int = 2
[static] A compression strategy that says: don't ever even waste time trying to compress.
Chunker
  TRY_COMPRESS : int = 1
[static] A compression stragegy that tries to compress the data, but only sends the compressed form if it would actually result in sending less chunks.
Chunker
Protected Constants
 ConstantDefined by
  COMPRESSED_TOKEN : int
[static]
Chunker
  END_TOKEN : int
[static]
Chunker
  MAX_CHUNK_DATA : int = 1020
[static] The maximum size of our chunks.
Chunker
  MIN_SEND_WAIT : int = 200
[static] The minimum time between sends.
Chunker
  NO_TOKENS : int = 0
[static] Token constants.
Chunker
  OBJECT_TOKEN : int
[static]
Chunker
  START_TOKEN : int
[static]
Chunker
Property detail
_ctrlproperty
protected var _ctrl:EntityControl

The entity control we're using.

_inChunksproperty 
protected var _inChunks:Object

Holds incomplete chunks being received.

_msgNameproperty 
protected var _msgName:String

The message name we're using.

_nextSendproperty 
protected var _nextSend:int

The time at which we should send the next chunk.

_outDataproperty 
protected var _outData:ByteArray

The data we're currently sending.

_outTokensproperty 
protected var _outTokens:int

Some tokens describing the format of the _outData.

_thisIdproperty 
protected var _thisId:String

The instance id of this instance of the chunker.

_timerproperty 
protected var _timer:Timer

The Timer used to throttle sends. Only used on the sender.

Constructor detail
Chunker()constructor
public function Chunker(ctrl:EntityControl, msgName:String = "chunk", receivedCallback:Function = null)

Construct a Chunker.

Parameters
ctrl:EntityControl — your AvatarControl or ToyControl, etc.
 
msgName:String (default = "chunk") — the prefix name of the message to use for data sent using this chunker.
 
receivedCallback:Function (default = null) — may be specified instead of listening for the complete event, this function will be invoked when the data is received. Only the value is returned. Signature: function (data :Object) :void;
Method detail
checkSendChunk()method
protected function checkSendChunk():void

Check to see if enough time has passed to send the next chunk.

chunkReceived()method 
protected function chunkReceived(id:String, inBytes:ByteArray):void

Handle a received chunk.

Parameters
id:String
 
inBytes:ByteArray
countChunks()method 
protected static function countChunks(dataLength:int):int

Counts the number of chunks to send data of the specified length.

Parameters
dataLength:int

Returns
int
handleMessage()method 
protected function handleMessage(event:ControlEvent):void

Handles ControlEvent.MESSAGE_RECEIVED.

Parameters
event:ControlEvent
handleUnload()method 
protected function handleUnload(event:Event):void

Handles Event.UNLOAD.

Parameters
event:Event
send()method 
public function send(data:Object, compressStrategy:int):void

Send this data to all instances of this entity in chunked and throttled messages.

Parameters
data:Object — a ByteArray or any other object graph that can be serialized to AMF3.
 
compressStrategy:int — the strategy to take when deciding whether to compress the data.
sendChunk()method 
protected function sendChunk(... ignored):void

Send the next chunk.

Parameters
... ignored
Event detail
completeevent 
Event object type: com.threerings.util.NamedValueEvent

Dispatched when the chunks are reconstituted and ready to use. The 'name' property will contain the String version of the instance id that sent the data. The 'value' property will contain the received data.

Constant detail
ALWAYS_COMPRESSconstant
public static const ALWAYS_COMPRESS:int = 0

A compression strategy that always compresses the data, regardless of whether it saved any space.

COMPRESSED_TOKENconstant 
protected static const COMPRESSED_TOKEN:int
END_TOKENconstant 
protected static const END_TOKEN:int
MAX_CHUNK_DATAconstant 
protected static const MAX_CHUNK_DATA:int = 1020

The maximum size of our chunks. Whirled enforces a post-AMF3 1024 byte limit, so we want to use all of that. In AMF3, one byte is used to encode "ByteArray", followed by the length, which will be two bytes because 1024-ish is larger than 2^7 but less than 2^14. So the AMF3 encoding takes 3 bytes, plus there's our 1 byte header for each chunk, leaving us 1020 bytes for our chunk size.

MIN_SEND_WAITconstant 
protected static const MIN_SEND_WAIT:int = 200

The minimum time between sends. This is even fairly aggressive. Using other values may "work" but then certain times they may not work, so you're best off not screwing with this.

NEVER_COMPRESSconstant 
public static const NEVER_COMPRESS:int = 2

A compression strategy that says: don't ever even waste time trying to compress.

NO_TOKENSconstant 
protected static const NO_TOKENS:int = 0

Token constants.

OBJECT_TOKENconstant 
protected static const OBJECT_TOKEN:int
START_TOKENconstant 
protected static const START_TOKEN:int
TRY_COMPRESSconstant 
public static const TRY_COMPRESS:int = 1

A compression stragegy that tries to compress the data, but only sends the compressed form if it would actually result in sending less chunks.