Class VirtualPublisher<T>

  • All Implemented Interfaces:, org.reactivestreams.Publisher<T>

    public class VirtualPublisher<T>
    extends java.util.concurrent.atomic.AtomicReference<java.lang.Object>
    implements org.reactivestreams.Publisher<T>

    The implementation of Sink.asPublisher needs to offer a Publisher that defers to the upstream that is connected during materialization. This would be trivial if it were not for materialized value computations that may even spawn the code that does pub.subscribe(sub) in a Future, running concurrently with the actual materialization. Therefore we implement a minimal shell here that plugs the downstream and the upstream together as soon as both are known. Using a VirtualProcessor would technically also work, but it would defeat the purpose of subscription timeouts—the subscription would always already be established from the Actor&rsquo;s perspective, regardless of whether a downstream will ever be connected.

    One important consideration is that this Publisher must not retain a reference to the Subscriber after having hooked it up with the real Publisher, hence the use of Inert.subscriber as a tombstone.

    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void onSubscriptionTimeout​(Materializer am, StreamSubscriptionTimeoutTerminationMode mode)  
      void registerPublisher​(org.reactivestreams.Publisher<?> pub)  
      void subscribe​(org.reactivestreams.Subscriber<? super T> subscriber)  
      java.lang.String toString()  
      • Methods inherited from class java.util.concurrent.atomic.AtomicReference

        accumulateAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, get, getAcquire, getAndAccumulate, getAndSet, getAndUpdate, getOpaque, getPlain, lazySet, set, setOpaque, setPlain, setRelease, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • VirtualPublisher

        public VirtualPublisher()
    • Method Detail

      • registerPublisher

        public final void registerPublisher​(org.reactivestreams.Publisher<?> pub)
      • subscribe

        public void subscribe​(org.reactivestreams.Subscriber<? super T> subscriber)
        Specified by:
        subscribe in interface org.reactivestreams.Publisher<T>
      • toString

        public java.lang.String toString()
        toString in class java.util.concurrent.atomic.AtomicReference<java.lang.Object>