Class MetadataCacheImpl<T>

java.lang.Object
org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl<T>
All Implemented Interfaces:
Consumer<Notification>, MetadataCache<T>

public class MetadataCacheImpl<T> extends Object implements MetadataCache<T>, Consumer<Notification>
  • Constructor Details

  • Method Details

    • get

      public CompletableFuture<Optional<T>> get(String path)
      Description copied from interface: MetadataCache
      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.

      Specified by:
      get in interface MetadataCache<T>
      Parameters:
      path - the path of the object in the metadata store
      Returns:
      a future to track the completion of the operation
    • getWithStats

      public CompletableFuture<Optional<CacheGetResult<T>>> getWithStats(String path)
      Description copied from interface: MetadataCache
      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.

      Specified by:
      getWithStats in interface MetadataCache<T>
      Parameters:
      path - the path of the object in the metadata store
      Returns:
      a future to track the completion of the operation
    • getIfCached

      public Optional<T> getIfCached(String path)
      Description copied from interface: MetadataCache
      Check if an object is present in cache without triggering a load from the metadata store.
      Specified by:
      getIfCached in interface MetadataCache<T>
      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
    • readModifyUpdateOrCreate

      public CompletableFuture<T> readModifyUpdateOrCreate(String path, Function<Optional<T>,T> modifyFunction)
      Description copied from interface: MetadataCache
      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.

      Specified by:
      readModifyUpdateOrCreate in interface MetadataCache<T>
      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

      public CompletableFuture<T> readModifyUpdate(String path, Function<T,T> modifyFunction)
      Description copied from interface: MetadataCache
      Perform an atomic read-modify-update of the value.

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

      Specified by:
      readModifyUpdate in interface MetadataCache<T>
      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

      public CompletableFuture<Void> create(String path, T value)
      Description copied from interface: MetadataCache
      Create a new object in the metadata store.

      This operation will make sure to keep the cache consistent.

      Specified by:
      create in interface MetadataCache<T>
      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
    • delete

      public CompletableFuture<Void> delete(String path)
      Description copied from interface: MetadataCache
      Delete an object from the metadata store.

      This operation will make sure to keep the cache consistent.

      Specified by:
      delete in interface MetadataCache<T>
      Parameters:
      path - the path of the object in the metadata store
      Returns:
      a future to track the completion of the operation
    • exists

      public CompletableFuture<Boolean> exists(String path)
      Description copied from interface: MetadataCache
      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.
      Specified by:
      exists in interface MetadataCache<T>
      Parameters:
      path - the path of the key to check on the store
      Returns:
      a future to track the async request
    • getChildren

      public CompletableFuture<List<String>> getChildren(String path)
      Description copied from interface: MetadataCache
      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.
      Specified by:
      getChildren in interface MetadataCache<T>
      Parameters:
      path - the path of the key to get from the store
      Returns:
      a future to track the async request
    • invalidate

      public void invalidate(String path)
      Description copied from interface: MetadataCache
      Force the invalidation of an object in the metadata cache.
      Specified by:
      invalidate in interface MetadataCache<T>
      Parameters:
      path - the path of the object in the metadata store
    • refresh

      public void refresh(String path)
      Description copied from interface: MetadataCache
      Invalidate and reload an object in the metadata cache.
      Specified by:
      refresh in interface MetadataCache<T>
      Parameters:
      path - the path of the object in the metadata store
    • invalidateAll

      public void invalidateAll()
    • accept

      public void accept(Notification t)
      Specified by:
      accept in interface Consumer<T>