org.javagroups.blocks
Class DistributedHashtable

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--org.javagroups.blocks.DistributedHashtable
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, MembershipListener, MessageListener, java.io.Serializable

public class DistributedHashtable
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 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.

Author:
Bela Ban
See Also:
Serialized Form

Inner Class Summary
static interface DistributedHashtable.Notification
           
 
Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
DistributedHashtable(JChannel channel, long state_timeout)
           
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)
           
 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()
           
 Channel getChannel()
           
 Address getLocalAddress()
           
 java.lang.Object getState()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void receive(Message msg)
           
 java.lang.Object remove(java.lang.Object key)
           
 void setState(java.lang.Object new_state)
           
 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, putAll, rehash, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DistributedHashtable

public DistributedHashtable(java.lang.String groupname,
                            ChannelFactory factory,
                            java.lang.String properties,
                            long state_timeout)
Creates a DistributedHashtable
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.

DistributedHashtable

public DistributedHashtable(JChannel channel,
                            long state_timeout)
Method Detail

getLocalAddress

public Address getLocalAddress()

getChannel

public Channel getChannel()

stop

public void stop()

addNotifier

public void addNotifier(DistributedHashtable.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

_put

public java.lang.Object _put(java.lang.Object key,
                             java.lang.Object value)

_clear

public void _clear()

_remove

public java.lang.Object _remove(java.lang.Object key)

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.