public class DistributedHashtable extends java.util.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.
| Modifier and Type | Class and Description |
|---|---|
static interface |
DistributedHashtable.Notification |
| Modifier and Type | Field and Description |
|---|---|
protected RpcDispatcher |
disp |
protected org.apache.commons.logging.Log |
log |
protected Promise |
state_promise |
| Constructor and Description |
|---|
DistributedHashtable(Channel channel,
boolean persistent,
long state_timeout) |
DistributedHashtable(Channel channel,
long state_timeout) |
DistributedHashtable(PullPushAdapter adapter,
java.io.Serializable id) |
DistributedHashtable(PullPushAdapter adapter,
java.io.Serializable id,
long state_timeout)
Uses a user-provided PullPushAdapter to create the dispatcher rather than a Channel.
|
DistributedHashtable(java.lang.String groupname,
ChannelFactory factory,
java.lang.String properties,
boolean persistent,
long state_timeout)
Creates a DisttributedHashtable.
|
DistributedHashtable(java.lang.String groupname,
ChannelFactory factory,
java.lang.String properties,
long state_timeout)
Creates a DistributedHashtable
|
| Modifier and Type | Method and Description |
|---|---|
void |
_clear() |
java.lang.Object |
_put(java.lang.Object key,
java.lang.Object value) |
void |
_putAll(java.util.Map m) |
java.lang.Object |
_remove(java.lang.Object key) |
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() |
java.lang.String |
getGroupName() |
Address |
getLocalAddress() |
boolean |
getPersistent() |
byte[] |
getState()
Answers the group state; e.g., when joining.
|
protected void |
init(long state_timeout) |
static void |
main(java.lang.String[] args) |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Maps the specified key to the specified value in the hashtable.
|
void |
putAll(java.util.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)
Called when a message is received.
|
java.lang.Object |
remove(java.lang.Object key)
Removes the key (and its corresponding value) from the Hashtable.
|
void |
removeNotifier(DistributedHashtable.Notification n) |
void |
setDeadlockDetection(boolean flag) |
void |
setPersistent(boolean p) |
void |
setState(byte[] new_state)
Sets the group state; e.g., when joining.
|
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)
Called when a change in membership has occurred.
|
protected transient RpcDispatcher disp
protected final transient Promise state_promise
protected final org.apache.commons.logging.Log log
public DistributedHashtable(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 channel. This will override the properties of
the factory. If null, then the factory properties will be usedstate_timeout - The time to wait until state is retrieved in milliseconds. A value of 0 means wait forever.ChannelExceptionpublic DistributedHashtable(java.lang.String groupname,
ChannelFactory factory,
java.lang.String properties,
boolean persistent,
long state_timeout)
throws ChannelException
PersistenceManager.groupname - Name of the group to joinfactory - Instance of a ChannelFactory to create the channelproperties - Protocol stack properties. This will override the properties of the factory. If
null, then the factory properties will be usedpersistent - Whether the contents should be persistedstate_timeout - Max number of milliseconds to wait until state is
retrievedChannelExceptionpublic DistributedHashtable(Channel channel, long state_timeout)
public DistributedHashtable(Channel channel, boolean persistent, long state_timeout)
public DistributedHashtable(PullPushAdapter adapter, java.io.Serializable id, long state_timeout) throws ChannelNotConnectedException, ChannelClosedException
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.state_timeout - Max number of milliseconds to wait until state is
retrievedChannelNotConnectedExceptionChannelClosedExceptionpublic DistributedHashtable(PullPushAdapter adapter, java.io.Serializable id)
protected final void init(long state_timeout)
public final void start(long state_timeout)
throws ChannelClosedException,
ChannelNotConnectedException
state_timeout - ChannelClosedExceptionChannelNotConnectedExceptionpublic Address getLocalAddress()
public java.lang.String getGroupName()
public Channel getChannel()
public boolean getPersistent()
public void setPersistent(boolean p)
public void setDeadlockDetection(boolean flag)
public void addNotifier(DistributedHashtable.Notification n)
public void removeNotifier(DistributedHashtable.Notification n)
public void stop()
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
put in interface java.util.Mapput in class java.util.Hashtablekey - - the hashtable keyvalue - - the valuepublic void putAll(java.util.Map m)
putAll in interface java.util.MapputAll in class java.util.Hashtablem - - Mappings to be stored in this mappublic void clear()
clear in interface java.util.Mapclear in class java.util.Hashtablepublic java.lang.Object remove(java.lang.Object key)
remove in interface java.util.Mapremove in class java.util.Hashtablekey - - the key to be removed.public java.lang.Object _put(java.lang.Object key,
java.lang.Object value)
public void _putAll(java.util.Map m)
Map.putAll(java.util.Map)public void _clear()
public java.lang.Object _remove(java.lang.Object key)
public void receive(Message msg)
MessageListenerreceive in interface MessageListenerpublic byte[] getState()
MessageListenergetState in interface MessageListenerpublic void setState(byte[] new_state)
MessageListenersetState in interface MessageListenerpublic void viewAccepted(View new_view)
MembershipListenerviewAccepted in interface MembershipListenerpublic void suspect(Address suspected_mbr)
suspect in interface MembershipListenerpublic void block()
block in interface MembershipListenerpublic static void main(java.lang.String[] args)
Copyright ? 1998-2006 Bela Ban. All Rights Reserved.