org.jgroups.blocks
Class PullPushAdapter
java.lang.Object
org.jgroups.blocks.PullPushAdapter
- Runnable
public class PullPushAdapter
extends java.lang.Object
implements 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:
- Bela Ban
listeners
protected HashMap listeners
membership_listeners
protected List membership_listeners
receiver_thread
protected Thread receiver_thread
PullPushAdapter
public PullPushAdapter(Transport transport)
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
notifyBlock
protected void notifyBlock()
notifySuspect
protected void notifySuspect(Address suspected_mbr)
notifyViewChange
protected void notifyViewChange(View v)
registerListener
public void registerListener(Serializable identifier,
MessageListener l)
sets a listener to messages with a given identifier messages sent with this identifier in there header will be routed to this listener
note: there could be only one listener for one identifier, if you want to register a different listener to an already registered identifier then unregister first
identifier
- - messages sent on the group with this object will be receive by this listenerl
- - the listener that will get the message
run
public void run()
Reentrant run(): message reception is serialized, then the listener is notified of the
message reception
send
public void send(Serializable identifier,
Message msg)
throws Exception
Sends a message to the group - listeners to this identifier will receive the messages
identifier
- the key that the proper listeners are listenting onmsg
- the Message to be sent
registerListener
send
public void send(Message msg)
throws Exception
sends a message with no identifier , listener member will get this message on the other group members
msg
- the Message to be sent
unregisterListener
public void unregisterListener(Serializable identifier)
removes a listener to a given identifier from the listeners map
identifier
- - the key to whom we do not want to listen any more
Copyright B) 2001,2002 www.jgroups.com . All Rights Reserved.