List of usage examples for com.mongodb.async.client MongoIterable into
<A extends Collection<? super TResult>> void into(A target, SingleResultCallback<A> callback);
From source file:com.supermy.im.mongo.MongoRepository.java
License:Apache License
/** * * @param collectionName/*w ww . j a v a 2s .c om*/ * @return */ public boolean collectionExists(final String collectionName) { MongoIterable colls = mongoDatabase().listCollectionNames(); List<String> collectionNames = new ArrayList<String>(); try { final CountDownLatch countDownLatch = new CountDownLatch(1);//?? colls.into(collectionNames, new SingleResultCallback<Void>() { @Override public void onResult(final Void result, final Throwable t) { // logger.debug("?"); countDownLatch.countDown(); } }); countDownLatch.await(2, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(collectionNames); System.out.println(collectionNames.size()); for (String name : collectionNames) { if (name.equalsIgnoreCase(collectionName)) { return true; } } return false; }
From source file:io.vertx.ext.mongo.impl.MongoClientImpl.java
License:Open Source License
private void convertMongoIterable(MongoIterable iterable, Handler<AsyncResult<JsonArray>> resultHandler) { List results = new ArrayList(); try {/*from w w w . j av a 2 s. co m*/ Context context = vertx.getOrCreateContext(); iterable.into(results, (result, throwable) -> { context.runOnContext(v -> { if (throwable != null) { resultHandler.handle(Future.failedFuture(throwable)); } else { resultHandler.handle(Future.succeededFuture(new JsonArray((List) result))); } }); }); } catch (Exception unhandledEx) { resultHandler.handle(Future.failedFuture(unhandledEx)); } }