java.lang.Object
org.jtrim2.concurrent.query.RefCachedData<DataType>
- Type Parameters:
DataType- the type of data referenced by theRefCachedData
Defines a data and a
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).
Thread safety
The methods of this class are safe to be accessed by multiple threads concurrently. Once created, the properties of this class cannot be changed. Note however, that if thedata is mutable then, it can
be changed. Also, the stored VolatileReference can be cleared.
Synchronization transparency
The methods of this class are synchronization transparent.-
Constructor Summary
ConstructorsConstructorDescriptionRefCachedData(DataType data, ObjectCache cache, ReferenceType refType) Initializes thisRefCachedDatawith the specifieddataand aVolatileReferenceto the data, created by the specified cache.RefCachedData(DataType data, VolatileReference<DataType> dataRef) -
Method Summary
Modifier and TypeMethodDescriptiongetData()Returns the data which is referenced by the storedVolatileReferencereturned by thegetDataRefmethod.Returns theVolatileReferencereferencing the storeddata.toString()Returns the string representation of thisRefCachedDatain no particular format.
-
Constructor Details
-
RefCachedData
Initializes thisRefCachedDatawith the specifieddataandreferenceto the data.The specified
VolatileReferencemust return the same data (in terms of "==") as the one specified or returnnullif the data has disappeared from the reference. Note however that this is not checked by this method.- Parameters:
data- the actual data which is referenced by the specifiedVolatileReference. This argument can benull.dataRef- theVolatileReferencereferencing the specified data. This argument cannot benull.- Throws:
NullPointerException- thrown if the specifiedVolatileReferenceisnull
-
RefCachedData
Initializes thisRefCachedDatawith the specifieddataand aVolatileReferenceto the data, created by the specified cache.- Parameters:
data- the actual data to which aVolatileReferencewill be created using the specified cache. This argument can benull.cache- theObjectCacheto be used to create theVolatileReferenceto the specified data. This argument can benull, in which caseObjectCache.javaRefCache()will be used instead.refType- theReferenceTypeto be used to reference the cached data using the specifiedObjectCache. This argument cannot benull.- Throws:
NullPointerException- thrown if the specifiedReferenceTypeisnull
-
-
Method Details
-
getData
Returns the data which is referenced by the storedVolatileReferencereturned by thegetDataRefmethod.- Returns:
- the data which is referenced by the stored
VolatileReferencereturned by thegetDataRefmethod. This method may returnnullifnullwas specified at construction time. - See Also:
-
getDataRef
Returns theVolatileReferencereferencing the storeddata. -
toString
-