K
- the type of cache keysS
- the type of cached systemspublic final class SystemCache<K,S> extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
SystemCache.Factory<S>
Constructs new systems to be stored in the cache.
|
Constructor and Description |
---|
SystemCache() |
Modifier and Type | Method and Description |
---|---|
S |
get(K key)
Gets the system associated with
key if it exists. |
S |
init(K key,
SystemCache.Factory<S> factory)
Atomically initializes a system associated with
key if no such
system exists. |
void |
remove(K key)
Removes the initialized system associated with
key from the
cache. |
public S get(K key) throws InterruptedException, ExecutionException
key
if it exists. Returns
null
if there is no system associated with key
.
If a thread calls this method concurrently with another thread that is initializing a system for the same key, this thread will block until initialization completes. If an error occurs in the initialization thread, it is also reported to this thread.
InterruptedException
- if this thread is interrupted while waiting
for initializationExecutionException
- if an error occurs while this thread is
waiting for initializationpublic S init(K key, SystemCache.Factory<S> factory) throws IOException
key
if no such
system exists. If this thread initialized the system, the system is
returned. Otherwise, this method returns null
.IOException
- if an I/O error occurs while initializing the systempublic void remove(K key)
key
from the
cache.IllegalStateException
- if this method is called while
initialization is in progress.