Interface MetadataCache<T>

  • All Known Implementing Classes:
    MetadataCacheImpl

    public interface MetadataCache<T>
    Represent the caching layer access for a specific type of objects.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<java.lang.Void> create​(java.lang.String path, T value)
      Create a new object in the metadata store.
      java.util.concurrent.CompletableFuture<java.lang.Void> delete​(java.lang.String path)
      Delete an object from the metadata store.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> exists​(java.lang.String path)
      Read whether a specific path exists.
      java.util.concurrent.CompletableFuture<java.util.Optional<T>> get​(java.lang.String path)
      Tries to fetch one item from the cache or fallback to the store if not present.
      java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> getChildren​(java.lang.String path)
      Return all the nodes (lexicographically sorted) that are children to the specific path.
      java.util.Optional<T> getIfCached​(java.lang.String path)
      Check if an object is present in cache without triggering a load from the metadata store.
      java.util.concurrent.CompletableFuture<java.util.Optional<CacheGetResult<T>>> getWithStats​(java.lang.String path)
      Tries to fetch one item from the cache or fallback to the store if not present.
      void invalidate​(java.lang.String path)
      Force the invalidation of an object in the metadata cache.
      java.util.concurrent.CompletableFuture<T> readModifyUpdate​(java.lang.String path, java.util.function.Function<T,​T> modifyFunction)
      Perform an atomic read-modify-update of the value.
      java.util.concurrent.CompletableFuture<T> readModifyUpdateOrCreate​(java.lang.String path, java.util.function.Function<java.util.Optional<T>,​T> modifyFunction)
      Perform an atomic read-modify-update of the value.
      void refresh​(java.lang.String path)
      Invalidate and reload an object in the metadata cache.
    • Method Detail

      • get

        java.util.concurrent.CompletableFuture<java.util.Optional<T>> get​(java.lang.String path)
        Tries to fetch one item from the cache or fallback to the store if not present.

        If the key is not found, the Optional will be empty.

        Parameters:
        path - the path of the object in the metadata store
        Returns:
        a future to track the completion of the operation
      • getWithStats

        java.util.concurrent.CompletableFuture<java.util.Optional<CacheGetResult<T>>> getWithStats​(java.lang.String path)
        Tries to fetch one item from the cache or fallback to the store if not present.

        If the key is not found, the Optional will be empty.

        Parameters:
        path - the path of the object in the metadata store
        Returns:
        a future to track the completion of the operation
      • getIfCached

        java.util.Optional<T> getIfCached​(java.lang.String path)
        Check if an object is present in cache without triggering a load from the metadata store.
        Parameters:
        path - the path of the object in the metadata store
        Returns:
        the cached object or an empty Optional is the cache doesn't have the object
      • getChildren

        java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> getChildren​(java.lang.String path)
        Return all the nodes (lexicographically sorted) that are children to the specific path. If the path itself does not exist, it will return an empty list.
        Parameters:
        path - the path of the key to get from the store
        Returns:
        a future to track the async request
      • exists

        java.util.concurrent.CompletableFuture<java.lang.Boolean> exists​(java.lang.String path)
        Read whether a specific path exists. Note: In case of keys with multiple levels (eg: '/a/b/c'), checking the existence of a parent (eg. '/a') might not necessarily return true, unless the key had been explicitly created.
        Parameters:
        path - the path of the key to check on the store
        Returns:
        a future to track the async request
      • readModifyUpdateOrCreate

        java.util.concurrent.CompletableFuture<T> readModifyUpdateOrCreate​(java.lang.String path,
                                                                           java.util.function.Function<java.util.Optional<T>,​T> modifyFunction)
        Perform an atomic read-modify-update of the value.

        The modify function can potentially be called multiple times if there are concurrent updates happening.

        If the object does not exist yet, the modifyFunction will get passed an Optional.empty() object.

        Parameters:
        path - the path of the object in the metadata store
        modifyFunction - a function that will be passed the current value and returns a modified value to be stored
        Returns:
        a future to track the completion of the operation
      • readModifyUpdate

        java.util.concurrent.CompletableFuture<T> readModifyUpdate​(java.lang.String path,
                                                                   java.util.function.Function<T,​T> modifyFunction)
        Perform an atomic read-modify-update of the value.

        The modify function can potentially be called multiple times if there are concurrent updates happening.

        Parameters:
        path - the path of the object in the metadata store
        modifyFunction - a function that will be passed the current value and returns a modified value to be stored
        Returns:
        a future to track the completion of the operation
      • create

        java.util.concurrent.CompletableFuture<java.lang.Void> create​(java.lang.String path,
                                                                      T value)
        Create a new object in the metadata store.

        This operation will make sure to keep the cache consistent.

        Parameters:
        path - the path of the object in the metadata store
        value - the object to insert in metadata store
        Returns:
        a future to track the completion of the operation
        Throws:
        MetadataStoreException.AlreadyExistsException - If the object is already present.
      • delete

        java.util.concurrent.CompletableFuture<java.lang.Void> delete​(java.lang.String path)
        Delete an object from the metadata store.

        This operation will make sure to keep the cache consistent.

        Parameters:
        path - the path of the object in the metadata store
        Returns:
        a future to track the completion of the operation
        Throws:
        MetadataStoreException.NotFoundException - if the object is not present in the metadata store.
      • invalidate

        void invalidate​(java.lang.String path)
        Force the invalidation of an object in the metadata cache.
        Parameters:
        path - the path of the object in the metadata store
      • refresh

        void refresh​(java.lang.String path)
        Invalidate and reload an object in the metadata cache.
        Parameters:
        path - the path of the object in the metadata store