org.openbp.common.util
Class ExpirationHashtable

java.lang.Object
  extended by org.openbp.common.util.ExpirationHashtable

public class ExpirationHashtable
extends java.lang.Object

This is an implementation of a simple hashtable which removes its elements after a given timeout period. The expiration timeout is restarted on each lookup of an object.

Author:
Falk Hartmann

Constructor Summary
ExpirationHashtable(long defaultTimeout)
          Constructor.
 
Method Summary
 boolean containsKey(java.lang.Object key)
          This method checks, whether the passed object is used as key in this hashtable.
 java.util.Enumeration elements()
          Returns an enumeration of the values in this hashtable.
 java.util.Set entrySet()
          Returns the entry set of the table.
 java.lang.Object get(java.lang.Object key)
          Returns the value to which the specified key is mapped in this hashtable.
 java.util.Enumeration keys()
          Returns an enumeration of the keys in this hashtable.
 java.util.Set keySet()
          Returns the key set of the table.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Maps the specified key to the specified value in this hashtable.
 java.lang.Object put(java.lang.Object key, java.lang.Object value, long timeout)
          Maps the specified key to the specified value in this hashtable.
 java.lang.Object remove(java.lang.Object key)
          This method removes the object registered with the given key and returns it.
 void setDisposalListener(DisposalListener disposalListener)
          This method sets a disposal listener for this container.
 int size()
          Returns the current size of the hashtable.
 java.util.Collection values()
          Returns the values of the table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpirationHashtable

public ExpirationHashtable(long defaultTimeout)
Constructor.

Parameters:
defaultTimeout - The timeout in milliseconds, after which an object should be removed from the hashtable. Each lookup of the object restarts the timeout period.
Method Detail

containsKey

public boolean containsKey(java.lang.Object key)
This method checks, whether the passed object is used as key in this hashtable.

Parameters:
key - The key to check for
Returns:
true if the key is a valid key in the hashtable

entrySet

public java.util.Set entrySet()
Returns the entry set of the table.

Returns:
A set of Map.Entry objects

keySet

public java.util.Set keySet()
Returns the key set of the table.

Returns:
The set of hash keys

values

public java.util.Collection values()
Returns the values of the table.

Returns:
The collection of hash values

elements

public java.util.Enumeration elements()
Returns an enumeration of the values in this hashtable.

Returns:
an enumeration of the values in this hashtable

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which the specified key is mapped in this hashtable.

Parameters:
key - A key in the hashtable
Returns:
the value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.

keys

public java.util.Enumeration keys()
Returns an enumeration of the keys in this hashtable.

Returns:
an enumeration of the keys in this hashtable

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null. The value can be retrieved by calling the get method with a key that is equal to the original key. The timeout value used to construct the expiration hashtable is used as timeout.

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.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value,
                            long timeout)
Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null. The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
key - the hashtable key
value - the value
timeout - the timeout in milliseconds, after which the value expires; use 0 for no expiration
Returns:
the previous value of the specified key in this hashtable, or null if it did not have one.

remove

public java.lang.Object remove(java.lang.Object key)
This method removes the object registered with the given key and returns it.

Parameters:
key - The key to remove the value for
Returns:
The object removed

setDisposalListener

public void setDisposalListener(DisposalListener disposalListener)
This method sets a disposal listener for this container. The listener will be invoked for each element that gets removed from the container due to expiration.

Parameters:
disposalListener - The listener to be called

size

public int size()
Returns the current size of the hashtable.

Returns:
The size of the hashtable


Copyright © 2011. All Rights Reserved.