|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Dictionary
java.util.Hashtable
org.javagroups.blocks.DistributedHashtable
Provides the abstraction of a java.util.Hashtable that is replicated at several locations. Any change to the hashtable (clear, put, 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 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
.
Nested Class Summary | |
static interface |
DistributedHashtable.Notification
|
Constructor Summary | |
DistributedHashtable(JChannel channel,
boolean persistent,
long state_timeout)
|
|
DistributedHashtable(JChannel channel,
long state_timeout)
|
|
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 |
Method Summary | |
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()
|
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)
|
java.lang.Object |
remove(java.lang.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)
|
void |
stop()
|
void |
suspect(Address suspected_mbr)
Called when a member is suspected |
void |
viewAccepted(View new_view)
Called by JavaGroups to notify the target object of a change of membership. |
Methods inherited from class java.util.Hashtable |
clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, rehash, size, toString, values |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
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 channelstate_timeout
- The time to wait until state is retrieved in milliseconds. A value of 0 means wait forever.public 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 propertiespersistent
- Whether the contents should be persistedstate_timeout
- Max number of milliseconds to wait until state is
retrievedpublic DistributedHashtable(JChannel channel, long state_timeout) throws ChannelNotConnectedException, ChannelClosedException
public DistributedHashtable(JChannel channel, boolean persistent, long state_timeout) throws ChannelNotConnectedException, ChannelClosedException
Method Detail |
protected void init(long state_timeout) throws ChannelClosedException, ChannelNotConnectedException
ChannelClosedException
ChannelNotConnectedException
public void start(long state_timeout) throws ChannelClosedException, ChannelNotConnectedException
ChannelClosedException
ChannelNotConnectedException
public Address getLocalAddress()
public java.lang.String getGroupName()
public Channel getChannel()
public boolean getPersistent()
public void setPersistent(boolean p)
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.Map
key
- - the hashtable keyvalue
- - the value
public void putAll(java.util.Map m)
putAll
in interface java.util.Map
m
- - Mappings to be stored in this mappublic void clear()
clear
in interface java.util.Map
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
key
- - 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)
receive
in interface MessageListener
public byte[] getState()
getState
in interface MessageListener
public void setState(byte[] new_state)
setState
in interface MessageListener
public void viewAccepted(View new_view)
MembershipListener
../Tests/QuoteServer.java
).
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)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |