Class FilteringObserver

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Observer

    public class FilteringObserver
    extends Object
    implements Observer, Closeable
    An observer that implements filtering of content changes while at the same time supporting (wrapping) a BackgroundObserver underneath.

    The FilteringObserver uses an explicit Filter to decide whether or not to forward a content change to the BackgroundObserver. If the Filter decides to include the change things happen as usual. If the Filter decides to exclude the change, this FilteringObserver does not forward the change, but remembers the fact that the last change was filtered. The first included change after excluded ones will cause a NOOP_CHANGE commitInfo to be passed along to the BackgroundObserver. That NOOP_CHANGE is then used by the FilteringDispatcher: if a CommitInfo is a NOOP_CHANGE then the FilteringDispatcher will not forward anything to the FilteringAwareObserver and only adjust the 'before' state accordingly (which it does also for a NOOP_CHANGE, to exactly achieve the skipping effect).

    • Constructor Detail

      • FilteringObserver

        public FilteringObserver​(@NotNull
                                 @NotNull Executor executor,
                                 int queueLength,
                                 @NotNull Filter filter,
                                 @NotNull FilteringAwareObserver observer)
        Default constructor which creates a BackgroundObserver automatically, including creating a FilteringDispatcher.
        executor - the executor that should be used for the BackgroundObserver
        queueLength - the queue length of the BackgroundObserver
        filter - the Filter to be used for filtering
        observer - the FilteringAwareObserver to which content changes ultimately are delivered after going through a chain of FilteringObserver->BackgroundObserver->FilteringDispatcher.
      • FilteringObserver

        public FilteringObserver​(@NotNull
                                 @NotNull BackgroundObserver backgroundObserver,
                                 @NotNull Filter filter)
        Alternative constructor where the BackgroundObserver is created elsewhere
        backgroundObserver - the BackgroundObserver to be used by this FilteringObserver
        filter - the Filter to be used for filtering
    • Method Detail

      • contentChanged

        public final void contentChanged​(@NotNull
                                         @NotNull NodeState root,
                                         @NotNull CommitInfo info)
        Description copied from interface: Observer
        Observes a content change. See the Observer class javadocs and relevant repository and observer registration details for more information on when and how this method gets called.
        Specified by:
        contentChanged in interface Observer
        root - root state of the repository
        info - commit information