org.javagroups.blocks
Class ReplicatedHashtable
java.lang.Object
|
+--java.util.Dictionary
|
+--java.util.Hashtable
|
+--org.javagroups.blocks.ReplicatedHashtable
- All Implemented Interfaces:
- java.lang.Cloneable, java.util.Map, MembershipListener, MessageListener, java.io.Serializable
- public class ReplicatedHashtable
- extends java.util.Hashtable
- implements MessageListener, MembershipListener, java.lang.Cloneable
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 ReplicatedHashtable
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.
Contrary to DistributedHashtable, this class does not make use of RpcDispatcher (and RequestCorrelator)
but uses plain asynchronous messages instead.
- Author:
- Bela Ban
- See Also:
- Serialized Form
Inner classes inherited from class java.util.Map |
java.util.Map.Entry |
Methods inherited from class java.util.Hashtable |
clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, putAll, rehash, size, toString, values |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
ReplicatedHashtable
public ReplicatedHashtable(java.lang.String groupname,
ChannelFactory factory,
java.lang.String properties,
long state_timeout)
- Creates a ReplicatedHashtable
- Parameters:
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.
ReplicatedHashtable
public ReplicatedHashtable(JChannel channel,
long state_timeout)
getLocalAddress
public Address getLocalAddress()
getChannel
public Channel getChannel()
addNotifier
public void addNotifier(ReplicatedHashtable.Notification n)
put
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
- Overrides:
put
in class java.util.Hashtable
clear
public void clear()
- Overrides:
clear
in class java.util.Hashtable
remove
public java.lang.Object remove(java.lang.Object key)
- Overrides:
remove
in class java.util.Hashtable
receive
public void receive(Message msg)
- Specified by:
receive
in interface MessageListener
getState
public java.lang.Object getState()
- Specified by:
getState
in interface MessageListener
setState
public void setState(java.lang.Object new_state)
- Specified by:
setState
in interface MessageListener
viewAccepted
public void viewAccepted(View new_view)
- Description copied from interface:
MembershipListener
- Called by JavaGroups to notify the target object of a change of membership.
No long running actions should be done in this callback in the case of Ensemble,
as this would block Ensemble. If some long running action needs to be performed,
it should be done in a separate thread (cf.
../Tests/QuoteServer.java
).
- Specified by:
viewAccepted
in interface MembershipListener
suspect
public void suspect(Address suspected_mbr)
- Called when a member is suspected
- Specified by:
suspect
in interface MembershipListener
block
public void block()
- Block sending and receiving of messages until ViewAccepted is called
- Specified by:
block
in interface MembershipListener
Copyright © 2001,2002 www.javagroups.com . All Rights Reserved.