Class ObservableCache<T>

    • Field Detail

      • once

        final java.util.concurrent.atomic.AtomicBoolean once
        The subscription to the source should happen at most once.
      • capacityHint

        final int capacityHint
        The number of items per cached nodes.
      • observers

        final java.util.concurrent.atomic.AtomicReference<ObservableCache.CacheDisposable<T>[]> observers
        The current known array of observer state to notify.
      • EMPTY

        static final ObservableCache.CacheDisposable[] EMPTY
        A shared instance of an empty array of observers to avoid creating a new empty array when all observers dispose.
      • TERMINATED

        static final ObservableCache.CacheDisposable[] TERMINATED
        A shared instance indicating the source has no more events and there is no need to remember observers anymore.
      • size

        volatile long size
        The total number of elements in the list available for reads.
      • tailOffset

        int tailOffset
        How many items have been put into the tail node so far.
      • error

        java.lang.Throwable error
        If observers is TERMINATED, this holds the terminal error if not null.
      • done

        volatile boolean done
        True if the source has terminated.
    • Constructor Detail

      • ObservableCache

        public ObservableCache​(Observable<T> source,
                               int capacityHint)
        Constructs an empty, non-connected cache.
        Parameters:
        source - the source to subscribe to for the first incoming observer
        capacityHint - the number of items expected (reduce allocation frequency)
    • Method Detail

      • subscribeActual

        protected void subscribeActual​(Observer<? super T> t)
        Description copied from class: Observable
        Operator implementations (both source and intermediate) should implement this method that performs the necessary business logic and handles the incoming Observers.

        There is no need to call any of the plugin hooks on the current Observable instance or the Observer; all hooks and basic safeguards have been applied by Observable.subscribe(Observer) before this method gets called.

        Specified by:
        subscribeActual in class Observable<T>
        Parameters:
        t - the incoming Observer, never null
      • isConnected

        boolean isConnected()
        Check if this cached observable is connected to its source.
        Returns:
        true if already connected
      • hasObservers

        boolean hasObservers()
        Returns true if there are observers subscribed to this observable.
        Returns:
        true if the cache has observers
      • cachedEventCount

        long cachedEventCount()
        Returns the number of events currently cached.
        Returns:
        the number of currently cached event count
      • add

        void add​(ObservableCache.CacheDisposable<T> consumer)
        Atomically adds the consumer to the observers copy-on-write array if the source has not yet terminated.
        Parameters:
        consumer - the consumer to add
      • replay

        void replay​(ObservableCache.CacheDisposable<T> consumer)
        Replays the contents of this cache to the given consumer based on its current state and number of items requested by it.
        Parameters:
        consumer - the consumer to continue replaying items to