4.3 A commercial implementation
In order to conclude this section I shall describe a commercial implementation of an object bus. It has been developed by a company known as SoftWired Ltd and is known as iBus. It is based on TCP/IP rather than UDP. The facilities offered by the iBus API provide developers with the facilities to construct objects which can subscribe to channels and to transmit any Java object to a channel. The code for a transmitter is shown below; the import statements are not shown. In the code for the transmitter and the receiver an object which is sent along the bus is known as a object.
This example is based on one used in a Sun Java training course SL30 1 Distributed Programming with Java. It is simple code: all that it does is to send the string message out on the bus. The bus is identified by a special type of URL which starts with the protocol identifier “ibus”. The variable st is a protocol stack; the constructor uses the string “Reliable” to indicate that it wants the data sent using a reliable protocol where data is guaranteed to arrive at its destination – not, for example, UDP.
The code for a very simple listener object is shown below; it just receives an object, displays it and exits.
The code is relatively straightforward. The class acts as the driver class. The method inside this class sets up a receiver object which is defined by the class and attaches it to the bus. The class implements the interface which has three methods whose code has to be provided. The only processing code for a method in this example is needed in which is executed when an object is sent down the bus.
The interface Receiver acts very much like a listener interface found in the Java AWT.