org.as2lib.core.BasicClass +--org.as2lib.env.event.TypeSafeEventListenerSource +--org.as2lib.env.event.distributor.AbstractEventDistributorControl +--org.as2lib.env.event.distributor.SimpleConsumableEventDistributorControl
ConsumableEventDistributorControl
SimpleConsumableEventDistributorControl
acts as a listener source and
event distributor. It enables you to distribute and handle events in the safest
way possible.
Note that unlike the SimpleEventDistributorControl class, this class
supports the consumption of events. An event is consumed if an event method on a
listener returns true
. This means that the distribution of the event will
be stopped immediately. Otherwise the event will further be distributed.
Example:
// creates a distributor control with the expected listener type
var distributorControl:SimpleConsumableEventDistributorControl = new SimpleConsumableEventDistributorControl(ErrorListener);
// adds new listeners that must be of the expected type
distributorControl.addListener(new MyErrorListener());
distributorControl.addListener(new SimpleErrorListener());
// gets a distributor to distribute the event to all listeners
var distributor:ErrorListener = ErrorListener(distributorControl.getDistributor());
// distributes the event with custom arguments
distributor.onError(myErrorCode, myException);
If in the above example, the MyErrorListener.onError
method returns
true
, the SimpleErrorListener.onError
method will not be invoked
because the event is consumed.
new SimpleConsumableEventDistributorControl()
addAllListeners(), addListener(), getAllListeners(), getListenerType(), hasListener(), isListenerTypeChecked(), removeAllListeners(), removeListener()
public function SimpleConsumableEventDistributorControl(listenerType:Function, checkListenerType:Boolean, listeners:Array)
Constructs a new SimpleConsumableEventDistributorControl
instance.
checkListenerType
is by default set to true
.
listenerType | the expected type of listeners |
checkListenerType | determines whether to check that passed-in listeners are of the expected type |
listeners | (optional) the listeners to add |
IllegalArgumentException | if the passed-in listenerType is
null or undefined
|