public class DistributedQueue extends java.lang.Object implements MessageListener, MembershipListener, java.lang.Cloneable
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.
Modifier and Type | Class and Description |
---|---|
static interface |
DistributedQueue.Notification |
Modifier and Type | Field and Description |
---|---|
protected Channel |
channel |
protected RpcDispatcher |
disp |
protected java.lang.String |
groupname |
protected java.util.LinkedList |
internalQueue |
protected org.apache.commons.logging.Log |
logger |
protected java.util.Vector |
members |
protected java.lang.Object |
mutex |
protected java.util.Vector |
notifs |
protected boolean |
stopped |
Constructor and Description |
---|
DistributedQueue(JChannel channel) |
DistributedQueue(PullPushAdapter adapter,
java.io.Serializable id)
Uses a user-provided PullPushAdapter to create the dispatcher rather than a Channel.
|
DistributedQueue(java.lang.String groupname,
ChannelFactory factory,
java.lang.String properties,
long state_timeout)
Creates a DistributedQueue
|
Modifier and Type | Method and Description |
---|---|
void |
_add(java.lang.Object value) |
void |
_addAll(java.util.Collection c) |
void |
_addAtHead(java.lang.Object value) |
protected void |
_private_reset() |
java.lang.Object |
_remove() |
void |
_reset() |
void |
add(java.lang.Object value)
Add the speficied element at the bottom of the queue
|
void |
addAll(java.util.Collection values)
Add the speficied collection to the top of the queue.
|
void |
addAtHead(java.lang.Object value)
Add the speficied element at the top of the queue
|
void |
addNotifier(DistributedQueue.Notification n) |
void |
block()
Block sending and receiving of messages until ViewAccepted is called
|
protected void |
checkResult(RspList rsp,
java.lang.Object retval) |
Channel |
getChannel() |
java.util.Vector |
getContents() |
Address |
getLocalAddress() |
byte[] |
getState()
Answers the group state; e.g., when joining.
|
protected void |
init() |
static void |
main(java.lang.String[] args) |
java.lang.Object |
peek()
returns the first object on the queue, without removing it.
|
void |
receive(Message msg)
Called when a message is received.
|
java.lang.Object |
remove()
Try to return the first objet in the queue.It does not wait for an object.
|
java.lang.Object |
remove(long timeout) |
void |
removeNotifier(DistributedQueue.Notification n) |
void |
reset() |
void |
setState(byte[] new_state)
Sets the group state; e.g., when joining.
|
int |
size() |
void |
start(long state_timeout) |
void |
stop() |
void |
suspect(Address suspected_mbr)
Called when a member is suspected
|
java.lang.String |
toString() |
void |
viewAccepted(View new_view)
Called when a change in membership has occurred.
|
protected org.apache.commons.logging.Log logger
protected final java.lang.Object mutex
protected boolean stopped
protected java.util.LinkedList internalQueue
protected Channel channel
protected RpcDispatcher disp
protected java.lang.String groupname
protected java.util.Vector notifs
protected java.util.Vector members
public DistributedQueue(java.lang.String groupname, ChannelFactory factory, java.lang.String properties, long state_timeout) throws ChannelException
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.ChannelException
public DistributedQueue(JChannel channel)
public DistributedQueue(PullPushAdapter adapter, java.io.Serializable id)
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.protected final void init()
public final void start(long state_timeout) throws ChannelClosedException, ChannelNotConnectedException
public Address getLocalAddress()
public Channel getChannel()
public void addNotifier(DistributedQueue.Notification n)
public void removeNotifier(DistributedQueue.Notification n)
public void stop()
public void add(java.lang.Object value)
value
- public void addAtHead(java.lang.Object value)
value
- public void addAll(java.util.Collection values)
values
- public java.util.Vector getContents()
public int size()
public java.lang.Object peek()
public void reset()
protected void checkResult(RspList rsp, java.lang.Object retval)
public java.lang.Object remove()
public java.lang.Object remove(long timeout)
timeout
- The time to wait until an entry is retrieved in milliseconds. A value of 0 means wait forever.public java.lang.String toString()
toString
in class java.lang.Object
public void _add(java.lang.Object value)
public void _addAtHead(java.lang.Object value)
public void _reset()
protected void _private_reset()
public java.lang.Object _remove()
public void _addAll(java.util.Collection c)
public void receive(Message msg)
MessageListener
receive
in interface MessageListener
public byte[] getState()
MessageListener
getState
in interface MessageListener
public void setState(byte[] new_state)
MessageListener
setState
in interface MessageListener
public void viewAccepted(View new_view)
MembershipListener
viewAccepted
in interface MembershipListener
public void suspect(Address suspected_mbr)
suspect
in interface MembershipListener
public void block()
block
in interface MembershipListener
public static void main(java.lang.String[] args)
Copyright ? 1998-2006 Bela Ban. All Rights Reserved.