Class AsyncChangeStream<DocumentT,​ChangeEventT extends BaseChangeEvent<DocumentT>>

  • Type Parameters:
    DocumentT - The type of the full document on the underlying change event to be returned asynchronously.
    ChangeEventT - The type of MongoDB change event that this stream internally returns.

    public class AsyncChangeStream<DocumentT,​ChangeEventT extends BaseChangeEvent<DocumentT>>
    extends Object
    An implementation of ChangeStream that returns each event as a Task.
    • Constructor Detail

      • AsyncChangeStream

        public AsyncChangeStream​(ChangeStream<ChangeEventT> stream,
                                 TaskDispatcher dispatcher)
        Initializes a passthrough change stream with the provided underlying event stream.
        Parameters:
        stream - The event stream.
        dispatcher - The event dispatcher.
    • Method Detail

      • addChangeEventListener

        public void addChangeEventListener​(BaseChangeEventListener<DocumentT,​ChangeEventT> listener)
        Adds a ChangeEventListener to the ChangeStream that will run on every event on the stream. Multiple ChangeEventListeners can be added to any given stream and they will be removed when the stream is closed or when the listener is removed. Calls to nextEvent() will fail while there exists any ChangeEventListener's on this stream. Additionally, any events that occur after the ChangeEventListener is opened will not be caught by the listener.
        Parameters:
        listener - the BaseChangeEventListener
      • close

        public void close()
                   throws IOException
        Closes the underlying stream and removes all ChangeEventListeners.
        Throws:
        IOException - If the underlying stream throws an IOException when it is closed.
      • setExceptionListener

        public void setExceptionListener​(ExceptionListener exceptionListener)
        Optionally adds a listener that is notified when an attempt to retrieve the next event. fails.
        Parameters:
        exceptionListener - The ExceptionListener.
      • isOpen

        public boolean isOpen()
        Indicates whether or not the change stream is currently open.
        Returns:
        True if the underlying change stream is open.