org.javagroups.blocks
Class PullPushAdapter

java.lang.Object
  |
  +--org.javagroups.blocks.PullPushAdapter
All Implemented Interfaces:
java.lang.Runnable

public class PullPushAdapter
extends java.lang.Object
implements java.lang.Runnable

Allows a client of Channel to be notified when messages have been received instead of having to actively poll the channel for new messages. Typically used in the client role (receive()). As this class does not implement interface Transport, but uses it for receiving messages, an underlying object has to be used to send messages (e.g. the channel on which an object of this class relies).

Multiple MembershipListeners can register with the PullPushAdapter; when a view is received, they will all be notified. There is one main message listener which sends and receives message. In addition, MessageListeners can register with a certain tag (identifier), and then send messages tagged with this identifier. When a message with such an identifier is received, the corresponding MessageListener will be looked up and the message dispatched to it. If no tag is found (default), the main MessageListener will receive the message.

Version:
$Revision
Author:
Bela Ban

Inner Class Summary
static class PullPushAdapter.PullHeader
           
 
Field Summary
protected  MessageListener listener
           
protected  java.util.HashMap listeners
           
protected  java.util.List membership_listeners
           
protected  java.lang.Thread receiver_thread
           
protected  Transport transport
           
 
Constructor Summary
PullPushAdapter(Transport transport)
           
PullPushAdapter(Transport transport, MembershipListener ml)
           
PullPushAdapter(Transport transport, MessageListener l)
           
PullPushAdapter(Transport transport, MessageListener l, MembershipListener ml)
           
 
Method Summary
 void addMembershipListener(MembershipListener l)
           
 Transport getTransport()
           
protected  void handleMessage(Message msg)
          Check whether the message has an identifier.
protected  void notifyBlock()
           
protected  void notifySuspect(Address suspected_mbr)
           
protected  void notifyViewChange(View v)
           
 void registerListener(java.io.Serializable identifier, MessageListener l)
           
 void run()
          Reentrant run(): message reception is serialized, then the listener is notified of the message reception
 void send(Message msg)
           
 void send(java.io.Serializable identifier, Message msg)
           
 void setListener(MessageListener l)
           
 void setMembershipListener(MembershipListener ml)
          Deprecated. Use addMembershipListener
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

transport

protected Transport transport

listener

protected MessageListener listener

membership_listeners

protected java.util.List membership_listeners

receiver_thread

protected java.lang.Thread receiver_thread

listeners

protected java.util.HashMap listeners
Constructor Detail

PullPushAdapter

public PullPushAdapter(Transport transport)

PullPushAdapter

public PullPushAdapter(Transport transport,
                       MessageListener l)

PullPushAdapter

public PullPushAdapter(Transport transport,
                       MembershipListener ml)

PullPushAdapter

public PullPushAdapter(Transport transport,
                       MessageListener l,
                       MembershipListener ml)
Method Detail

getTransport

public Transport getTransport()

start

public void start()

stop

public void stop()

send

public void send(java.io.Serializable identifier,
                 Message msg)
          throws java.lang.Exception

send

public void send(Message msg)
          throws java.lang.Exception

setListener

public void setListener(MessageListener l)

registerListener

public void registerListener(java.io.Serializable identifier,
                             MessageListener l)

setMembershipListener

public void setMembershipListener(MembershipListener ml)
Deprecated. Use addMembershipListener


addMembershipListener

public void addMembershipListener(MembershipListener l)

run

public void run()
Reentrant run(): message reception is serialized, then the listener is notified of the message reception
Specified by:
run in interface java.lang.Runnable

handleMessage

protected void handleMessage(Message msg)
Check whether the message has an identifier. If yes, lookup the MessageListener associated with the given identifier in the hashtable and dispatch to it. Otherwise just use the main (default) message listener

notifyViewChange

protected void notifyViewChange(View v)

notifySuspect

protected void notifySuspect(Address suspected_mbr)

notifyBlock

protected void notifyBlock()


Copyright © 2001,2002 www.javagroups.com . All Rights Reserved.