List of usage examples for com.mongodb Bytes QUERYOPTION_TAILABLE
int QUERYOPTION_TAILABLE
To view the source code for com.mongodb Bytes QUERYOPTION_TAILABLE.
Click Source Link
From source file:HAL.libraries.blackboard_client.OplogMonitorThread.java
License:Open Source License
/** * Constructs a tailed cursor for the specified query on the oplog collection. * This constructor should be used when user authentication is required. * /*from w ww . j av a 2 s. c om*/ * @param mongo The Mongo database connection that should be used. * @param oplogDBName The database in which the oplog collection resides. * @param oplogCollectionName The name of the oplog collection. * @param username Username that will be used to authenticate with the oplog database. This user should have read access. * @param password The password belonging to the specified user. * @param query The query that will be used in the tailed cursor. **/ public OplogMonitorThread(Mongo mongo, String oplogDBName, String oplogCollectionName, String username, String password, DBObject query) { database = mongo.getDB(oplogDBName); database.authenticate(username, password.toCharArray()); DBCollection collection = database.getCollection(oplogCollectionName); tailedCursor = collection.find(query); tailedCursor.addOption(Bytes.QUERYOPTION_TAILABLE); tailedCursor.addOption(Bytes.QUERYOPTION_AWAITDATA); tailedCursor.skip(tailedCursor.size()); callbackThread = new OplogCallbackThread(); }
From source file:org.apache.camel.component.mongodb.MongoDbTailingProcess.java
License:Apache License
private DBCursor initializeCursor() { Object lastVal = tailTracking.lastVal; // lastVal can be null if we are initializing and there is no persistence enabled DBCursor answer;//from w w w .j a va 2 s .co m if (lastVal == null) { answer = dbCol.find().addOption(Bytes.QUERYOPTION_TAILABLE).addOption(Bytes.QUERYOPTION_AWAITDATA); } else { DBObject queryObj = new BasicDBObject(tailTracking.getIncreasingFieldName(), new BasicDBObject("$gt", lastVal)); answer = dbCol.find(queryObj).addOption(Bytes.QUERYOPTION_TAILABLE) .addOption(Bytes.QUERYOPTION_AWAITDATA); } return answer; }
From source file:org.mongodb.demos.tailable.RealTimeAppServer.java
License:Apache License
public static void main(String[] args) throws Exception { RealTimeAppServer realTimeAppServer = new RealTimeAppServer(); DBCollection coll = realTimeAppServer.createAndGetCappedCollection("messages"); DBCursor cur = coll.find().sort(BasicDBObjectBuilder.start("$natural", 1).get()) .addOption(Bytes.QUERYOPTION_TAILABLE).addOption(Bytes.QUERYOPTION_AWAITDATA); System.out.println("== open cursor =="); Runnable task = () -> {/*from w w w . j a v a2 s . co m*/ System.out.println("\tWaiting for events"); while (cur.hasNext()) { DBObject obj = cur.next(); System.out.println(obj); } }; new Thread(task).start(); }
From source file:thingynet.event.EventListener.java
License:Apache License
private void refreshCursor() { if (cursor != null) { cursor.close();/*from w w w.j ava 2s .c om*/ if (cursorPollMillis > 0) { try { Thread.sleep(cursorPollMillis); } catch (InterruptedException e) { log.error("Thread was interrupted", e); } } } if (handler.getLast() == null) { cursor = collection.getDBCollection().find().addOption(Bytes.QUERYOPTION_TAILABLE) .addOption(Bytes.QUERYOPTION_AWAITDATA); } else { DBObject queryObj = new BasicDBObject("_id", new BasicDBObject("$gt", handler.getLast())); cursor = collection.getDBCollection().find(queryObj).addOption(Bytes.QUERYOPTION_TAILABLE) .addOption(Bytes.QUERYOPTION_AWAITDATA); } }