|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.util.ReferenceHolder<T>
public abstract class ReferenceHolder<T>
useful to easily cache a large value 'softly' or 'weakly' through a ValueRetriever
using a Reference.
If the reference is garbage collected, the value is re-retrieved via
the embedded ValueRetriever.
| Constructor Summary | |
|---|---|
protected |
ReferenceHolder(com.antelmann.util.ReferenceHolder.Kind kind,
ValueRetriever<T> retriever)
|
| Method Summary | |
|---|---|
boolean |
clear()
releases the instance and returns true only if it was previously held in memory. |
T |
getRelevantValue()
if the value is still cached via the embedded reference, it is returned; otherwise it is re-retrieved (and again cached). |
T |
getValue()
returns getRelevantValue() but wraps occurring exceptions into RuntimeExceptions
(convenience method) |
boolean |
isAvailable()
returns true only if the reference is currently cached |
boolean |
isWired()
|
void |
refreshContent()
refreshes the embedded content |
void |
setCurrentValue(T value)
allows to manually set the value independent of the embedded retriever. |
void |
setRetriever(ValueRetriever<T> retriever)
|
void |
setWired(boolean flag)
allows to 'hold' the value in memory, so that it won't be garbage-collected and not re-retrieved until unwired. |
ValueRetriever<T> |
unwrap()
returns the embedded instance that this wrapper encloses |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected ReferenceHolder(com.antelmann.util.ReferenceHolder.Kind kind,
ValueRetriever<T> retriever)
| Method Detail |
|---|
public void setRetriever(ValueRetriever<T> retriever)
public boolean isAvailable()
public boolean isWired()
public void setWired(boolean flag)
@Warning(value="using this method may result in having multiple instance of the retrieved value in memory if the value was held im memory elsewhere") public boolean clear()
getRelevantValue()
is called again, you may end up with more than one instance of the retrieved value in memory.
Note that calling this method also 'unwires' the content for this instance.
setWired(boolean)
public void refreshContent()
throws IOException
Refreshable
refreshContent in interface RefreshableIOException - if the refresh failed
public T getValue()
throws RuntimeException
getRelevantValue() but wraps occurring exceptions into RuntimeExceptions
(convenience method)
RuntimeException
public T getRelevantValue()
throws IOException
getRelevantValue in interface ValueRetriever<T>IOException - if any resource to fulfill the request is not accessiblepublic void setCurrentValue(T value)
getRelevantValue(),
unless the caller ensures that the value may not be garbage-collected through keeping a hard link to its value.
setWired(boolean)public ValueRetriever<T> unwrap()
Wrapped
unwrap in interface Wrapped<ValueRetriever<T>>
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||