org.objectweb.tribe.adapters
Class PullPushAdapter

java.lang.Object
  extended byorg.objectweb.tribe.adapters.PullPushAdapter
All Implemented Interfaces:
java.lang.Runnable

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

Allows a client 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()). This blocks works with any kind of reliable group channel.

Note that message delivery is single threaded and if the message handler hangs, it will block further message delivery. Send() methods are just provided for convenience and wraps calls to the same methods on the channel.

This adapter is inspired from JGroups PullPushAdapter but does not deal with views.

Version:
1.0
Author:
Emmanuel Cecchet , Bela Ban

Field Summary
protected  ReliableGroupChannel channel
           
protected  MessageListener listener
           
protected  java.lang.Thread readerThread
           
 
Constructor Summary
PullPushAdapter(ReliableGroupChannel channel, MessageListener listener)
          Creates a new PullPushAdapter on a channel and use the provided listener for callbacks on message reception.
 
Method Summary
 ReliableGroupChannel getChannel()
          Return the underlying channel.
 void run()
          Reentrant run(): message reception is serialized, then the listener is notified of the message reception
 java.util.ArrayList send(java.io.Serializable msg)
          Sends the given message to all members of the group.
 java.util.ArrayList send(java.io.Serializable msg, java.util.ArrayList members)
          Sends a message to a subset of group members.
 java.util.ArrayList send(java.io.Serializable msg, GroupIdentifier gid, java.util.ArrayList members)
          Sends a message to members of group gid without being necessary member of the group.
 void start()
          Start a new thread
 void stop()
          Stop the current adapter and its associated thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channel

protected ReliableGroupChannel channel

listener

protected MessageListener listener

readerThread

protected java.lang.Thread readerThread
Constructor Detail

PullPushAdapter

public PullPushAdapter(ReliableGroupChannel channel,
                       MessageListener listener)
Creates a new PullPushAdapter on a channel and use the provided listener for callbacks on message reception.

Parameters:
channel - channel to read messages from
listener - MessageListener for callbacks
Method Detail

getChannel

public ReliableGroupChannel getChannel()
Return the underlying channel.

Returns:
underlying channel

start

public void start()
Start a new thread


stop

public void stop()
Stop the current adapter and its associated thread.


send

public java.util.ArrayList send(java.io.Serializable msg)
                         throws ChannelException,
                                NotConnectedException
Sends the given message to all members of the group.

Parameters:
msg - message to send
Returns:
an ArrayList of Members who failed, or null if all members received successfully the message.
Throws:
ChannelException - if an error occurs
NotConnectedException - if the channel is not connected to any group
See Also:
ReliableGroupChannel.send(Serializable)

send

public java.util.ArrayList send(java.io.Serializable msg,
                                java.util.ArrayList members)
                         throws ChannelException,
                                NotConnectedException
Sends a message to a subset of group members.

Parameters:
msg - message to send
members - ArrayList of Member that are all part of the group
Returns:
an ArrayList of Members who failed, or null if all members received successfully the message.
Throws:
ChannelException - if an error occurs
NotConnectedException - if the channel is not connected to any group
See Also:
ReliableGroupChannel.send(Serializable, ArrayList)

send

public java.util.ArrayList send(java.io.Serializable msg,
                                GroupIdentifier gid,
                                java.util.ArrayList members)
                         throws ChannelException,
                                NotConnectedException
Sends a message to members of group gid without being necessary member of the group.

Parameters:
msg - message to send
members - ArrayList of Member that are all part of the group
Returns:
an ArrayList of Members who failed, or null if all members received successfully the message.
Throws:
ChannelException - if an error occurs
NotConnectedException - if the channel is not connected to any group
See Also:
ReliableGroupChannel.send(Serializable, GroupIdentifier, ArrayList)

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


Copyright © 2004 - ObjectWeb Consortium - All Rights Reserved.