Package com.usatiuk.objects
Class JDataVersionedWrapperLazy
java.lang.Object
com.usatiuk.objects.JDataVersionedWrapperLazy
- All Implemented Interfaces:
Data<JDataVersionedWrapper>
,MaybeTombstone<JDataVersionedWrapper>
,JDataVersionedWrapper
Lazy JDataVersionedWrapper implementation.
The object is deserialized only when data() is called for the first time.
Also allows to set a callback to be called when the data is loaded (e.g. to cache it).
-
Constructor Summary
ConstructorsConstructorDescriptionJDataVersionedWrapperLazy
(long version, int estimatedSize, Supplier<JData> producer) Creates a new JDataVersionedWrapperLazy object. -
Method Summary
Modifier and TypeMethodDescriptiondata()
Returns the wrapped object.int
Returns the estimated size of the object in bytes.void
setCacheCallback
(Runnable cacheCallback) Set a callback to be called when the data is loaded.long
version()
Returns the version number of the object.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.usatiuk.objects.JDataVersionedWrapper
value
-
Constructor Details
-
JDataVersionedWrapperLazy
Creates a new JDataVersionedWrapperLazy object.- Parameters:
version
- the version number of the objectestimatedSize
- the estimated size of the object in bytesproducer
- a supplier that produces the wrapped object
-
-
Method Details
-
setCacheCallback
Set a callback to be called when the data is loaded.- Parameters:
cacheCallback
- the callback to be called
-
data
Description copied from interface:JDataVersionedWrapper
Returns the wrapped object.- Specified by:
data
in interfaceJDataVersionedWrapper
- Returns:
- the wrapped object
-
version
public long version()Description copied from interface:JDataVersionedWrapper
Returns the version number of the object.- Specified by:
version
in interfaceJDataVersionedWrapper
- Returns:
- the version number of the object
-
estimateSize
public int estimateSize()Description copied from interface:JDataVersionedWrapper
Returns the estimated size of the object in bytes.- Specified by:
estimateSize
in interfaceJDataVersionedWrapper
- Returns:
- the estimated size of the object in bytes
-