public class Changes
extends java.lang.Object
Contains the Change Notifications API, supports normal and continuous feed Changes.
Usage example for normal feed limiting to 10 results, with a filter:
// feed type normal
String since = db.info().getUpdateSeq(); // latest update seq
ChangesResult changeResult = db.changes()
.since(since)
.limit(10)
.filter("example/filter")
.getChanges();
//process the ChangesResult
for (ChangesResult.Row row : changeResult.getResults()) {
String docId = row.getId()
JsonObject doc = row.getDoc();
}
Usage example for continuous feed, including document content:
// feed type continuous
Changes changes = db.changes()
.includeDocs(true)
.heartBeat(30000)
.continuousChanges();
while (changes.hasNext()) {
ChangesResult.Row feed = changes.next();
String docId = feed.getId();
JsonObject doc = feed.getDoc();
}
//while loop blocks; stop from another thread
changes.stop(); // stop continuous feed
ChangesResult
,
Databases - get changesModifier and Type | Method and Description |
---|---|
Changes |
continuousChanges()
Requests Change notifications of feed type continuous.
|
Changes |
descending(boolean descending) |
Changes |
filter(java.lang.String filter)
Specify a filter function to apply to the changes feed.
|
ChangesResult |
getChanges()
Requests Change notifications of feed type normal.
|
boolean |
hasNext()
Checks whether a feed is available in the continuous stream, blocking
until a feed is received.
|
Changes |
heartBeat(long heartBeat)
Enable an empty line heartbeat for longpoll or continuous feeds for when there have been no
changes.
|
Changes |
includeDocs(boolean includeDocs) |
Changes |
limit(int limit)
Limit the number of rows to return.
|
ChangesResult.Row |
next() |
Changes |
parameter(java.lang.String name,
java.lang.String value)
Add a custom query parameter to the _changes request.
|
Changes |
since(java.lang.String since)
Return only changes after the specified sequence identifier.
|
void |
stop()
Stops a running continuous feed.
|
Changes |
style(java.lang.String style)
Configures how many changes are returned "main_only" for the winning revision only or
"all_docs" to also include leaf revisions.
|
Changes |
timeout(long timeout)
Configure a timeout for the changes feed.
|
public Changes continuousChanges()
Feed notifications are accessed in an iterator style.
This method will connect to the changes feed; any configuration options applied after calling it will be ignored.
Note that in some versions of Apache CouchDB and Cloudant the HTTP response headers will be delayed until the first change or heartbeat is sent (see https://github.com/apache/couchdb/issues/985). As such this method may block for up to the heartbeat duration if there are no changes to be received from the database immediately.
public boolean hasNext()
public ChangesResult.Row next()
public void stop()
public ChangesResult getChanges()
ChangesResult
encapsulating the normal feed changespublic Changes since(java.lang.String since)
since
- sequence identifier or "now"
public Changes limit(int limit)
limit
- the number of rowspublic Changes heartBeat(long heartBeat)
heartBeat
- time in milliseconds after which an empty line is sentpublic Changes timeout(long timeout)
timeout
- time in milliseconds to wait for datapublic Changes filter(java.lang.String filter)
filter
- name of the design document filter function e.g "designDoc/filterFunction"
public Changes includeDocs(boolean includeDocs)
includeDocs
- whether to include document content in the returned rowspublic Changes style(java.lang.String style)
style
- "main_only"
or "all_docs"
public Changes descending(boolean descending)
descending
- true
to return changes in descending orderpublic Changes parameter(java.lang.String name, java.lang.String value)
name
- the name of the query parametervalue
- the value of the query parameter