org.jgroups.blocks
Class DistributedQueue
java.lang.Object
org.jgroups.blocks.DistributedQueue
- Cloneable, MembershipListener, MessageListener
public class DistributedQueue
extends java.lang.Object
Provides the abstraction of a java.util.LinkedList that is replicated at several
locations. Any change to the list (reset, add, remove, etc.) will transparently be
propagated to all replicas in the group. All read-only methods will always access the
local replica.
Both keys and values added to the list
must be serializable, the reason
being that they will be sent across the network to all replicas of the group.
An instance of this class will contact an existing member of the group to fetch its
initial state.
Beware to use a
total protocol on initialization or elements would not be in same
order on all replicas.
groupname
protected String groupname
internalQueue
protected LinkedList internalQueue
logger
protected Log logger
members
protected Vector members
mutex
protected Object mutex
notifs
protected Vector notifs
stopped
protected boolean stopped
DistributedQueue
public DistributedQueue(String groupname,
ChannelFactory factory,
String properties,
long state_timeout)
throws ChannelException
Creates a DistributedQueue
groupname
- The name of the group to joinfactory
- The ChannelFactory which will be used to create a channelproperties
- The property string to be used to define the channelstate_timeout
- The time to wait until state is retrieved in milliseconds. A value of 0 means wait forever.
DistributedQueue
public DistributedQueue(JChannel channel)
DistributedQueue
public DistributedQueue(PullPushAdapter adapter,
Serializable id)
Uses a user-provided PullPushAdapter to create the dispatcher rather than a Channel. If id is non-null, it will be
used to register under that id. This is typically used when another building block is already using
PullPushAdapter, and we want to add this building block in addition. The id is the used to discriminate
between messages for the various blocks on top of PullPushAdapter. If null, we will assume we are the
first block created on PullPushAdapter.
The caller needs to call start(), before using the this block. It gives the opportunity for the caller
to register as a lessoner for Notifications events.
adapter
- The PullPushAdapter which to use as underlying transportid
- A serializable object (e.g. an Integer) used to discriminate (multiplex/demultiplex) between
requests/responses for different building blocks on top of PullPushAdapter.
_add
public void _add(Object value)
_addAll
public void _addAll(Collection c)
_addAtHead
public void _addAtHead(Object value)
_private_reset
protected void _private_reset()
_remove
public Object _remove()
_reset
public void _reset()
add
public void add(Object value)
Add the speficied element at the bottom of the queue
addAll
public void addAll(Collection values)
Add the speficied collection to the top of the queue.
Elements are added in the order that they are returned by the specified
collection's iterator.
addAtHead
public void addAtHead(Object value)
Add the speficied element at the top of the queue
block
public void block()
Block sending and receiving of messages until ViewAccepted is called
- block in interface MembershipListener
checkResult
protected void checkResult(RspList rsp,
Object retval)
getChannel
public Channel getChannel()
getContents
public Vector getContents()
getLocalAddress
public Address getLocalAddress()
getState
public byte[] getState()
Answers the group state; e.g., when joining.
- getState in interface MessageListener
init
protected void init()
main
public static void main(String[] args)
peek
public Object peek()
returns the first object on the queue, without removing it.
If the queue is empty this object blocks until the first queue object has
been added
- the first object on the queue
remove
public Object remove()
Try to return the first objet in the queue.It does not wait for an object.
- the first object in the queue or null if none were found.
remove
public Object remove(long timeout)
timeout
- The time to wait until an entry is retrieved in milliseconds. A value of 0 means wait forever.
- the first object in the queue or null if none were found
setState
public void setState(byte[] new_state)
Sets the group state; e.g., when joining.
- setState in interface MessageListener
toString
public String toString()
Copyright B) 1998-2005 Bela Ban. All Rights Reserved.