org.jgroups.blocks
public class DistributedHashtable extends Hashtable implements MessageListener, MembershipListener
Both keys and values added to the hashtable must be serializable, the reason
being that they will be sent across the network to all replicas of the group. Having said
this, it is now for example possible to add RMI remote objects to the hashtable as they
are derived from java.rmi.server.RemoteObject
which in turn is serializable.
This allows to lookup shared distributed objects by their name and invoke methods on them,
regardless of one's onw location. A DistributedHashtable
thus allows to
implement a distributed naming service in just a couple of lines.
An instance of this class will contact an existing member of the group to fetch its
initial state (using the state exchange funclet StateExchangeFunclet
.
Version: $Id: DistributedHashtable.java,v 1.20 2005/11/10 20:54:01 belaban Exp $
Nested Class Summary | |
---|---|
interface | DistributedHashtable.Notification |
Field Summary | |
---|---|
protected RpcDispatcher | disp |
protected Log | log |
protected Promise | state_promise |
Constructor Summary | |
---|---|
DistributedHashtable(String groupname, ChannelFactory factory, String properties, long state_timeout)
Creates a DistributedHashtable | |
DistributedHashtable(String groupname, ChannelFactory factory, String properties, boolean persistent, long state_timeout)
Creates a DisttributedHashtable. | |
DistributedHashtable(JChannel channel, long state_timeout) | |
DistributedHashtable(JChannel channel, boolean persistent, long state_timeout) | |
DistributedHashtable(PullPushAdapter adapter, Serializable id, long state_timeout)
Uses a user-provided PullPushAdapter to create the dispatcher rather than a Channel. | |
DistributedHashtable(PullPushAdapter adapter, Serializable id) |
Method Summary | |
---|---|
void | addNotifier(DistributedHashtable.Notification n) |
void | block() Block sending and receiving of messages until ViewAccepted is called |
void | clear()
Clears this hashtable so that it contains no keys |
Channel | getChannel() |
String | getGroupName() |
Address | getLocalAddress() |
boolean | getPersistent() |
byte[] | getState() |
protected void | init(long state_timeout) |
static void | main(String[] args) |
Object | put(Object key, Object value)
Maps the specified key to the specified value in the hashtable. |
void | putAll(Map m)
Copies all of the mappings from the specified Map to this Hashtable These mappings will replace any mappings that this Hashtable had for any of the keys currently in the specified Map. |
void | receive(Message msg) |
Object | remove(Object key)
Removes the key (and its corresponding value) from the Hashtable. |
void | removeNotifier(DistributedHashtable.Notification n) |
void | setPersistent(boolean p) |
void | setState(byte[] new_state) |
void | start(long state_timeout)
Fetches the state |
void | stop() |
void | suspect(Address suspected_mbr) Called when a member is suspected |
void | viewAccepted(View new_view) |
void | _clear() |
Object | _put(Object key, Object value) |
void | _putAll(Map m) |
Object | _remove(Object key) |
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.
Parameters: groupname Name of the group to join factory Instance of a ChannelFactory to create the channel properties Protocol stack properties persistent Whether the contents should be persisted state_timeout Max number of milliseconds to wait until state is retrieved
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. state_timeout Max number of milliseconds to wait until state is retrieved
Parameters: key - the hashtable key value - the value
Returns: the previous value of the specified key in this hashtable, or null if it did not have one
Parameters: m - Mappings to be stored in this map
Parameters: key - the key to be removed.
Returns: the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping.
Parameters: state_timeout
Throws: ChannelClosedException ChannelNotConnectedException
See Also: java.util.Map#putAll(java.util.Map)