List of usage examples for com.mongodb CursorType NonTailable
CursorType NonTailable
To view the source code for com.mongodb CursorType NonTailable.
Click Source Link
From source file:com.eightkdata.mongowp.client.wrapper.MongoConnectionWrapper.java
License:Open Source License
private CursorType toCursorType(QueryOptions queryOptions) { if (!queryOptions.isTailable()) { return CursorType.NonTailable; }//from ww w. ja v a 2 s .c om if (queryOptions.isAwaitData()) { return CursorType.TailableAwait; } return CursorType.Tailable; }
From source file:com.redhat.jielicious.storage.mongo.handler.MongoStorageHandler.java
License:Open Source License
private void getAll(String offset, String limit, SecurityContext context, String systemId, String agentId, String jvmId, final String namespace, final String sort, AsyncResponse asyncResponse, final String collectionSuffix) { try {// w w w . j a v a 2 s .c o m final int o = Integer.valueOf(offset); final int l = Integer.valueOf(limit); final String userName = context.getUserPrincipal().getName(); final Bson filter = MongoRequestFilters.buildGetFilter(systemId, agentId, jvmId, Collections.singletonList(userName)); TimedRequest<String> timedRequest = new TimedRequest<>(); String documents = timedRequest.run(new TimedRequest.TimedRunnable<String>() { @Override public String run() { FindIterable<Document> documents = ThermostatMongoStorage.getDatabase() .getCollection(namespace + collectionSuffix).find(filter) .projection(fields(include("obj"), excludeId())).sort(createSortObject(sort)).limit(l) .skip(o).batchSize(l).cursorType(CursorType.NonTailable); return MongoResponseBuilder.buildJsonDocuments(documents); } }); asyncResponse.resume(Response.status(Response.Status.OK) .entity(MongoResponseBuilder.buildJsonResponseWithTime(documents, timedRequest.getElapsed())) .build()); } catch (Exception e) { asyncResponse.resume(Response.status(Response.Status.BAD_REQUEST).build()); } }
From source file:com.redhat.jielicious.storage.mongo.handler.MongoStorageHandler.java
License:Open Source License
private void postAll(String body, String offset, String limit, SecurityContext context, String systemId, String agentId, String jvmId, final String namespace, final String sort, AsyncResponse asyncResponse, final String collectionSuffix) { try {//ww w .j a va2 s. c o m BasicDBList queries = (BasicDBList) JSON.parse(body); final int o = Integer.valueOf(offset); final int l = Integer.valueOf(limit); final String userName = context.getUserPrincipal().getName(); final Bson filter = MongoRequestFilters.buildPostFilter(queries, systemId, agentId, jvmId, Collections.singletonList(userName)); TimedRequest<String> timedRequest = new TimedRequest<>(); String documents = timedRequest.run(new TimedRequest.TimedRunnable<String>() { @Override public String run() { FindIterable<Document> documents = ThermostatMongoStorage.getDatabase() .getCollection(namespace + collectionSuffix).find(filter) .projection(fields(exclude("tags"), excludeId())).sort(createSortObject(sort)).limit(l) .skip(o).batchSize(l).cursorType(CursorType.NonTailable); return MongoResponseBuilder.buildJsonDocuments(documents); } }); asyncResponse.resume(Response.status(Response.Status.OK) .entity(MongoResponseBuilder.buildJsonResponseWithTime(documents, timedRequest.getElapsed())) .build()); } catch (Exception e) { e.printStackTrace(); asyncResponse.resume(Response.status(Response.Status.BAD_REQUEST).build()); } }
From source file:com.redhat.thermostat.gateway.common.mongodb.executor.MongoExecutor.java
License:Open Source License
public MongoDataResultContainer execGetRequest(MongoCollection<Document> collection, Integer limit, Integer offset, String sort, List<String> queries, String includes, String excludes, Set<String> realms) { FindIterable<Document> documents = collection.find(); MongoDataResultContainer queryDataContainer = new MongoDataResultContainer(); Bson query = MongoRequestFilters.buildQuery(queries, realms); documents = documents.filter(query); long count = collection.count(query); queryDataContainer.setGetReqCount(count); queryDataContainer.setRemainingNumQueryDocuments((int) (count - (limit + offset))); documents = buildProjection(documents, includes, excludes); final Bson sortObject = MongoSortFilters.createSortObject(sort); documents = documents.sort(sortObject).limit(limit).skip(offset).batchSize(limit) .cursorType(CursorType.NonTailable); queryDataContainer.setQueryDataResult(documents); return queryDataContainer; }
From source file:com.redhat.thermostat.gateway.common.mongodb.MongoStorageHandler.java
License:Open Source License
public String getMany(MongoCollection<Document> collection, Bson query, Integer limit, Integer offset, String sort, String includes, String excludes) { FindIterable<Document> documents = query == null ? collection.find() : collection.find(query); documents = buildProjection(documents, includes, excludes); final Bson sortObject = MongoSortFilters.createSortObject(sort); documents = documents.sort(sortObject).limit(limit).skip(offset).batchSize(limit) .cursorType(CursorType.NonTailable); return mongoResponseBuilder.addQueryDocuments(documents).build(); }
From source file:com.streamsets.pipeline.stage.origin.mongodb.AbstractMongoDBSource.java
License:Apache License
private void checkCursor(List<ConfigIssue> issues) { //According to MongoDB Oplog: https://docs.mongodb.com/manual/reference/method/cursor.batchSize/ //We should not use batch size of 1, and in mongo db world batch size of 1 is special //and equal to specifying limit 1, so the below queries will simply use limit 1 //rather than batchsize and limit both 1. if (configBean.isCapped) { try {//w w w.j av a2 s . c o m mongoCollection.find().cursorType(CursorType.TailableAwait).limit(1).iterator().close(); } catch (MongoQueryException e) { LOG.error("Error during Mongo Query in checkCursor: {}", e); issues.add(getContext().createConfigIssue(Groups.MONGODB.name(), MongoDBConfig.MONGO_CONFIG_PREFIX + "collection", Errors.MONGODB_04, configBean.mongoConfig.collection, e.toString())); } } else { try { mongoCollection.find().cursorType(CursorType.NonTailable).limit(1).iterator().close(); } catch (MongoQueryException e) { LOG.error("Error during Mongo Query in checkCursor: {}", e); issues.add(getContext().createConfigIssue(Groups.MONGODB.name(), MongoDBConfig.MONGO_CONFIG_PREFIX + "collection", Errors.MONGODB_06, configBean.mongoConfig.collection, e.toString())); } } }
From source file:com.streamsets.pipeline.stage.origin.mongodb.MongoDBSource.java
License:Apache License
private void prepareCursor(int maxBatchSize, String offsetField, String lastSourceOffset) { createMongoClient();// w ww. j a v a 2s . co m ObjectId offset; if (null == cursor) { if (null == lastSourceOffset || lastSourceOffset.isEmpty()) { offset = initialObjectId; } else { offset = new ObjectId(lastSourceOffset); } LOG.debug("Getting new cursor with params: {} {} {}", maxBatchSize, offsetField, lastSourceOffset); if (isCapped) { cursor = mongoCollection.find().filter(Filters.gt(offsetField, offset)) .cursorType(CursorType.TailableAwait).batchSize(maxBatchSize).iterator(); } else { cursor = mongoCollection.find().filter(Filters.gt(offsetField, offset)) .sort(Sorts.ascending(offsetField)).cursorType(CursorType.NonTailable) .batchSize(maxBatchSize).iterator(); } } }
From source file:com.streamsets.pipeline.stage.origin.mongodb.MongoDBSource.java
License:Apache License
private void checkCursor(List<ConfigIssue> issues) { if (isCapped) { try {/*from w ww . ja v a 2 s .c om*/ mongoCollection.find().cursorType(CursorType.TailableAwait).batchSize(1).limit(1).iterator() .close(); } catch (MongoQueryException e) { issues.add(getContext().createConfigIssue(Groups.MONGODB.name(), "collection", Errors.MONGODB_04, mongoDatabaseName, e.toString())); } } else { try { mongoCollection.find().cursorType(CursorType.NonTailable).batchSize(1).limit(1).iterator().close(); } catch (MongoQueryException e) { issues.add(getContext().createConfigIssue(Groups.MONGODB.name(), "collection", Errors.MONGODB_06, mongoDatabaseName, e.toString())); } } }