Class ZooPropStore

    • Method Detail

      • exists

        public boolean exists​(PropStoreKey<?> propStoreKey)
        Description copied from interface: PropStore
        Test that a node for properties exists without throwing a KeeperException.
        Specified by:
        exists in interface PropStore
        Parameters:
        propStoreKey - the prop cache key
        Returns:
        true if the property node exists, false otherwise.
      • create

        public void create​(PropStoreKey<?> propStoreKey,
                           Map<String,​String> props)
        Description copied from interface: PropStore
        Create an initial entry for the PropCacheId. If properties already exist, they are not modified.
        Specified by:
        create in interface PropStore
        Parameters:
        propStoreKey - the prop cache key
        props - a map of property k,v pairs
      • get

        public @NonNull VersionedProperties get​(PropStoreKey<?> propStoreKey)
        get or create properties from the store. If the property node does not exist in ZooKeeper, legacy properties exist, they will be converted to the new storage form and naming convention. The legacy properties are deleted once the new node format is written.
        Specified by:
        get in interface PropStore
        Parameters:
        propStoreKey - the prop cache key
        Returns:
        The versioned properties.
        Throws:
        IllegalStateException - if the updates fails because of an underlying store exception
      • readFromZk

        public static @Nullable VersionedProperties readFromZk​(PropStoreKey<?> propStoreKey,
                                                               PropStoreWatcher watcher,
                                                               ZooReader zooReader)
                                                        throws IOException,
                                                               org.apache.zookeeper.KeeperException,
                                                               InterruptedException
        Convenience method for utilities that may not have a PropStore read the encoded properties directly from ZooKeeper. This allows utilities access when there is a ZooKeeper, may there may not be a full instance running. All exception handling is left to the caller.
        Parameters:
        propStoreKey - the prop cache key
        watcher - a prop store watcher that will receive / handle ZooKeeper events.
        zooReader - a ZooReader with an authenticated session.
        Returns:
        the versioned properties or null if the node does not exist.
        Throws:
        IOException - if the underlying data from the ZooKeeper node cannot be decoded.
        org.apache.zookeeper.KeeperException - if a ZooKeeper exception occurs
        InterruptedException - if the ZooKeeper read was interrupted.
      • putAll

        public void putAll​(@NonNull PropStoreKey<?> propStoreKey,
                           @NonNull Map<String,​String> props)
        Copies all mappings from the specified map and into the existing property values and stores them into the backend store. New keys are added and keys the may have existed in the current properties are overwritten.

        If multiple threads attempt to update values concurrently, this method will automatically retry. If the threads are setting different keys / values the result will be the sum of the changes. If the concurrent threads are attempting to set a value(s) for the same key(s), the value(s) will be the set to the values provided by the last thread to complete. The order is indeterminate.

        Specified by:
        putAll in interface PropStore
        Parameters:
        propStoreKey - the prop cache id
        props - a map of property k,v pairs
        Throws:
        IllegalStateException - if the values cannot be written or if an underlying store exception occurs.
      • replaceAll

        public void replaceAll​(@NonNull PropStoreKey<?> propStoreKey,
                               long version,
                               @NonNull Map<String,​String> props)
        Description copied from interface: PropStore
        Replaces all current properties with map provided. If a property is not included in the new map, the property will not be set.
        Specified by:
        replaceAll in interface PropStore
        Parameters:
        propStoreKey - the prop cache key
        version - the version of the properties
        props - a map of property k,v pairs
      • removeProperties

        public void removeProperties​(@NonNull PropStoreKey<?> propStoreKey,
                                     @NonNull Collection<String> keys)
        Description copied from interface: PropStore
        Deletes individual properties specified by the set of keys.
        Specified by:
        removeProperties in interface PropStore
        Parameters:
        propStoreKey - the prop cache key
        keys - a set of keys.
      • delete

        public void delete​(@NonNull PropStoreKey<?> propStoreKey)
        Description copied from interface: PropStore
        Delete the store node from the underlying store.
        Specified by:
        delete in interface PropStore
        Parameters:
        propStoreKey - the prop cache key
      • registerAsListener

        public void registerAsListener​(PropStoreKey<?> propStoreKey,
                                       PropChangeListener listener)
        Description copied from interface: PropStore
        External processes can register for notifications if the properties change. Normally processes can read from the store and always receive the current snapshot of the latest values. However, it the process wants to take an active action on change detections, then they can register and receive notifications.

        Implementation detail - the notification occurs on a separate thread from the underlying store, but listeners should not perform lengthy operations on the notification to prevent delaying other listeners from receive timely notification of the changes detected.

        Specified by:
        registerAsListener in interface PropStore
        Parameters:
        propStoreKey - the prop cache key
        listener - a listener
      • cacheChangeEvent

        public void cacheChangeEvent​(PropStoreKey<?> propStoreKey)
        NOOP for the prop store - the cache value will reflect the updated value on next read. The change is also sent to external listeners of the need to take action, but for the prop store, no additional action is required.
        Specified by:
        cacheChangeEvent in interface PropChangeListener
        Parameters:
        propStoreKey - the prop cache id.
      • validateDataVersion

        public boolean validateDataVersion​(PropStoreKey<?> storeKey,
                                           long expectedVersion)
        Description copied from interface: PropStore
        Compare the stored data version with the expected version. Notifies subscribers of the change detection.
        Specified by:
        validateDataVersion in interface PropStore
        Parameters:
        storeKey - specifies key for backend store
        expectedVersion - the expected data version
        Returns:
        true if the stored version matches the provided expected version.