Class OwnershipCache


  • public class OwnershipCache
    extends java.lang.Object
    This class provides a cache service for all the service unit ownership among the brokers. It provide a cache service as well as MetadataStore read/write functions for a) lookup of a service unit ownership to a broker; b) take ownership of a service unit by the local broker
    • Method Detail

      • checkOwnershipAsync

        public java.util.concurrent.CompletableFuture<java.lang.Boolean> checkOwnershipAsync​(NamespaceBundle bundle)
        Check whether this broker owns given namespace bundle.
        Parameters:
        bundle - namespace bundle
        Returns:
        future that will complete with check result
      • getOwnerAsync

        public java.util.concurrent.CompletableFuture<java.util.Optional<NamespaceEphemeralData>> getOwnerAsync​(NamespaceBundle suName)
        Method to get the current owner of the ServiceUnit.
        Parameters:
        suName - name of the ServiceUnit
        Returns:
        The ephemeral node data showing the current ownership info in ZooKeeper
        Throws:
        java.lang.Exception - throws exception if no ownership info is found
      • tryAcquiringOwnership

        public java.util.concurrent.CompletableFuture<NamespaceEphemeralData> tryAcquiringOwnership​(NamespaceBundle bundle)
                                                                                             throws java.lang.Exception
        Method to get the current owner of the ServiceUnit or set the local broker as the owner if absent.
        Parameters:
        bundle - the NamespaceBundle
        Returns:
        The ephemeral node data showing the current ownership info in ZooKeeper
        Throws:
        java.lang.Exception
      • removeOwnership

        public java.util.concurrent.CompletableFuture<java.lang.Void> removeOwnership​(NamespaceBundle bundle)
        Method to remove the ownership of local broker on the NamespaceBundle, if owned.
      • removeOwnership

        public java.util.concurrent.CompletableFuture<java.lang.Void> removeOwnership​(NamespaceBundles bundles)
        Method to remove ownership of all owned bundles.
        Parameters:
        bundles - NamespaceBundles to remove from ownership cache
      • getOwnedBundles

        public java.util.Map<NamespaceBundle,​OwnedBundle> getOwnedBundles()
        Method to access the map of all ServiceUnit objects owned by the local broker.
        Returns:
        a map of owned ServiceUnit objects
      • isNamespaceBundleOwned

        public boolean isNamespaceBundleOwned​(NamespaceBundle bundle)
        Checked whether a particular bundle is currently owned by this broker.
        Parameters:
        bundle -
        Returns:
      • getOwnedBundleAsync

        public java.util.Optional<java.util.concurrent.CompletableFuture<OwnedBundle>> getOwnedBundleAsync​(NamespaceBundle bundle)
      • disableOwnership

        public java.util.concurrent.CompletableFuture<java.lang.Void> disableOwnership​(NamespaceBundle bundle)
        Disable bundle in local cache and on zk.
        Parameters:
        bundle -
        Throws:
        java.lang.Exception
      • updateBundleState

        public java.util.concurrent.CompletableFuture<java.lang.Void> updateBundleState​(NamespaceBundle bundle,
                                                                                        boolean isActive)
        Update bundle state in a local cache.
        Parameters:
        bundle -
        Throws:
        java.lang.Exception
      • invalidateLocalOwnerCache

        public void invalidateLocalOwnerCache()
      • refreshSelfOwnerInfo

        public boolean refreshSelfOwnerInfo()