Class ReferencedObject<T>
java.lang.Object
com.github.cafapi.common.util.ref.ReferencedObject<T>
- Type Parameters:
T
- the type of the wrapped, referenced object
Utility wrapper for allowing data to potentially be within a message or located on a remote DataStore. The acquire(ObjectSource) method
allows transparent method of obtaining the wrapped data, which will only be retrieved the first time acquire is called (if it is not
already present).
It should be noted that because this class returns a fully formed Java object instance, the entire instance must be loaded into memory.
As such, this wrapper should only be used for objects that are at most a few megabytes of data.
-
Method Summary
Modifier and TypeMethodDescriptionacquire
(DataSource source) Return the referenced object, potentially performing a remote DataStore lookup and deserialisation.static <T> ReferencedObject<T>
getReferencedObject
(Class<T> clazz, String ref) Create a ReferencedObject that uses a remote reference to data present in an ObjectSource.static <T> ReferencedObject<T>
getWrappedObject
(Class<T> clazz, T obj) Create a ReferencedObject that directly wraps an object without a reference.
-
Method Details
-
acquire
Return the referenced object, potentially performing a remote DataStore lookup and deserialisation. If the object is already present or has been previously acquired, it is immediately returned.- Parameters:
source
- the implementation that provides object instances given the provided references- Returns:
- the object that this container is wrapping
- Throws:
DataSourceException
- if the object cannot be acquiredIllegalStateException
- if there is no object or reference present
-
getReference
- Returns:
- the remote reference to the object in the DataStore, if set
-
getReferencedObject
Create a ReferencedObject that uses a remote reference to data present in an ObjectSource.- Type Parameters:
T
- the type of the referenced object- Parameters:
clazz
- the class of the referenced objectref
- the reference to be interpreted by the DataStore- Returns:
- a new ReferencedObject instance that relates to a remote object via reference
-
getWrappedObject
Create a ReferencedObject that directly wraps an object without a reference.- Type Parameters:
T
- the type of the object- Parameters:
clazz
- the class of the objectobj
- the object to wrapper- Returns:
- a new ReferencedObject instance that directly wraps the object specified
-