com.google.code.rees.scope.util.monitor
Class HashMonitoredContext<K,V,T extends MonitoredContext<K,V,T>>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by com.google.code.rees.scope.util.monitor.HashMonitoredContext<K,V,T>
All Implemented Interfaces:
MonitoredContext<K,V,T>, Timeoutable<T>, Serializable, Cloneable, Map<K,V>
Direct Known Subclasses:
DefaultConversationContext

public abstract class HashMonitoredContext<K,V,T extends MonitoredContext<K,V,T>>
extends HashMap<K,V>
implements MonitoredContext<K,V,T>

A Serializable Hash implementation of the Map and Timeoutable interfaces. Resets its own remaining time whenever the wrapped HashMap is accessed.

Author:
rees.byars
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  long maxIdleTime
           
protected  long timeOfMostRecentAccess
           
protected  Collection<TimeoutListener<T>> timeoutListeners
           
 
Constructor Summary
HashMonitoredContext(long maxIdleTime)
           
 
Method Summary
 void addTimeoutListener(TimeoutListener<T> timeoutListener)
          Add a listener whose TimeoutListener.onTimeout(Object) method will be called when this Timeoutable's Timeoutable.timeout() method is called.
 Set<Map.Entry<K,V>> entrySet()
          
 V get(Object key)
          
 long getRemainingTime()
          The time remaining until this Timeoutable's Timeoutable.timeout() method will be called
 Set<K> keySet()
          
protected  void ping()
           
 V put(K key, V value)
          
 void putAll(Map<? extends K,? extends V> m)
          
 V remove(Object key)
          
 void reset()
          Resets this Timeoutable's remaining time to the max idle time
 void setMaxIdleTime(long maxIdleTime)
          Sets the time after which this Timeoutable's Timeoutable.timeout() method will be called
 void timeout()
          Called when this Timeoutable's Timeoutable.getRemainingTime() is equal to or less than zero (i.e.
 Collection<V> values()
          
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, isEmpty, size
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, equals, hashCode, isEmpty, size
 
Methods inherited from interface com.google.code.rees.scope.util.monitor.Timeoutable
getId
 

Field Detail

timeoutListeners

protected Collection<TimeoutListener<T extends MonitoredContext<K,V,T>>> timeoutListeners

timeOfMostRecentAccess

protected long timeOfMostRecentAccess

maxIdleTime

protected long maxIdleTime
Constructor Detail

HashMonitoredContext

public HashMonitoredContext(long maxIdleTime)
Method Detail

get

public V get(Object key)

Specified by:
get in interface Map<K,V>
Overrides:
get in class HashMap<K,V>

put

public V put(K key,
             V value)

Specified by:
put in interface Map<K,V>
Overrides:
put in class HashMap<K,V>

putAll

public void putAll(Map<? extends K,? extends V> m)

Specified by:
putAll in interface Map<K,V>
Overrides:
putAll in class HashMap<K,V>

values

public Collection<V> values()

Specified by:
values in interface Map<K,V>
Overrides:
values in class HashMap<K,V>

remove

public V remove(Object key)

Specified by:
remove in interface Map<K,V>
Overrides:
remove in class HashMap<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()

Specified by:
entrySet in interface Map<K,V>
Overrides:
entrySet in class HashMap<K,V>

keySet

public Set<K> keySet()

Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class HashMap<K,V>

getRemainingTime

public long getRemainingTime()
The time remaining until this Timeoutable's Timeoutable.timeout() method will be called

Specified by:
getRemainingTime in interface Timeoutable<T extends MonitoredContext<K,V,T>>
Returns:

reset

public void reset()
Resets this Timeoutable's remaining time to the max idle time

Specified by:
reset in interface Timeoutable<T extends MonitoredContext<K,V,T>>

setMaxIdleTime

public void setMaxIdleTime(long maxIdleTime)
Sets the time after which this Timeoutable's Timeoutable.timeout() method will be called

Specified by:
setMaxIdleTime in interface Timeoutable<T extends MonitoredContext<K,V,T>>

addTimeoutListener

public void addTimeoutListener(TimeoutListener<T> timeoutListener)
Add a listener whose TimeoutListener.onTimeout(Object) method will be called when this Timeoutable's Timeoutable.timeout() method is called.

Specified by:
addTimeoutListener in interface Timeoutable<T extends MonitoredContext<K,V,T>>

timeout

public void timeout()
Called when this Timeoutable's Timeoutable.getRemainingTime() is equal to or less than zero (i.e. the max idle time has been exceeded).

Specified by:
timeout in interface Timeoutable<T extends MonitoredContext<K,V,T>>

ping

protected void ping()


Copyright © 2012-2013. All Rights Reserved.