next up previous contents
Next: Example Up: Building Blocks Previous: Building Blocks   Contents


PullPushAdapter

This class is a converter (or adapter, as used in [GHJV95]) between the pull-style of actively receiving messages from the channel and the push-style where clients register a callback which is invoked whenever a message has been received. Clients of a channel do not have to allocate a separate thread for message reception.

A PullPushAdapter is always created on top of a class that implements interface Transport (e.g. a channel). Clients interested in being called when a message is received can register with the PullPushAdapter using method setListener(). They have to implement interface MessageListener, whose receive() method will be called when a message arrives. When a client is interested in getting view, suspicion messages and blocks, then it must additionally register as a MembershipListener using method setMembershipListener(). Whenever a view, suspicion or block is received, the corresponding method will be called.

Upon creation, an instance of PullPushAdapter creates a thread which constantly calls the receive() method of the underlying Transport instance, blocking until a message is available. When a message is received, if there is a registered message listener, its receive() method will be called.

As this class does not implement interface Transport, but merely uses it for receiving messages, an underlying object has to be used to send messages (e.g. the channel on top of which an object of this class resides). This is shown in fig. 4.1.

Figure 4.1: Class PullPushAdapter
\begin{figure}\center{\epsfig{file=figs/PullPushAdapter.eps,width=.35\textwidth}}
\end{figure}

As is shown, the thread constantly pulls messages from the channel and forwards them to the registered listeners. An application thus does not have to actively pull for messages, but the PullPushAdapter does this for it. Note however, that the application has to directly access the channel if it wants to send a message.



Subsections
next up previous contents
Next: Example Up: Building Blocks Previous: Building Blocks   Contents
Bela Ban 2002-11-16