Package org.apache.hadoop.crypto.key.kms
Class ValueQueue<E>
java.lang.Object
org.apache.hadoop.crypto.key.kms.ValueQueue<E>
A Utility class that maintains a Queue of entries for a given key. It tries
to ensure that there is are always at-least
numValues entries
available for the client to consume for a particular key.
It also uses an underlying Cache to evict queues for keys that have not been
accessed for a configurable period of time.
Implementing classes are required to implement the
QueueRefiller interface that exposes a method to refill the
queue, when empty-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceQueueRefiller interface a client must implement to use this classstatic enumPolicy to decide how many values to return to client when client asks for "n" values and Queue is empty. -
Constructor Summary
ConstructorsConstructorDescriptionValueQueue(int numValues, float lowWaterMark, long expiry, int numFillerThreads, ValueQueue.QueueRefiller<E> fetcher) ValueQueue(int numValues, float lowWatermark, long expiry, int numFillerThreads, ValueQueue.SyncGenerationPolicy policy, ValueQueue.QueueRefiller<E> refiller) Constructor takes the following tunable configuration parameters -
Method Summary
Modifier and TypeMethodDescriptionvoidDrains the Queue for the provided key.This removes the "num" values currently at the head of the Queue for the provided key.This removes the value currently at the head of the Queue for the provided key.intGet size of the Queue for keyName.voidinitializeQueuesForKeys(String... keyNames) Initializes the Value Queues for the provided keys by calling the fill Method with "numInitValues" valuesvoidshutdown()Cleanly shutdown
-
Constructor Details
-
ValueQueue
public ValueQueue(int numValues, float lowWatermark, long expiry, int numFillerThreads, ValueQueue.SyncGenerationPolicy policy, ValueQueue.QueueRefiller<E> refiller) Constructor takes the following tunable configuration parameters- Parameters:
numValues- The number of values cached in the Queue for a particular key.lowWatermark- The ratio of (number of current entries/numValues) below which thefillQueueForKey()funciton will be invoked to fill the Queue.expiry- Expiry time after which the Key and associated Queue are evicted from the cache.numFillerThreads- Number of threads to use for the filler threadpolicy- The SyncGenerationPolicy to use when client calls "getAtMost"refiller- implementation of the QueueRefiller
-
ValueQueue
public ValueQueue(int numValues, float lowWaterMark, long expiry, int numFillerThreads, ValueQueue.QueueRefiller<E> fetcher)
-
-
Method Details
-
initializeQueuesForKeys
Initializes the Value Queues for the provided keys by calling the fill Method with "numInitValues" values- Parameters:
keyNames- Array of key Names- Throws:
IOException- if initialization fails for any provided keys
-
getNext
This removes the value currently at the head of the Queue for the provided key. Will immediately fire the Queue filler function if key does not exist. If Queue exists but all values are drained, It will ask the generator function to add 1 value to Queue and then drain it.- Parameters:
keyName- String key name- Returns:
- E the next value in the Queue
- Throws:
IOException- raised on errors performing I/O.ExecutionException- executionException.
-
drain
Drains the Queue for the provided key.- Parameters:
keyName- the key to drain the Queue for
-
getSize
Get size of the Queue for keyName. This is only used in unit tests.- Parameters:
keyName- the key name- Returns:
- int queue size. Zero means the queue is empty or the key does not exist.
-
getAtMost
This removes the "num" values currently at the head of the Queue for the provided key. Will immediately fire the Queue filler function if key does not exist How many values are actually returned is governed by theSyncGenerationPolicyspecified by the user.- Parameters:
keyName- String key namenum- Minimum number of values to return.- Returns:
- List<E> values returned
- Throws:
IOException- raised on errors performing I/O.ExecutionException- execution exception.
-
shutdown
public void shutdown()Cleanly shutdown
-