Interface PersistenceManager

    • Method Detail

      • isEnabled

        boolean isEnabled()
      • isPreloaded

        boolean isPreloaded()
        Returns:
        true if all entries from the store have been inserted to the cache. If the persistence/preload is disabled or eviction limit was reached when preloading, returns false.
      • preload

        void preload()
        Loads the data from the external store into memory during cache startup.
      • disableStore

        void disableStore​(java.lang.String storeType)
        Marks the given storage as disabled.
      • getStores

        <T> java.util.Set<T> getStores​(java.lang.Class<T> storeClass)
      • getStoresAsString

        java.util.Collection<java.lang.String> getStoresAsString()
      • purgeExpired

        void purgeExpired()
        Removes the expired entries from all the existing storage.
      • deleteFromAllStores

        boolean deleteFromAllStores​(java.lang.Object key,
                                    int segment,
                                    java.util.function.Predicate<? super StoreConfiguration> predicate)
      • publishEntries

        <K,​V> org.reactivestreams.Publisher<MarshalledEntry<K,​V>> publishEntries​(java.util.function.Predicate<? super K> filter,
                                                                                             boolean fetchValue,
                                                                                             boolean fetchMetadata,
                                                                                             java.util.function.Predicate<? super StoreConfiguration> predicate)
        Returns a publisher that will publish all entries stored by the underlying cache store. Only the first cache store that implements AdvancedCacheLoader will be used. Predicate is applied by the underlying loader in a best attempt to improve performance.

        Caller can tell the store to also fetch the value or metadata. In some cases this can improve performance. If metadata is not fetched the publisher may include expired entries.

        Type Parameters:
        K - key type
        V - value type
        Parameters:
        filter - filter so that only entries whose key matches are returned
        fetchValue - whether to fetch value or not
        fetchMetadata - whether to fetch metadata or not
        predicate - whether a store can be used by publish entries
        Returns:
        publisher that will publish entries
      • publishEntries

        <K,​V> org.reactivestreams.Publisher<MarshalledEntry<K,​V>> publishEntries​(IntSet segments,
                                                                                             java.util.function.Predicate<? super K> filter,
                                                                                             boolean fetchValue,
                                                                                             boolean fetchMetadata,
                                                                                             java.util.function.Predicate<? super StoreConfiguration> predicate)
        Returns a publisher that will publish entries that map to the provided segments. It will attempt to find the first segmented store if one is available. If not it will fall back to the first non segmented store and filter out entries that don't map to the provided segment.
        Type Parameters:
        K - key type
        V - value type
        Parameters:
        segments - only entries that map to these segments are processed
        filter - filter so that only entries whose key matches are returned
        fetchValue - whether to fetch value or not
        fetchMetadata - whether to fetch metadata or not
        predicate - whether a store can be used by publish entries
        Returns:
        publisher that will publish entries belonging to the given segments
      • publishKeys

        <K> org.reactivestreams.Publisher<K> publishKeys​(java.util.function.Predicate<? super K> filter,
                                                         java.util.function.Predicate<? super StoreConfiguration> predicate)
        Returns a publisher that will publish all keys stored by the underlying cache store. Only the first cache store that implements AdvancedCacheLoader will be used. Predicate is applied by the underlying loader in a best attempt to improve performance.

        This method should be preferred over publishEntries(Predicate, boolean, boolean, Predicate) when only keys are desired as many stores can do this in a significantly more performant way.

        This publisher will never return a key which belongs to an expired entry

        Type Parameters:
        K - key type
        Parameters:
        filter - filter so that only keys which match are returned
        predicate - access mode to choose what type of loader to use
        Returns:
        publisher that will publish keys
      • publishKeys

        <K> org.reactivestreams.Publisher<K> publishKeys​(IntSet segments,
                                                         java.util.function.Predicate<? super K> filter,
                                                         java.util.function.Predicate<? super StoreConfiguration> predicate)
        Returns a publisher that will publish keys that map to the provided segments. It will attempt to find the first segmented store if one is available. If not it will fall back to the first non segmented store and filter out entries that don't map to the provided segment.

        This method should be preferred over publishEntries(IntSet, Predicate, boolean, boolean, Predicate) when only keys are desired as many stores can do this in a significantly more performant way.

        This publisher will never return a key which belongs to an expired entry

        Type Parameters:
        K - key type
        Parameters:
        segments - only keys that map to these segments are processed
        filter - filter so that only keys which match are returned
        predicate - access mode to choose what type of loader to use
        Returns:
        publisher that will publish keys belonging to the given segments
      • loadFromAllStores

        MarshalledEntry loadFromAllStores​(java.lang.Object key,
                                          boolean localInvocation,
                                          boolean includeStores)
        Loads an entry from the persistence store for the given key. The returned value may be null. This value is guaranteed to not be expired when it was returned.
        Parameters:
        key - key to read the entry from
        localInvocation - whether this invocation is a local invocation. Some loaders may be ignored if it is not local
        includeStores - if a loader that is also a store can be loaded from
        Returns:
        entry that maps to the key
      • loadFromAllStores

        default MarshalledEntry loadFromAllStores​(java.lang.Object key,
                                                  int segment,
                                                  boolean localInvocation,
                                                  boolean includeStores)
        Same as loadFromAllStores(Object, boolean, boolean) except that the segment of the key is also provided to avoid having to calculate the segment.
        Parameters:
        key - key to read the entry from
        segment - segment the key maps to
        localInvocation - whether this invocation is a local invocation. Some loaders may be ignored if it is not local
        includeStores - if a loader that is also a store can be loaded from
        Returns:
        entry that maps to the key
      • getStateTransferProvider

        AdvancedCacheLoader getStateTransferProvider()
        Returns the store one configured with fetch persistent state, or null if none exist.
      • size

        default int size()
      • size

        int size​(java.util.function.Predicate<? super StoreConfiguration> predicate)
        Returns the count of how many entries are persisted. If no store can handle the request for the given mode a value of -1 is returned instead.
        Parameters:
        predicate - whether a loader can be used
        Returns:
        size or -1 if size couldn't be computed
      • size

        int size​(IntSet segments)
        Returns the count of how many entries are persisted within the given segments. The returned value will always be 0 or greater.
        Parameters:
        segments - which segments to count entries from
        Returns:
        how many entries are in the store which map to the given segments
      • setClearOnStop

        void setClearOnStop​(boolean clearOnStop)
      • writeToAllNonTxStores

        void writeToAllNonTxStores​(MarshalledEntry marshalledEntry,
                                   int segment,
                                   java.util.function.Predicate<? super StoreConfiguration> predicate)
        Write to all stores that are not transactional. A store is considered transactional if all of the following are true:

        • The store implements TransactionalCacheWriter
        • The store is configured to be transactional
        • The cache's TransactionMode === TRANSACTIONAL

        Parameters:
        marshalledEntry - the entry to be written to all non-tx stores.
        segment - the segment the entry maps to
        predicate - should we write to a given store
      • prepareAllTxStores

        void prepareAllTxStores​(javax.transaction.Transaction transaction,
                                BatchModification batchModification,
                                java.util.function.Predicate<? super StoreConfiguration> predicate)
                         throws PersistenceException
        Perform the prepare phase of 2PC on all Tx stores.
        Parameters:
        transaction - the current transactional context.
        batchModification - an object containing the write/remove operations required for this transaction.
        predicate - should we prepare on a given store
        Throws:
        PersistenceException - if an error is encountered at any of the underlying stores.
      • commitAllTxStores

        void commitAllTxStores​(javax.transaction.Transaction transaction,
                               java.util.function.Predicate<? super StoreConfiguration> predicate)
        Perform the commit operation for the provided transaction on all Tx stores.
        Parameters:
        transaction - the transactional context to be committed.
        predicate - should we commit each store
      • rollbackAllTxStores

        void rollbackAllTxStores​(javax.transaction.Transaction transaction,
                                 java.util.function.Predicate<? super StoreConfiguration> predicate)
        Perform the rollback operation for the provided transaction on all Tx stores.
        Parameters:
        transaction - the transactional context to be rolledback.
        predicate - should we rollback each store
      • writeBatchToAllNonTxStores

        void writeBatchToAllNonTxStores​(java.lang.Iterable<MarshalledEntry> entries,
                                        java.util.function.Predicate<? super StoreConfiguration> predicate,
                                        long flags)
        Write all entries to the underlying non-transactional stores as a single batch.
        Parameters:
        entries - a List of MarshalledEntry to be written to the store.
        predicate - whether a given store should write the entry
        flags - Flags used during command invocation
      • deleteBatchFromAllNonTxStores

        void deleteBatchFromAllNonTxStores​(java.lang.Iterable<java.lang.Object> keys,
                                           java.util.function.Predicate<? super StoreConfiguration> predicate,
                                           long flags)
        Remove all entries from the underlying non-transactional stores as a single batch.
        Parameters:
        keys - a List of Keys to be removed from the store.
        predicate - whether a given store should delete the entries
        flags - Flags used during command invocation
      • isAvailable

        boolean isAvailable()
        Returns:
        true if all configured stores are available and ready for read/write operations.
      • addSegments

        default boolean addSegments​(IntSet segments)
        Notifies any underlying segmented stores that the segments provided are owned by this cache and to start/configure any underlying resources required to handle requests for entries on the given segments.

        This only affects stores that are not shared as shared stores have to keep all segments running at all times

        This method returns true if all stores were able to handle the added segments. That is that either there are no stores or that all the configured stores are segmented. Note that configured loaders do not affect the return value.

        Parameters:
        segments - segments this cache owns
        Returns:
        false if a configured store couldn't configure newly added segments
      • removeSegments

        default boolean removeSegments​(IntSet segments)
        Notifies any underlying segmented stores that a given segment is no longer owned by this cache and allowing it to remove the given segments and release resources related to it.

        This only affects stores that are not shared as shared stores have to keep all segments running at all times

        This method returns true if all stores were able to handle the added segments. That is that either there are no stores or that all the configured stores are segmented. Note that configured loaders do not affect the return value.

        Parameters:
        segments - segments this cache no longer owns
        Returns:
        false if a configured store couldn't remove configured segments