Class PropStoreWatcher

  • All Implemented Interfaces:
    org.apache.zookeeper.Watcher

    public class PropStoreWatcher
    extends Object
    implements org.apache.zookeeper.Watcher
    This class serves as a translator between ZooKeeper events and converts them to PropStore events. Using this as an intermediary, the external listeners do not need to set / manage external ZooKeeper watchers, they can register for PropStore events if they need to take active action on change detection.

    Users of the PropStore.get() will get properties that match what is stored in ZooKeeper for each call and do not need to manage any caching. However, the ability to receive active notification without needed to register / manage ZooKeeper watchers external to the PropStore is provided in case other code is relying on active notifications.

    The notification occurs on a separate thread from the ZooKeeper notification handling, but listeners should not perform lengthy operations on the notification thread so that other listener notifications are not delayed.

    • Constructor Detail

      • PropStoreWatcher

        public PropStoreWatcher​(ReadyMonitor zkReadyMonitor)
    • Method Detail

      • process

        public void process​(org.apache.zookeeper.WatchedEvent event)
        Process a ZooKeeper event. This method does not reset the watcher. Subscribers are notified of the change - if they call get to update and respond to the change the watcher will be (re)set then. This helps clean up watchers by not automatically re-adding the watcher on the event but only if being used.
        Specified by:
        process in interface org.apache.zookeeper.Watcher
        Parameters:
        event - ZooKeeper event.
      • signalZkChangeEvent

        public void signalZkChangeEvent​(@NonNull PropStoreKey<?> propStoreKey)
        Execute a task to notify registered listeners that the propStoreKey node received an event notification from ZooKeeper and should be updated. The process can be initiated either by a ZooKeeper notification or a change detected in the cache based on a ZooKeeper event.
        Parameters:
        propStoreKey - the cache id
      • signalCacheChangeEvent

        public void signalCacheChangeEvent​(PropStoreKey<?> propStoreKey)
        Execute a task to notify registered listeners that the propStoreKey node change was detected should be updated.
        Parameters:
        propStoreKey - the cache id
      • listenerCleanup

        public void listenerCleanup​(PropStoreKey<?> propStoreKey)
        Clean-up the active listeners set when an entry is removed from the cache, remove it from the active listeners.
        Parameters:
        propStoreKey - the cache id