Class ChangeStream<EventT extends BaseChangeEvent>
- java.lang.Object
-
- com.mongodb.stitch.core.services.mongodb.remote.ChangeStream<EventT>
-
- Type Parameters:
EventT
- The type of underlying event for this ChangeStream.
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class ChangeStream<EventT extends BaseChangeEvent> extends Object implements Closeable
User-level abstraction for a stream returningChangeEvent
s from the server.
-
-
Constructor Summary
Constructors Constructor Description ChangeStream(Stream<EventT> stream)
Constructs a ChangeStream from the underlying Stream.
-
Method Summary
Modifier and Type Method Description void
addChangeEventListener(BaseChangeEventListener listener)
Adds a ChangeEventListener to the ChangeStream that will run on every event on the stream.void
close()
Closes the underlying stream and removes all ChangeEventListeners.protected void
dispatchError(StitchEvent<EventT> event)
protected Enumeration<BaseChangeEventListener>
getChangeEventListeners()
protected ExceptionListener
getExceptionListener()
protected Stream<EventT>
getInternalStream()
boolean
isListenerThreadRunning()
Indicates whether or not any ChangeStreamListeners are currently running.boolean
isOpen()
Indicates whether or not the change stream is currently open.EventT
nextEvent()
Returns the next event available from the stream.protected void
removeAllChangeEventListeners()
void
removeChangeEventListener(BaseChangeEventListener listener)
Remove a ChangeEventListener from the ChangeStream.void
setExceptionListener(ExceptionListener exceptionListener)
Optionally adds a listener that is notified when an attempt to retrieve the next event fails.
-
-
-
Method Detail
-
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 exception listener.
-
nextEvent
public EventT nextEvent() throws IOException, IllegalStateException
Returns the next event available from the stream.- Returns:
- The next event.
- Throws:
IOException
- If the underlying stream throws anIOException
IllegalStateException
- if called while a ChangeEventListener is attached
-
addChangeEventListener
public void addChangeEventListener(BaseChangeEventListener 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.- Parameters:
listener
- the ChangeEventListener
-
removeChangeEventListener
public void removeChangeEventListener(BaseChangeEventListener listener)
Remove a ChangeEventListener from the ChangeStream.- Parameters:
listener
- the ChangeEventListener
-
isOpen
public boolean isOpen()
Indicates whether or not the change stream is currently open.- Returns:
- True if the underlying change stream is open.
-
isListenerThreadRunning
public boolean isListenerThreadRunning()
Indicates whether or not any ChangeStreamListeners are currently running.- Returns:
- True if the ChangeStreamListeners are running
-
close
public void close() throws IOException
Closes the underlying stream and removes all ChangeEventListeners.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If the underlying stream throws anIOException
when it is closed.
-
removeAllChangeEventListeners
protected void removeAllChangeEventListeners()
-
getChangeEventListeners
protected Enumeration<BaseChangeEventListener> getChangeEventListeners()
-
getExceptionListener
protected ExceptionListener getExceptionListener()
-
dispatchError
protected void dispatchError(StitchEvent<EventT> event)
-
-