Some datamixer objects can listen to others, and take action when an event
occurs. The listener can specify what type of event it is interested in. For
example, an I/O element might listen to an
iterator's next event. The listener can also specify the action
that it should take when an event occurs. In this example, the I/O element
might ask that its setValue action be run.
Any datamixer class can be an event generator, by implementing interface DatamixerEventGenerator . Currently iterators and attributes are event generators.
Any datamixer class can be a listener, by implementing interface
DatamixerListener.
Currently, I/O attributes and elements, and value
lists are listeners. An I/O element listens to an iterator's done or
next events, and writes the generated values. A value list listens to an
I/O attribute's next event, and adds each new value to itself.
Event Generators
The next table lists the objects that generate events.
| Object | Event | Description |
|---|---|---|
| iterator | next | fired with each next value |
| iterator | done | fired when hasNext() returns false |
| attribute | next | fired when setValue() is called |
Event Listeners
The next table lists the objects that listen to events, and the actions they can take on receiving an event.
| Object | Action | Description | |
|---|---|---|---|
| attribute | setValue | calls setValue() with the value in the event | |
| element | iterator | calls setValue() with the value in the event | |
| element | iterator | calls write() | |
| element | iterator |
calls setValue() with the value in the event, and then
calls write()
|
Here is a fragment from the university example (see the examples subdirectory). An I/O element listens to the next event of the iterator whose name is building. When a next event occurs, the element's event handler sets the generated value into the element, then writes it.
<!-- iterator -->
<dm:list name="building">
<dm:ints range="[1]" name="pk"/>
...
<dm:listener listener="csvBuildings" event="next" action="setValueWrite"/>
</dm:list>
<!-- element -->
<dmio:element id="csvBuildings">
<dmio:file-writer path="csv/buildings.csv"/>
<dmio:csv-format/>
<dmio:attribute value="building.pk"/>
</dmio:element>