next up previous contents
Next: Example Up: Building blocks Previous: Building blocks

   
PullPushAdapter

This class is a converter (or adapter, as used in [GHJV95]) between the pull-style of actively having to receive messages and the push-style where clients register a callback method which is invoked whenever a message has been received. It allows clients of a channel to be notified when messages have been received instead of having to actively poll the channel for new messages. This eliminates any need for the clients to allocate a separate thread for receiving messages.

A PullPushAdapter (JavaGroups.PullPushAdapter) is always created on top of a class that implements interface Transportable (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 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 Transportable instance (e.g. a channel)3.4, 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 Transportable, 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. 3.3.


  
Figure 3.3: Class PullPushAdapter
\begin{figure}
\center{\epsfig{file=/home/bba/JavaGroups/Papers/UsersGuide/figs/PullPushAdapter.eps,width=.3\textwidth} }
\end{figure}

As is shown, the thread constantly pulls messages from the channel and forwards them to the registered client. 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.



 
next up previous contents
Next: Example Up: Building blocks Previous: Building blocks

1999-12-13