DataBus Documentation

Writing your own modules

new components

New components need to implement at least the 'DataBusComponent' interface. The methods defined there are used for life cycle management of the components. They are called during startup (the order is 'init', 'preStartup', 'start', 'postStartup').
In the init() method, the configuration should be read. Use the preStartup() method to initialize everything which must be done before other components are started.
If you need to do normal initializations, or want to start threads, do this in the start() method. Everything which must be done during program startup, and which depends on the proper initializations of other components, must be done in the postStartup() method (e.g. sending events to other components).
Note that the components need to have a default constructor (or no constructor at all).

consumers


You want to implement one of the 'DataBusConsumer' or 'DataBusProducer' interfaces also. The latter interface is also used for knowing which component can generate new events (a DataBus should shut down if no active producers are available), but doesn't contain any methods.
The 'DataBusConsumer' interface only defines the dataAvilable() method. It is called if a registered event is received. This registration should be done in the init() method (just call the databus.addConsumer() method).
If you want to add new event types, give the class a 'public static final String NAME' attribute, containing the name of the event. This constant can the be used by the components to register as listener for this event (to avoid typos).
The order in which the events received by a consumer are handled via the dataAvailable() method is the same for all consumers. But it is nor guaranteed that this happens at the same time (e.g. if two consumers are listening for events of the type TEST, and a producer send three events, it may be that the first consumer handles all three events before the second consumer can handle even the first event.
This behaviour is important if consumers act itself as producers and generate new events from the ones they have received. If you do this, and depend on the proper ordering of the generated events, you will need your own synchronization mechanism between the components.