本文整理汇总了Java中com.mongodb.Mongo.close方法的典型用法代码示例。如果您正苦于以下问题:Java Mongo.close方法的具体用法?Java Mongo.close怎么用?Java Mongo.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.Mongo
的用法示例。
在下文中一共展示了Mongo.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEstimatedSizeBytes
import com.mongodb.Mongo; //导入方法依赖的package包/类
@Override
public long getEstimatedSizeBytes(PipelineOptions options) throws Exception {
Mongo mongo = spec.connectionConfiguration().setupMongo();
try {
GridFS gridfs = spec.connectionConfiguration().setupGridFS(mongo);
DBCursor cursor = createCursor(gridfs);
long size = 0;
while (cursor.hasNext()) {
GridFSDBFile file = (GridFSDBFile) cursor.next();
size += file.getLength();
}
return size;
} finally {
mongo.close();
}
}
示例2: destroy
import com.mongodb.Mongo; //导入方法依赖的package包/类
@Override
public void destroy() throws Exception {
if (!CollectionUtils.isEmpty(activityMongos)) {
for (Mongo mongo : activityMongos) {
mongo.close();
}
}
}
示例3: split
import com.mongodb.Mongo; //导入方法依赖的package包/类
@Override
public List<? extends BoundedSource<ObjectId>> split(
long desiredBundleSizeBytes, PipelineOptions options) throws Exception {
Mongo mongo = spec.connectionConfiguration().setupMongo();
try {
GridFS gridfs = spec.connectionConfiguration().setupGridFS(mongo);
DBCursor cursor = createCursor(gridfs);
long size = 0;
List<BoundedGridFSSource> list = new ArrayList<>();
List<ObjectId> objects = new ArrayList<>();
while (cursor.hasNext()) {
GridFSDBFile file = (GridFSDBFile) cursor.next();
long len = file.getLength();
if ((size + len) > desiredBundleSizeBytes && !objects.isEmpty()) {
list.add(new BoundedGridFSSource(spec, objects));
size = 0;
objects = new ArrayList<>();
}
objects.add((ObjectId) file.getId());
size += len;
}
if (!objects.isEmpty() || list.isEmpty()) {
list.add(new BoundedGridFSSource(spec, objects));
}
return list;
} finally {
mongo.close();
}
}