Class SimplePushEventSourceImpl<T,​U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>>

    • Field Detail

      • lock

        private final java.lang.Object lock
      • queuePolicy

        private final QueuePolicy<T,​U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> queuePolicy
      • queue

        private final U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>> queue
      • parallelism

        private final int parallelism
      • semaphore

        private final java.util.concurrent.Semaphore semaphore
      • onClose

        private final java.lang.Runnable onClose
      • closed

        private boolean closed
      • connectPromise

        private Deferred<java.lang.Void> connectPromise
      • waitForFinishes

        private boolean waitForFinishes
    • Constructor Detail

      • SimplePushEventSourceImpl

        public SimplePushEventSourceImpl​(PromiseFactory promiseFactory,
                                         QueuePolicy<T,​U> queuePolicy,
                                         U queue,
                                         int parallelism,
                                         java.lang.Runnable onClose)
    • Method Detail

      • open

        public java.lang.AutoCloseable open​(PushEventConsumer<? super T> pec)
                                     throws java.lang.Exception
        Description copied from interface: PushEventSource
        Open the asynchronous channel between the source and the consumer. The call returns an AutoCloseable. This can be closed, and should close the channel, including sending a Close event if the channel was not already closed. The returned object must be able to be closed multiple times without sending more than one Close events.
        Specified by:
        open in interface PushEventSource<T>
        Parameters:
        pec - the consumer (not null)
        Returns:
        a AutoCloseable that can be used to close the stream
        Throws:
        java.lang.Exception
      • close

        public void close()
        Description copied from interface: SimplePushEventSource
        Close this source. Calling this method indicates that there will never be any more events published by it. Calling this method sends a close event to all connected consumers. After calling this method any PushEventConsumer that tries to PushEventSource.open(PushEventConsumer) this source will immediately receive a close event, and will not see any remaining buffered events.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface SimplePushEventSource<T>
      • close

        private void close​(PushEvent<T> event)
      • publish

        public void publish​(T t)
        Description copied from interface: SimplePushEventSource
        Asynchronously publish an event to this stream and all connected PushEventConsumer instances. When this method returns there is no guarantee that all consumers have been notified. Events published by a single thread will maintain their relative ordering, however they may be interleaved with events from other threads.
        Specified by:
        publish in interface SimplePushEventSource<T>
      • enqueueEvent

        private void enqueueEvent​(PushEvent<T> event)
      • startWorker

        private void startWorker()
      • handleReset

        private void handleReset​(boolean resetWait)
      • connectPromise

        public Promise<java.lang.Void> connectPromise()
        Description copied from interface: SimplePushEventSource
        This method can be used to delay event generation until an event source has connected. The returned promise will resolve as soon as one or more PushEventConsumer instances have opened the SimplePushEventSource.

        The returned promise may already be resolved if this SimplePushEventSource already has connected consumers. If the SimplePushEventSource is closed before the returned Promise resolves then it will be failed with an IllegalStateException.

        Note that the connected consumers are able to asynchronously close their connections to this SimplePushEventSource, and therefore it is possible that once the promise resolves this SimplePushEventSource may no longer be connected to any consumers.

        Specified by:
        connectPromise in interface SimplePushEventSource<T>
        Returns:
        A promise representing the connection state of this EventSource
      • closedConnectPromise

        private Promise<java.lang.Void> closedConnectPromise()