com.sleepycat.je.rep.utilint
Class SizeAwaitMap<K,V>

java.lang.Object
  extended by com.sleepycat.je.rep.utilint.SizeAwaitMap<K,V>
All Implemented Interfaces:
Map<K,V>

public class SizeAwaitMap<K,V>
extends Object
implements Map<K,V>

Creates a Map, that Threads can conveniently wait on to reach a specific size. The wait functionality is provided by the sizeAwait() method defined by this class.


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
SizeAwaitMap(EnvironmentImpl envImpl, Map<K,V> map)
          Creates the wrapped Map class.
 
Method Summary
 void clear()
          Deprecated. Use clear(Exception) instead.
 void clear(Exception cause)
          Clears the underlying map and the latch map, after first counting them down, thus permitting them to make progress.
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object key)
           
 StatGroup getStatistics()
           
 boolean isEmpty()
           
 Set<K> keySet()
           
(package private)  int latchCount()
          Used for unit tests only
 V put(K key, V value)
          Notes the addition of a new value and counts down any latches that were assigned to that threshold.
 void putAll(Map<? extends K,? extends V> t)
           
 V remove(Object key)
          It's synchronized so that size() has a stable value in the above methods.
 int size()
           
 boolean sizeAwait(int thresholdSize, long timeout, TimeUnit unit)
          Causes the requesting thread to wait until the map reaches the specified size or the thread is interrupted.
 Collection<V> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

SizeAwaitMap

public SizeAwaitMap(EnvironmentImpl envImpl,
                    Map<K,V> map)
Creates the wrapped Map class. Note that the application must not directly manipulate the underlying map class. The underlying map must be synchronized if it's accessed concurrently.

Parameters:
map - the actual map instance.
Method Detail

getStatistics

public StatGroup getStatistics()

sizeAwait

public boolean sizeAwait(int thresholdSize,
                         long timeout,
                         TimeUnit unit)
                  throws InterruptedException
Causes the requesting thread to wait until the map reaches the specified size or the thread is interrupted.

Parameters:
thresholdSize - the size to wait for.
Returns:
true if the threshold was reached, false, if the wait timed out.
Throws:
InterruptedException - for the usual reasons, or if the map was cleared and the size threshold was not actually reached.

latchCount

int latchCount()
Used for unit tests only

Returns:

put

public V put(K key,
             V value)
Notes the addition of a new value and counts down any latches that were assigned to that threshold.

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

remove

public V remove(Object key)
It's synchronized so that size() has a stable value in the above methods.

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

clear

public void clear()
           throws UnsupportedOperationException
Deprecated. Use clear(Exception) instead.

Specified by:
clear in interface Map<K,V>
Throws:
UnsupportedOperationException

clear

public void clear(Exception cause)
Clears the underlying map and the latch map, after first counting them down, thus permitting them to make progress.


containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>

get

public V get(Object key)
Specified by:
get in interface Map<K,V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>

putAll

public void putAll(Map<? extends K,? extends V> t)
Specified by:
putAll in interface Map<K,V>

size

public int size()
Specified by:
size in interface Map<K,V>

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>


Copyright (c) 2004-2012 Oracle. All rights reserved.