org.jgroups.blocks
Class DistributedHashtable

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable
          extended by org.jgroups.blocks.DistributedHashtable
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map, ExtendedMembershipListener, ExtendedMessageListener, MembershipListener, MessageListener

Deprecated. Use ReplicatedHashMap instead

public class DistributedHashtable
extends java.util.Hashtable
implements ExtendedMessageListener, ExtendedMembershipListener

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.

Version:
$Id: DistributedHashtable.java,v 1.38 2010/01/09 16:03:11 belaban Exp $
Author:
Bela Ban, Alfonso Olias-Sanz
See Also:
Serialized Form

Nested Class Summary
static interface DistributedHashtable.Notification
          Deprecated.  
 
Field Summary
protected  RpcDispatcher disp
          Deprecated.  
protected  Log log
          Deprecated.  
protected  Promise<java.lang.Boolean> state_promise
          Deprecated.  
 
Constructor Summary
DistributedHashtable(Channel channel, boolean persistent, long state_timeout)
          Deprecated.  
DistributedHashtable(Channel channel, long state_timeout)
          Deprecated.  
DistributedHashtable(PullPushAdapter adapter, java.io.Serializable id)
          Deprecated. 
DistributedHashtable(PullPushAdapter adapter, java.io.Serializable id, long state_timeout)
          Deprecated. 
DistributedHashtable(java.lang.String groupname, ChannelFactory factory, java.lang.String properties, boolean persistent, long state_timeout)
          Deprecated. Creates a DisttributedHashtable.
DistributedHashtable(java.lang.String groupname, ChannelFactory factory, java.lang.String properties, long state_timeout)
          Deprecated. Creates a DistributedHashtable
 
Method Summary
 void _clear()
          Deprecated.  
 java.lang.Object _put(java.lang.Object key, java.lang.Object value)
          Deprecated.  
 void _putAll(java.util.Map m)
          Deprecated.  
 java.lang.Object _remove(java.lang.Object key)
          Deprecated.  
 void addNotifier(DistributedHashtable.Notification n)
          Deprecated.  
 void block()
          Deprecated. Block sending and receiving of messages until ViewAccepted is called
 void clear()
          Deprecated. Clears this hashtable so that it contains no keys
 Channel getChannel()
          Deprecated.  
 java.lang.String getGroupName()
          Deprecated.  
 Address getLocalAddress()
          Deprecated.  
 boolean getPersistent()
          Deprecated.  
 byte[] getState()
          Deprecated. Answers the group state; e.g., when joining.
 void getState(java.io.OutputStream ostream)
          Deprecated. Allows an application to write a state through a provided OutputStream.
 byte[] getState(java.lang.String state_id)
          Deprecated. Allows an application to provide a partial state as a byte array
 void getState(java.lang.String state_id, java.io.OutputStream ostream)
          Deprecated. Allows an application to write a partial state through a provided OutputStream.
protected  void init(long state_timeout)
          Deprecated.  
static void main(java.lang.String[] args)
          Deprecated.  
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Deprecated. Maps the specified key to the specified value in the hashtable.
 void putAll(java.util.Map m)
          Deprecated. 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)
          Deprecated. Called when a message is received.
 java.lang.Object remove(java.lang.Object key)
          Deprecated. Removes the key (and its corresponding value) from the Hashtable.
 void removeNotifier(DistributedHashtable.Notification n)
          Deprecated.  
 void setDeadlockDetection(boolean flag)
          Deprecated.  
 void setPersistent(boolean p)
          Deprecated.  
 void setState(byte[] new_state)
          Deprecated. Sets the group state; e.g., when joining.
 void setState(java.io.InputStream istream)
          Deprecated. Allows an application to read a state through a provided InputStream.
 void setState(java.lang.String state_id, byte[] state)
          Deprecated. Allows an application to read a partial state indicated by state_id from a given state byte array parameter.
 void setState(java.lang.String state_id, java.io.InputStream istream)
          Deprecated. Allows an application to read a partial state through a provided InputStream.
 void start(long state_timeout)
          Deprecated. Fetches the state
 void stop()
          Deprecated.  
 void suspect(Address suspected_mbr)
          Deprecated. Called when a member is suspected
 void unblock()
          Deprecated. Called after the FLUSH protocol has unblocked previously blocked senders, and messages can be sent again.
 void viewAccepted(View new_view)
          Deprecated. Called when a change in membership has occurred.
 
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
 

Field Detail

disp

protected transient RpcDispatcher disp
Deprecated. 

state_promise

protected final transient Promise<java.lang.Boolean> state_promise
Deprecated. 

log

protected final Log log
Deprecated. 
Constructor Detail

DistributedHashtable

public DistributedHashtable(java.lang.String groupname,
                            ChannelFactory factory,
                            java.lang.String properties,
                            long state_timeout)
                     throws ChannelException
Deprecated. 
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. This will override the properties of the factory. If null, then the factory properties will be used
state_timeout - The time to wait until state is retrieved in milliseconds. A value of 0 means wait forever.
Throws:
ChannelException

DistributedHashtable

public DistributedHashtable(java.lang.String groupname,
                            ChannelFactory factory,
                            java.lang.String properties,
                            boolean persistent,
                            long state_timeout)
                     throws ChannelException
Deprecated. 
Creates a DisttributedHashtable. Optionally the contents can be saved to persistemt storage using the PersistenceManager.

Parameters:
groupname - Name of the group to join
factory - Instance of a ChannelFactory to create the channel
properties - Protocol stack properties. This will override the properties of the factory. If null, then the factory properties will be used
persistent - Whether the contents should be persisted
state_timeout - Max number of milliseconds to wait until state is retrieved
Throws:
ChannelException

DistributedHashtable

public DistributedHashtable(Channel channel,
                            long state_timeout)
Deprecated. 

DistributedHashtable

public DistributedHashtable(Channel channel,
                            boolean persistent,
                            long state_timeout)
Deprecated. 

DistributedHashtable

@Deprecated
public DistributedHashtable(PullPushAdapter adapter,
                                       java.io.Serializable id,
                                       long state_timeout)
                     throws ChannelNotConnectedException,
                            ChannelClosedException
Deprecated. 

Uses a user-provided PullPushAdapter to create the dispatcher rather than a Channel. If id is non-null, it will be used to register under that id. This is typically used when another building block is already using PullPushAdapter, and we want to add this building block in addition. The id is the used to discriminate between messages for the various blocks on top of PullPushAdapter. If null, we will assume we are the first block created on PullPushAdapter.

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
Throws:
ChannelNotConnectedException
ChannelClosedException

DistributedHashtable

@Deprecated
public DistributedHashtable(PullPushAdapter adapter,
                                       java.io.Serializable id)
Deprecated. 

Method Detail

init

protected final void init(long state_timeout)
Deprecated. 

start

public final void start(long state_timeout)
                 throws ChannelClosedException,
                        ChannelNotConnectedException
Deprecated. 
Fetches the state

Parameters:
state_timeout -
Throws:
ChannelClosedException
ChannelNotConnectedException

getLocalAddress

public Address getLocalAddress()
Deprecated. 

getGroupName

public java.lang.String getGroupName()
Deprecated. 

getChannel

public Channel getChannel()
Deprecated. 

getPersistent

public boolean getPersistent()
Deprecated. 

setPersistent

public void setPersistent(boolean p)
Deprecated. 

setDeadlockDetection

public void setDeadlockDetection(boolean flag)
Deprecated. 

addNotifier

public void addNotifier(DistributedHashtable.Notification n)
Deprecated. 

removeNotifier

public void removeNotifier(DistributedHashtable.Notification n)
Deprecated. 

stop

public void stop()
Deprecated. 

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Deprecated. 
Maps the specified key to the specified value in the hashtable. Neither of both parameters can be null

Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.Hashtable
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

putAll

public void putAll(java.util.Map m)
Deprecated. 
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.

Specified by:
putAll in interface java.util.Map
Overrides:
putAll in class java.util.Hashtable
Parameters:
m - - Mappings to be stored in this map

clear

public void clear()
Deprecated. 
Clears this hashtable so that it contains no keys

Specified by:
clear in interface java.util.Map
Overrides:
clear in class java.util.Hashtable

remove

public java.lang.Object remove(java.lang.Object key)
Deprecated. 
Removes the key (and its corresponding value) from the Hashtable.

Specified by:
remove in interface java.util.Map
Overrides:
remove in class java.util.Hashtable
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.

_put

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

_putAll

public void _putAll(java.util.Map m)
Deprecated. 
See Also:
Map.putAll(java.util.Map)

_clear

public void _clear()
Deprecated. 

_remove

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

receive

public void receive(Message msg)
Deprecated. 
Description copied from interface: MessageListener
Called when a message is received.

Specified by:
receive in interface MessageListener

getState

public byte[] getState()
Deprecated. 
Description copied from interface: MessageListener
Answers the group state; e.g., when joining.

Specified by:
getState in interface MessageListener
Returns:
byte[]

setState

public void setState(byte[] new_state)
Deprecated. 
Description copied from interface: MessageListener
Sets the group state; e.g., when joining.

Specified by:
setState in interface MessageListener

viewAccepted

public void viewAccepted(View new_view)
Deprecated. 
Description copied from interface: MembershipListener
Called when a change in membership has occurred. No long running actions or sending of messages should be done in this callback. If some long running action needs to be performed, it should be done in a separate thread.

Note that on reception of the first view (a new member just joined), the channel will not yet be in the connected state. This only happens when Channel.connect(String) returns.

Specified by:
viewAccepted in interface MembershipListener

suspect

public void suspect(Address suspected_mbr)
Deprecated. 
Called when a member is suspected

Specified by:
suspect in interface MembershipListener

block

public void block()
Deprecated. 
Block sending and receiving of messages until ViewAccepted is called

Specified by:
block in interface MembershipListener

main

public static void main(java.lang.String[] args)
Deprecated. 

getState

public byte[] getState(java.lang.String state_id)
Deprecated. 
Description copied from interface: ExtendedMessageListener
Allows an application to provide a partial state as a byte array

Specified by:
getState in interface ExtendedMessageListener
Parameters:
state_id - id of the partial state requested
Returns:
partial state for the given state_id

getState

public void getState(java.io.OutputStream ostream)
Deprecated. 
Description copied from interface: ExtendedMessageListener
Allows an application to write a state through a provided OutputStream. An application is obligated to always close the given OutputStream reference.

Specified by:
getState in interface ExtendedMessageListener
Parameters:
ostream - the OutputStream
See Also:
OutputStream.close()

getState

public void getState(java.lang.String state_id,
                     java.io.OutputStream ostream)
Deprecated. 
Description copied from interface: ExtendedMessageListener
Allows an application to write a partial state through a provided OutputStream. An application is obligated to always close the given OutputStream reference.

Specified by:
getState in interface ExtendedMessageListener
Parameters:
state_id - id of the partial state requested
ostream - the OutputStream
See Also:
OutputStream.close()

setState

public void setState(java.lang.String state_id,
                     byte[] state)
Deprecated. 
Description copied from interface: ExtendedMessageListener
Allows an application to read a partial state indicated by state_id from a given state byte array parameter.

Specified by:
setState in interface ExtendedMessageListener
Parameters:
state_id - id of the partial state requested
state - partial state for the given state_id

setState

public void setState(java.io.InputStream istream)
Deprecated. 
Description copied from interface: ExtendedMessageListener
Allows an application to read a state through a provided InputStream. An application is obligated to always close the given InputStream reference.

Specified by:
setState in interface ExtendedMessageListener
Parameters:
istream - the InputStream
See Also:
InputStream.close()

setState

public void setState(java.lang.String state_id,
                     java.io.InputStream istream)
Deprecated. 
Description copied from interface: ExtendedMessageListener
Allows an application to read a partial state through a provided InputStream. An application is obligated to always close the given InputStream reference.

Specified by:
setState in interface ExtendedMessageListener
Parameters:
state_id - id of the partial state requested
istream - the InputStream
See Also:
InputStream.close()

unblock

public void unblock()
Deprecated. 
Description copied from interface: ExtendedMembershipListener
Called after the FLUSH protocol has unblocked previously blocked senders, and messages can be sent again. This callback only needs to be implemented if we require a notification of that.

Note that during new view installation we provide guarantee that unblock invocation strictly follows view installation at some node A belonging to that view . However, some other message M may squeeze in between view and unblock callbacks. For more details see https://jira.jboss.org/jira/browse/JGRP-986

Specified by:
unblock in interface ExtendedMembershipListener


Copyright © 1998-2009 Bela Ban / Red Hat. All Rights Reserved.