DataType - the type of data referenced by the RefCachedDatapublic final class RefCachedData<DataType> extends Object
VolatileReference of the same data.
Instances of RefCachedData store a hard reference to the data, so
in case the VolatileReference is backed by a WeakReference
or a SoftReference, then the reference from the
VolatileReference will not disappear (unless
cleared explicitly).
It should always be the case that getDataRef().get() be the same
object as the data of the RefCachedData or
be null (if the reference disappeared from the
VolatileReference).
data is mutable then, it can
be changed. Also, the stored VolatileReference can be cleared.
| Constructor and Description |
|---|
RefCachedData(DataType data,
ObjectCache cache,
ReferenceType refType)
Initializes this
RefCachedData with the specified
data and a VolatileReference to the data,
created by the specified cache. |
RefCachedData(DataType data,
VolatileReference<DataType> dataRef)
|
| Modifier and Type | Method and Description |
|---|---|
DataType |
getData()
Returns the data which is referenced by the stored
VolatileReference returned by the
getDataRef method. |
VolatileReference<DataType> |
getDataRef()
Returns the
VolatileReference referencing the stored
data. |
String |
toString()
Returns the string representation of this
RefCachedData in no
particular format. |
public RefCachedData(DataType data, VolatileReference<DataType> dataRef)
RefCachedData with the specified
data and reference to the data.
The specified VolatileReference must return the same data
(in terms of "==") as the one specified or return null if the
data has disappeared from the reference. Note however that this is not
checked by this method.
data - the actual data which is referenced by the specified
VolatileReference. This argument can be null.dataRef - the VolatileReference referencing the specified
data. This argument cannot be null.NullPointerException - thrown if the specified
VolatileReference is nullpublic RefCachedData(DataType data, ObjectCache cache, ReferenceType refType)
RefCachedData with the specified
data and a VolatileReference to the data,
created by the specified cache.data - the actual data to which a VolatileReference will be
created using the specified cache. This argument can be null.cache - the ObjectCache to be used to create the
VolatileReference to the specified data. This argument can be
null, in which case ObjectCache.javaRefCache() will
be used instead.refType - the ReferenceType to be used to reference the
cached data using the specified ObjectCache. This argument
cannot be null.NullPointerException - thrown if the specified
ReferenceType is nullpublic DataType getData()
VolatileReference returned by the
getDataRef method.VolatileReference returned by the
getDataRef method. This method may return
null if null was specified at construction time.getDataRef()public VolatileReference<DataType> getDataRef()
VolatileReference referencing the stored
data.public String toString()