ChannelBroadcaster
| Kind of class: | public class |
|---|---|
| Package: | com.bourre.events |
| Inherits from: | none |
| Known subclasses: | |
| Author: | Francis Bourre |
| Classpath: | com.bourre.events.ChannelBroadcaster |
| File last modified: | Monday, 24 November 2008, 11:36:53 |
ChannelBroadcaster is a macro broadcasterwhich offer to dispatch events over communication channels.
The main idea is the following, developpers can create specific
channels for communication, onto which event will be broadcasted.
To take a metaphor, is like a CB radio, you can select a frequency
and then you will listen and talk to people which are connected to
that frequency, and only that one. To achieve this process, the
channel broadcaster aggregates Broadcaster implementation
and map it with EventChannel object. In that principle
the channel broadcaster is no more than a CB base station. With
a big difference anyway, the broadcaster channel offers an access
to a frequency, it doesn't broadcast messages itself.
To initiate the dispatching on a specific channel, developers
only need to call the redefined functions of the class as they
can do with a Broadcaster implementation with a proper
event channel, the channel broadcaster will check for the presence
of a broadcaster instance for this channel, and if there's no
corresponding broadcaster it will create it.
The channel broadcaster redefines many functions of the Broadcaster interface in order to add the channel
parameter. See below the list of redefined methods :
isRegisteredbroadcastEventaddListeneraddEventListenerremoveListenerremoveEventListenerhasChannelListener, which correspond
to thehasListenerCollectionmethod of theEventBroadcasterclass .
Summary
- ChannelBroadcaster (broadcasterClass:Class = null, channel:EventChannel = null)
- Creates a new ChannelBroadcaster with the passed-in
- getDefaultDispatcher : Broadcaster
- Returns the Broadcaster implementation associated
- getDefaultChannel : EventChannel
- Returns a reference to the default channel of this
- setDefaultChannel (channel:EventChannel = null) : void
- Defines which channel is used as default channel for this
- empty : void
- Clean the current channel broacaster by removing all
- isRegistered (listener:Object, type:String, channel:EventChannel) : Boolean
- Returns true if the passed-in listeneris registered as listener for the passed-in event typein the passed-in channel.
- hasChannelDispatcher (channel:EventChannel) : Boolean
- Returns true if there is a Broadcasterinstance registered for the passed-in channel.
- hasChannelListener (type:String, channel:EventChannel = null) : Boolean
- Returns true if there is a Broadcaster instance
- releaseChannelDispatcher (channel:EventChannel) : Boolean
- Returns the Broadcaster instance associated with the
- addListener (listener:Object, channel:EventChannel = null) : Boolean
- Adds the passed-in listener as listener for all events
- removeListener (listener:Object, channel:EventChannel = null) : Boolean
- Removes the passed-in listener object from this event
- addEventListener (type:String, listener:Object, channel:EventChannel = null) : Boolean
- Adds an event listener for the specified event type of the
- removeEventListener (type:String, listener:Object, channel:EventChannel = null) : Boolean
- Removes the passed-in listener for listening the specified event of
- broadcastEvent (e:Event, channel:EventChannel = null) : void
- Broadcast the passed-in event object to listeners
- toString : String
- Returns the string representation of this instance.
Constructor
ChannelBroadcaster
ChannelBroadcaster with the passed-inBroadcaster class to build broadcaster instances andan event channel as default channel. The default channel is used
when a call to function is done without specifying any channel. If
the channel argument is omitted, the default channel is set to the
internal
DefaultChannel.CHANNEL constant. broadcaster
- {VISDOC_LINK_0}
IllegalArgumentException— If the passed-in
class doesn't implementBroadcasterinterface
Instance methods
addEventListener
specified channel. There is two behaviors for the
addEventListener function :- The passed-in listener is an object :
The object is added as listener only for the specified event, the object
must have a function with the same name thantypeor at least
ahandleEventfunction. - The passed-in listener is a function :
ADelegateobject is created and then
added as listener for the event type . There is no restriction on the name
of the function.
-
trueif the function have been succesfully added as
listener fot the passed-in event
- {VISDOC_LINK_0}
UnsupportedOperationException— If the listener is an object
which have neither a function with the same name than the event type nor
a function calledhandleEvent
addListener
dispatched by this event channel broadcaster. The function
returns
true if the listener have been addedat the end of the call. If the listener is already registered
in this event channel broadcaster the function returns
false.Note : The addListener function doesn't accept
functions as listener, functions could only register for
a single event.
-
trueif the listener have been added during this call
- {VISDOC_LINK_0}
IllegalArgumentException— If the passed-in listener
listener doesn't match the listener type supported by this
broadcaster instance - {VISDOC_LINK_1}
IllegalArgumentException— If the passed-in listener
is a function
broadcastEvent
according to the event's type and
channelargument. The event is broadcasted to both listenersregistered specifically for this event type and global
listeners in the broadcaster.
If the target property of the passed-in event
is null, it will be set using the value of the
source property of this event broadcaster.
- {VISDOC_LINK_0}
UnsupportedOperationException— If one listener is an object
which have neither a function with the same name than the event type nor
a function calledhandleEvent
empty
Broadcaster instances previously createdand then rebuild the default
EventBroadcaster. getDefaultChannel
channel broadcaster. This function never returns
null. - a reference to the default channel of this
channel broadcaster
getDefaultDispatcher
Broadcaster implementation associatedwith the default channel of this channel broadcaster.
- the
Broadcasterimplementatation associated
with the default channel of this channel broadcaster
hasChannelDispatcher
true if there is a Broadcasterinstance registered for the passed-in channel. -
trueif there is aBroadcasterinstance registered for the passed-in channel
hasChannelListener
true if there is a Broadcaster instanceregistered for the passed-in channel, and if this broadcaster has registered
listeners.
-
trueif there is aBroadcasterinstance registered for the passed-in channel, and if this
broadcaster has registered listeners
isRegistered
true if the passed-in listeneris registered as listener for the passed-in event typein the passed-in channel. -
trueif the passed-inlisteneris registered as listener for the passed-in event
typein the passed-inchannel
releaseChannelDispatcher
Broadcaster instance associated with thepassed-in
channel<code>. The <code>owner is an optionnalparameter which is used to initialize the newly created
Broadcasterwhen there is no broadcaster for this channel. is no broadcaster associated to the channel
- the
Broadcasterinstance associated with
the passed-inchannel<code> %ASDOCHR%/ public function getChannelDispatcher( channel : EventChannel = null, owner : Object = null ) : Broadcaster { if ( hasChannelDispatcher( channel ) ) return channel == null ? _mChannel.get( _oDefaultChannel ) : _mChannel.get( channel ); else { var eb : Broadcaster = new (_broadcasterClass as Class)( owner ); _mChannel.put( channel, eb ); return eb; } } /** %ASDOCHR%Removes the <code>Broadcasterinstance associated with
the passed-inchannel<code>, and return <code>trueif there is a broadcaster and if it have been successfully removed. -
trueif there is a broadcaster and if it have
been successfully removed.
removeEventListener
the specified channel. The listener could be either an object or a function.
-
trueif the listener have been successfully removed
as listener for the passed-in event
removeListener
channel broadcaster. The object is removed as listener
for all events the broadcaster may dispatch on this
channel.
this event broadcaster object
-
trueif the object have been successfully
removed from this broadcaster instance
- {VISDOC_LINK_0}
IllegalArgumentException— If the passed-in listener
is a function
setDefaultChannel
channel broadcaster. If the passed-in channel is
nullthe internal DefaultChannel.CHANNEL constant is usedas default channel.
toString
- the string representation of this instance