当前位置: 首页>>代码示例>>Java>>正文


Java CursorType类代码示例

本文整理汇总了Java中com.mongodb.CursorType的典型用法代码示例。如果您正苦于以下问题:Java CursorType类的具体用法?Java CursorType怎么用?Java CursorType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CursorType类属于com.mongodb包,在下文中一共展示了CursorType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: call

import com.mongodb.CursorType; //导入依赖的package包/类
@Override
public Void call() throws Exception {
    
    final Date now = new Date();
    final Document query = new Document("ns", ns)
        .append("ts", new Document("$gt", new BSONTimestamp((int) (now.getTime() / 1000), 0)));
    
    final MongoCursor<Document> cursor = oplog.find(query)
        .cursorType(CursorType.TailableAwait).iterator();
    
    while (cursor.hasNext()) {
        final Document doc = cursor.next();
        for (final OplogListener listener : listeners) {
            listener.onOplog(doc);
        }
    }

    return null;
}
 
开发者ID:bbonnin,项目名称:mongo2els,代码行数:20,代码来源:OplogTailer.java

示例2: createCollection

import com.mongodb.CursorType; //导入依赖的package包/类
@Before
public void createCollection() throws Exception {
  MongoDatabase db = mongoClient.getDatabase(DATABASE);
  testCollectionName = name.getMethodName();
  db.createCollection(testCollectionName);
  final long currentTime = System.currentTimeMillis();
  //To make sure that oplog is read on each method after we created the above collection.
  //We let this current second pass, before we get the initial timestamp seconds.
  Awaitility.await().untilTrue(new AtomicBoolean((System.currentTimeMillis() - currentTime) > 1000));
  //So we can skip old oplogs and just start with whatever this test is producing
  initialTs = getInitialTsFromCurrentTime();
  testDocuments = mongoClient.getDatabase(DATABASE).getCollection(testCollectionName);
  mongoCursorFindIterable = mongoClient.getDatabase("local").getCollection(OPLOG_COLLECTION)
      .find()
      //As the collection is a capped collection we use Tailable cursor which will return results in natural order in this case
      //based on ts timestamp field.
      //Tailable Await does not return and blocks, so we are using tailable.
      .cursorType(CursorType.Tailable);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:20,代码来源:MongoDBOplogSourceIT.java

示例3: getCursor

import com.mongodb.CursorType; //导入依赖的package包/类
private FindIterable<O2MSyncEventLog> getCursor() throws InterruptedException {
	Thread.sleep(waitTime);
	waitTime *= retryCount;
	logCollection = MongoConnection.INSTANCE.getMongoDataBase()
			.getCollection(String.valueOf(ApplicationCollections.O2MSyncEventLog), O2MSyncEventLog.class);
	FindIterable<O2MSyncEventLog> it = logCollection
			.find(Filters.and(Filters.eq(O2MSyncEventLogCodec.EVENT_ID, String.valueOf(eventId)),
					Filters.eq(O2MSyncEventLogCodec.STATUS, O2MSyncEventLogCodec.PENDING)))
			.cursorType(CursorType.TailableAwait).noCursorTimeout(true);
	return it;
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:12,代码来源:OrclToMngSyncReader.java

示例4: getCursor

import com.mongodb.CursorType; //导入依赖的package包/类
private FindIterable<Document> getCursor(){
	MongoClient client = DBCacheManager.INSTANCE.getCachedMongoPool(mongoDbName, mongoUserName);
	//MongoClient client = DBCacheManager.INSTANCE.getCachedMongoPool(mongoDbName, "ccwOplRO");
	client.setReadPreference(ReadPreference.secondary());
	MongoCollection<Document> collection =client.getDatabase(localDb).getCollection(oplogRs);
	FindIterable<Document> it = collection.find(Filters.and(Filters.eq(NS, ns),Filters.gt(TS, lastReadTime)))
			.cursorType(CursorType.TailableAwait).noCursorTimeout(true).maxAwaitTime(30, TimeUnit.MINUTES);
	return it;
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:10,代码来源:MngOpLogReader.java

示例5: testFind

import com.mongodb.CursorType; //导入依赖的package包/类
@Test
public void testFind()
{
    FindIterable<Document> find = coll.find(Filters.eq("name", "Alto"), Document.class)
        .sort(Sorts.ascending("color"));
    List<Document> docList = toDocumentList(find);
    assertEquals(4, docList.size());

    find = coll.find(Filters.eq("name", "Alto")).sort(Sorts.ascending("color"));
    docList = toDocumentList(find);
    assertEquals(4, docList.size());

    find = coll.find(Document.class).filter(Filters.eq("name", "Alto")).sort(Sorts.ascending("color"));
    docList = toDocumentList(find);
    assertEquals(4, docList.size());

    find = coll.find().filter(Filters.eq("name", "Alto")).sort(Sorts.ascending("color"));
    docList = toDocumentList(find);
    assertEquals(4, docList.size());

    find = coll.find().filter(Filters.eq("name", "Alto")).sort(Sorts.ascending("color")).batchSize(123)
        .collation(Collation.builder().build()).cursorType(CursorType.NonTailable).limit(2)
        .maxAwaitTime(12, TimeUnit.DAYS).maxTime(12, TimeUnit.DAYS).noCursorTimeout(true).oplogReplay(false)
        .partial(false).skip(1);
    docList = toDocumentList(find);
    assertEquals(2, docList.size());

    Document firstFind = coll.find().filter(Filters.eq("name", "Alto")).sort(Sorts.ascending("color")).first();
    Assert.assertNotNull(firstFind);

    coll.find().filter(Filters.eq("name", "Alto")).forEach(new Block<Document>()
    {
        @Override
        public void apply(Document t)
        {
            System.out.println(t.get("name"));
        }
    });

}
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:41,代码来源:ProfiledMongoClientTest.java

示例6: find

import com.mongodb.CursorType; //导入依赖的package包/类
private FindIterable<Document> find(int page){
    final FindIterable<Document> documents = oplog
            .find(query)
            .sort(new Document("$natural", 1))
            .skip(page * batchSize)
            .limit(batchSize)
            .projection(Projections.include("ts", "op", "ns", "o"))
            .cursorType(CursorType.TailableAwait);
    return documents;
}
 
开发者ID:DataReply,项目名称:kafka-connect-mongodb,代码行数:11,代码来源:DatabaseReader.java

示例7: bindHostToPublisher

import com.mongodb.CursorType; //导入依赖的package包/类
private void bindHostToPublisher(MongoCollection<Document> tsCollection,
      Map<String, FindPublisher<Document>> publishers, List<MongoClientWrapper> clients) {
   for (MongoClientWrapper client : clients) {
      logger.info("------------ Binding "+client.getHost()+" to oplog. ---------------");
      FindPublisher<Document> oplogPublisher = client.getClient().getDatabase("local")
            .getCollection("oplog.rs").find().filter(getQueryFilter(tsCollection, client))
            .sort(new Document("$natural", 1)).cursorType(CursorType.TailableAwait);
      publishers.put(client.getHost(), oplogPublisher);
   }
}
 
开发者ID:JaiHirsch,项目名称:flink-mingo-tail,代码行数:11,代码来源:MongoOplogTailMapper.java

示例8: main

import com.mongodb.CursorType; //导入依赖的package包/类
public static void main(String[] args) {

        try (MongoClient client = new MongoClient()) {

            FindIterable<Document> oplogTail = client.getDatabase("local")
                    .getCollection("oplog.rs").find().filter(getQueryFilter())
                    .sort(new Document("$natural", 1)).cursorType(CursorType.TailableAwait);

            oplogTail.forEach((Block<Document>) document -> System.out.println(document));
        }
    }
 
开发者ID:JaiHirsch,项目名称:flink-mingo-tail,代码行数:12,代码来源:SimpleOplogTailExample.java

示例9: tailQueue

import com.mongodb.CursorType; //导入依赖的package包/类
private void tailQueue() {
    while (!engine.isDestroyed()) {
        try {
            FindIterable<org.bson.Document> cursor;
            if (lastProcessed == null) {
                cursor = queueCollection.find(and(ne(PID, pid),gt(CREATED,new Date().getTime()))).cursorType(CursorType.TailableAwait);
            } else {
                cursor = queueCollection.find(and(ne(PID, pid), gt("_id", lastProcessed))).cursorType(CursorType.TailableAwait);
            }
            cursor.forEach(new Block<org.bson.Document>() {
                @Override
                public void apply(final org.bson.Document event) {
                    lastProcessed = event.getObjectId("_id");
                    engine.execute(new Runnable() {

                        @Override
                        public void run() {
                               processEvent(event);
                        }
                    }, null);
                 

                }
            });
        } catch (Exception ex) {
            LOG.severe("Exception while tailing event queue: " + ex.getMessage());
            ex.printStackTrace();
        }
    }
}
 
开发者ID:KAOREND,项目名称:reactive-hamster,代码行数:31,代码来源:EventQueue.java

示例10: initializeCursor

import com.mongodb.CursorType; //导入依赖的package包/类
private MongoCursor<BasicDBObject> initializeCursor() {
    Object lastVal = tailTracking.lastVal;
    // lastVal can be null if we are initializing and there is no persistence enabled
    MongoCursor<BasicDBObject> answer;
    if (lastVal == null) {
        answer = dbCol.find().cursorType(CursorType.TailableAwait).iterator();
    } else {
        BasicDBObject queryObj = new BasicDBObject(tailTracking.getIncreasingFieldName(), new BasicDBObject("$gt", lastVal));
        answer = dbCol.find(queryObj).cursorType(CursorType.TailableAwait).iterator();
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:MongoDbTailingProcess.java

示例11: run

import com.mongodb.CursorType; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void run() {
    BsonTimestamp timestamp = OpLogUtils.getLatestOplogTimestamp(oplog);
    if (timestamp == null) {
        LOGGER.severe("OpLog is not ready. Please make sure that the server maintains an oplog and restart this server.");
        return;
    }
    final AtomicReference<BsonTimestamp> last = new AtomicReference<>(timestamp);
    //noinspection InfiniteLoopStatement
    while (true) {
        final CountDownLatch waiter = new CountDownLatch(1);
        oplog.find(Filters.and(Filters.gt("ts", last.get()), Filters.eq("ns", namespace))).cursorType(CursorType.TailableAwait).forEach(
                new Block<BsonDocument>() {
                    @Override
                    public void apply(BsonDocument document) {
                        BsonTimestamp current = document.getTimestamp("ts");
                        if (current.getTime() > last.get().getTime()) {
                            last.set(current);
                            parser.emit(document);
                        }
                    }
                },
                new SingleResultCallback<Void>() {
                    @Override
                    public void onResult(Void aVoid, Throwable throwable) {
                        waiter.countDown();
                    }
                }
        );
        ConcurrentUtils.safeAwait(waiter);
    }
}
 
开发者ID:maxikg,项目名称:mongowg,代码行数:36,代码来源:OpLogRetriever.java

示例12: prepareCursor

import com.mongodb.CursorType; //导入依赖的package包/类
private void prepareCursor(int timestampSeconds, int ordinal, List<OplogOpType> filterOplogTypes, int batchSize) {
  LOG.debug("Getting new cursor with offset - TimeStampInSeconds:'{}', Ordinal : '{}' and Batch Size : '{}'",timestampSeconds, ordinal, batchSize);
  FindIterable<Document> mongoCursorIterable = mongoCollection
      .find()
      //As the collection is a capped collection we use Tailable cursor which will return results in natural order in this case
      //based on ts timestamp field.
      //Tailable Await does not return and blocks, so we are using tailable.
      .cursorType(CursorType.Tailable)
      .batchSize(batchSize);

  List<Bson> andFilters = new ArrayList<>();
  //Only filter if we already have saved/initial offset specified or else both time_t and ordinal will not be -1.
  if (timestampSeconds > 0 && ordinal >= 0) {
    andFilters.add(Filters.gt(TIMESTAMP_FIELD, new BsonTimestamp(timestampSeconds, ordinal)));
  }

  if (!filterOplogTypes.isEmpty()) {
    List<Bson> oplogOptypeFilters = new ArrayList<>();
    Set<OplogOpType> oplogOpTypesSet = new HashSet<>();
    for (OplogOpType filterOplogopType : filterOplogTypes) {
      if (oplogOpTypesSet.add(filterOplogopType)) {
        oplogOptypeFilters.add(Filters.eq(OP_TYPE_FIELD, filterOplogopType.getOp()));
      }
    }
    //Add an or filter for filtered Or Types
    andFilters.add(Filters.or(oplogOptypeFilters));
  }
  //Finally and timestamp with oplog filters
  if (!andFilters.isEmpty()) {
    mongoCursorIterable = mongoCursorIterable.filter(Filters.and(andFilters));
  }
  cursor = mongoCursorIterable.iterator();
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:34,代码来源:MongoDBOplogSource.java

示例13: toCursorType

import com.mongodb.CursorType; //导入依赖的package包/类
private CursorType toCursorType(QueryOptions queryOptions) {
  if (!queryOptions.isTailable()) {
    return CursorType.NonTailable;
  }
  if (queryOptions.isAwaitData()) {
    return CursorType.TailableAwait;
  }
  return CursorType.Tailable;
}
 
开发者ID:torodb,项目名称:mongowp,代码行数:10,代码来源:MongoConnectionWrapper.java

示例14: testTailableCursors

import com.mongodb.CursorType; //导入依赖的package包/类
@Test
public void testTailableCursors() {
    getMorphia().map(CappedPic.class);
    getDs().ensureCaps();
    final Query<CappedPic> query = getDs().find(CappedPic.class);
    final List<CappedPic> found = new ArrayList<CappedPic>();
    final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);

    assertEquals(0, query.count());

    executorService.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            getDs().save(new CappedPic(System.currentTimeMillis() + ""));
        }
    }, 0, 500, TimeUnit.MILLISECONDS);

    final Iterator<CappedPic> tail = query
        .fetch(new FindOptions()
                   .cursorType(CursorType.Tailable));
    Awaitility
        .await()
        .pollDelay(500, TimeUnit.MILLISECONDS)
        .atMost(10, TimeUnit.SECONDS)
        .until(new Callable<Boolean>() {
            @Override
            public Boolean call() {
                if (tail.hasNext()) {
                    found.add(tail.next());
                }
                return found.size() >= 10;
            }
        });
    executorService.shutdownNow();
    Assert.assertTrue(query.count() >= 10);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:37,代码来源:TestQuery.java

示例15: getCursorType

import com.mongodb.CursorType; //导入依赖的package包/类
public CursorType getCursorType()
{
    return cursorType;
}
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:5,代码来源:ProfiledFindIterable.java


注:本文中的com.mongodb.CursorType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。