org.jgroups.blocks

Class DistributedQueue

public class DistributedQueue extends Object implements MessageListener, MembershipListener, Cloneable

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.

Author: Romuald du Song

Nested Class Summary
interfaceDistributedQueue.Notification
Field Summary
protected Channelchannel
protected RpcDispatcherdisp
protected Stringgroupname
protected LinkedListinternalQueue
protected Loglogger
protected Vectormembers
protected Objectmutex
protected Vectornotifs
protected booleanstopped
Constructor Summary
DistributedQueue(String groupname, ChannelFactory factory, String properties, long state_timeout)
Creates a DistributedQueue
DistributedQueue(JChannel channel)
DistributedQueue(PullPushAdapter adapter, Serializable id)
Uses a user-provided PullPushAdapter to create the dispatcher rather than a Channel.
Method Summary
voidadd(Object value)
Add the speficied element at the bottom of the queue
voidaddAll(Collection values)
Add the speficied collection to the top of the queue.
voidaddAtHead(Object value)
Add the speficied element at the top of the queue
voidaddNotifier(DistributedQueue.Notification n)
voidblock()
Block sending and receiving of messages until ViewAccepted is called
protected voidcheckResult(RspList rsp, Object retval)
ChannelgetChannel()
VectorgetContents()
AddressgetLocalAddress()
byte[]getState()
protected voidinit()
static voidmain(String[] args)
Objectpeek()
returns the first object on the queue, without removing it.
voidreceive(Message msg)
Objectremove()
Try to return the first objet in the queue.It does not wait for an object.
Objectremove(long timeout)
voidremoveNotifier(DistributedQueue.Notification n)
voidreset()
voidsetState(byte[] new_state)
intsize()
voidstart(long state_timeout)
voidstop()
voidsuspect(Address suspected_mbr)
Called when a member is suspected
StringtoString()
voidviewAccepted(View new_view)
void_add(Object value)
void_addAll(Collection c)
void_addAtHead(Object value)
protected void_private_reset()
Object_remove()
void_reset()

Field Detail

channel

protected transient Channel channel

disp

protected transient RpcDispatcher disp

groupname

protected transient String groupname

internalQueue

protected LinkedList internalQueue

logger

protected Log logger

members

protected transient Vector members

mutex

protected Object mutex

notifs

protected transient Vector notifs

stopped

protected transient boolean stopped

Constructor Detail

DistributedQueue

public DistributedQueue(String groupname, ChannelFactory factory, String properties, long state_timeout)
Creates a DistributedQueue

Parameters: groupname The name of the group to join factory The ChannelFactory which will be used to create a channel properties The property string to be used to define the channel state_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.

Parameters: adapter The PullPushAdapter which to use as underlying transport id A serializable object (e.g. an Integer) used to discriminate (multiplex/demultiplex) between requests/responses for different building blocks on top of PullPushAdapter.

Method Detail

add

public void add(Object value)
Add the speficied element at the bottom of the queue

Parameters: value

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.

Parameters: values

addAtHead

public void addAtHead(Object value)
Add the speficied element at the top of the queue

Parameters: value

addNotifier

public void addNotifier(DistributedQueue.Notification n)

block

public void block()
Block sending and receiving of messages until ViewAccepted is called

checkResult

protected void checkResult(RspList rsp, Object retval)

getChannel

public Channel getChannel()

getContents

public Vector getContents()

getLocalAddress

public Address getLocalAddress()

getState

public byte[] getState()

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

Returns: the first object on the queue

receive

public void receive(Message msg)

remove

public Object remove()
Try to return the first objet in the queue.It does not wait for an object.

Returns: the first object in the queue or null if none were found.

remove

public Object remove(long timeout)

Parameters: timeout The time to wait until an entry is retrieved in milliseconds. A value of 0 means wait forever.

Returns: the first object in the queue or null if none were found

removeNotifier

public void removeNotifier(DistributedQueue.Notification n)

reset

public void reset()

setState

public void setState(byte[] new_state)

size

public int size()

start

public void start(long state_timeout)

stop

public void stop()

suspect

public void suspect(Address suspected_mbr)
Called when a member is suspected

toString

public String toString()

viewAccepted

public void viewAccepted(View new_view)

_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()
Copyright ? 1998-2005 Bela Ban. All Rights Reserved.