new ChangeStreamListenerThread(dbName, collName, filterPipeline, changeStreamOptions, changeHandler, changeHandlerOptions, targetHost, readPreferenceMode)
Creates a ChangeStreamListenerThread.
Parameters:
Name | Type | Description |
---|---|---|
dbName |
String | The database name. |
collName |
String | The collection name. |
filterPipeline |
Array | The aggregation pipeline that should follow the '$changeStream' aggregation stage. |
changeStreamOptions |
Object | The options that should be passed to the '$changeStream' aggregation stage. Defaults to no options. |
changeHandler |
function | A callback function that takes a change document, a state object and an options object as parameters. The function will be called for each change document read. Defaults to a noop function. |
changeHandlerOptions |
Object | An object that will be passed as argument to the changeHandler callback function. Defaults to an empty object. |
targetHost |
String | The host to connect to in order to listen for the change stream. Defaults to the the default server (using the global db). |
readPreferenceMode |
String | The read preference of the change stream aggregation pipeline. |
- Source:
Methods
hasStarted()
Returns true if the listener thread has been created and started.
- Source:
join()
Joins the thread.
- Source:
start()
Spawns a ScopedThread that will run _readChangeStream().
- Source:
stop()
Stops the thread.
- Source:
(inner) _readChangeStream()
Create a change stream cursor and continually read from it. This function is executed in a ScopedThread.
The 'continueCounter' parameter is a CountDownLatch used by the main thread to signal this function, which is executed in a ScopedThread, if it can continue or should stop. Its count must be set to 1 to indicate that the function can continue, and to 0 to indicate that it should stop. The 'notReadyCounter' parameter is a CountDownLatch used by this function to signal the main thread that it is ready and reading change streams. It must be passed to this function with a count of 1, and the function will set it to 0 when ready.
- Source: