Interface SubjectDataCache<I>

    • Method Detail

      • type

        SubjectType<Itype()
        Get the subject type for this cache.
        Returns:
        the subject type this cache contains data for
        Since:
        2.0.0
      • data

        CompletableFuture<ImmutableSubjectDatadata​(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 query
        listener - 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 for
        strongListeners - 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<ImmutableSubjectDataupdate​(I identifier,
                                                       UnaryOperator<ImmutableSubjectData> action)
        Update data for a given subject, acting on the latest data available. The action callback may be called within an asynchronous task.
        Parameters:
        identifier - The identifier of the subject to be updated
        action - 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<BooleanisRegistered​(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<ImmutableSubjectDataremove​(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<ImmutableSubjectDataset​(I identifier,
                                                    @Nullable ImmutableSubjectData newData)
        Set the data for identifier.
        Parameters:
        identifier - identifier of the target subject
        newData - data to set for the subject, null to 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 about
        listener - The callback function to notify
      • getAllIdentifiers

        Stream<IgetAllIdentifiers()
        Get a set of identifiers for all registered subjects of this type
        Returns:
        The set of identifiers
      • getDefaultIdentifier

        SubjectRef<StringgetDefaultIdentifier()
        Get the identifier for the subject holding default data for subjects of this type
        Returns:
        The id for the default subject of this type