Interface SubjectDataCache<I>
-
public interface SubjectDataCache<I>
A cached view of the subject data within a particularDataStore.Provides operations to manage querying, writing, and updating
ImmutableSubjectDataobjects.- Since:
- 2.0.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddListener(I identifier, Consumer<ImmutableSubjectData> listener)Add a listener to be notified on updates to the given subjectvoidcacheAll()Enter all subjects of this type into cacheCompletableFuture<ImmutableSubjectData>data(I identifier, @Nullable Consumer<ImmutableSubjectData> listener)Get data for a given subject.Stream<I>getAllIdentifiers()Get a set of identifiers for all registered subjects of this typeSubjectRef<SubjectType<?>>getDefaultIdentifier()Get the identifier for the subject holding default data for subjects of this typevoidinvalidate(I identifier)Remove a given subject identifier from the cacheCompletableFuture<Boolean>isRegistered(I identifier)Check if a given subject is registered.voidload(I identifier)Load data (if any) known for the given identifierCompletableFuture<? extends SubjectRef.ToData<I>>referenceTo(I identifier)Get a reference to subject data for a given subject.CompletableFuture<? extends SubjectRef.ToData<I>>referenceTo(I identifier, boolean strongListeners)Get a reference to subject data for a given subjectCompletableFuture<ImmutableSubjectData>remove(I identifier)Remove a subject from the backing data storeCompletableFuture<ImmutableSubjectData>set(I identifier, @Nullable ImmutableSubjectData newData)Set the data foridentifier.SubjectType<I>type()Get the subject type for this cache.CompletableFuture<ImmutableSubjectData>update(I identifier, UnaryOperator<ImmutableSubjectData> action)Update data for a given subject, acting on the latest data available.
-
-
-
Method Detail
-
type
SubjectType<I> type()
Get the subject type for this cache.- Returns:
- the subject type this cache contains data for
- Since:
- 2.0.0
-
data
CompletableFuture<ImmutableSubjectData> data(I identifier, @Nullable Consumer<ImmutableSubjectData> listener)
Get data for a given subject.This will return a data object even if the subject is not registered; the data object will just be empty.
For most longer-lifetime use cases,
referenceTo(Object)will be the preferred method to get a reference to the latest subject data.- Parameters:
identifier- The identifier of the subject to querylistener- A callback that will be notified whenever a change is made to the data object- Returns:
- A future returning when the data is available
-
referenceTo
CompletableFuture<? extends SubjectRef.ToData<I>> referenceTo(I identifier)
Get a reference to subject data for a given subject. The reference will update as changes are made to the backing data store, and can always be used to query a specific subject's raw data.- Parameters:
identifier- The identifier of the subject to get data for- Returns:
- A future returning with a full reference to the given subject's data.
-
referenceTo
CompletableFuture<? extends SubjectRef.ToData<I>> referenceTo(I identifier, boolean strongListeners)
Get a reference to subject data for a given subject- Parameters:
identifier- The identifier of the subject to get data forstrongListeners- Whether to hold listeners to this subject data even after they would be otherwise GC'd- Returns:
- A future completing with the subject data reference
-
update
CompletableFuture<ImmutableSubjectData> update(I identifier, UnaryOperator<ImmutableSubjectData> action)
Update data for a given subject, acting on the latest data available. Theactioncallback may be called within an asynchronous task.- Parameters:
identifier- The identifier of the subject to be updatedaction- A function taking an old subject data instance and returning an updated one- Returns:
- A future completing with the latest subject data after modifications are made
-
load
void load(I identifier)
Load data (if any) known for the given identifier- Parameters:
identifier- The subject identifier
-
invalidate
void invalidate(I identifier)
Remove a given subject identifier from the cache- Parameters:
identifier- The identifier of the subject to be removed
-
cacheAll
void cacheAll()
Enter all subjects of this type into cache
-
isRegistered
CompletableFuture<Boolean> isRegistered(I identifier)
Check if a given subject is registered. This operation occurs asynchronously Registered means that a subject has any sort of data stored.- Parameters:
identifier- The identifier of the subject to check- Returns:
- A future returning whether the subject has data stored
-
remove
CompletableFuture<ImmutableSubjectData> remove(I identifier)
Remove a subject from the backing data store- Parameters:
identifier- The identifier of the subject to remove- Returns:
- A future returning the previous subject data.
-
set
CompletableFuture<ImmutableSubjectData> set(I identifier, @Nullable ImmutableSubjectData newData)
Set the data foridentifier.- Parameters:
identifier- identifier of the target subjectnewData- data to set for the subject,nullto clear all data.- Returns:
- a future completing with the newly set subject data.
-
addListener
void addListener(I identifier, Consumer<ImmutableSubjectData> listener)
Add a listener to be notified on updates to the given subject- Parameters:
identifier- The identifier of the subject to receive notifications aboutlistener- The callback function to notify
-
getAllIdentifiers
Stream<I> getAllIdentifiers()
Get a set of identifiers for all registered subjects of this type- Returns:
- The set of identifiers
-
getDefaultIdentifier
SubjectRef<SubjectType<?>> getDefaultIdentifier()
Get the identifier for the subject holding default data for subjects of this type- Returns:
- The id for the default subject of this type
-
-