V - type of referent encapsulated and reloaded by this classpublic final class ReloadingReference<V> extends Object
Callable is given that can create the thing is provided.
This can also periodically re-create or reload the value.| Modifier and Type | Field and Description |
|---|---|
static long |
NO_RELOAD |
| Constructor and Description |
|---|
ReloadingReference(Callable<V> retriever) |
ReloadingReference(Callable<V> retriever,
long duration,
TimeUnit timeUnit) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears the reference, requiring a load on next access.
|
V |
get() |
V |
get(long timeout,
TimeUnit timeUnit)
Like
get(), but when a value already exists, will only wait for the given amount of time before
just proceeding to return the existing value instead of waiting for a new value to load. |
V |
maybeGet() |
public static final long NO_RELOAD
public ReloadingReference(Callable<V> retriever, long duration, TimeUnit timeUnit)
retriever - object that can supply a new, current value of the referenceduration - time after which a new value will be loaded, or NO_RELOAD to not reload
after the initial value is loadedtimeUnit - units of time for durationpublic V get(long timeout, TimeUnit timeUnit)
get(), but when a value already exists, will only wait for the given amount of time before
just proceeding to return the existing value instead of waiting for a new value to load.public V get()
Callable. If not yet created, it will block and
wait for creation. If already created, it will return the existing value. The value will be re-created
periodically, if the object has been configured to, and when this is needed, this method will again
block while the value is re-created.public V maybeGet()
Callable, if it has already been created
previously, or null otherwisepublic void clear()
Copyright © 2012-2013 Myrrix Ltd. All Rights Reserved.