• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MongoClients类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: DatabaseWriter

import com.mongodb.async.client.MongoClients; //导入依赖的package包/类
/**
 * DataWriter constructor
 *
 * @throws IllegalStateException if database configuration is not set
 */
private DatabaseWriter() {
    try {
        final MongoClient mongoClient = MongoClients.create(PROPERTIES_MANAGER.getProperty("database.host"));
        final MongoDatabase mongoDatabase = mongoClient.getDatabase(PROPERTIES_MANAGER.getProperty("database.datasource"));
        this.mongoCollection = mongoDatabase.getCollection(PROPERTIES_MANAGER.getProperty("database.collection"));
    } catch (IllegalArgumentException e) {
        LOGGER.error(e.getMessage());
        throw new IllegalStateException(e.getMessage());
    }
    LOGGER.info("DatabaseWriter has been instantiate");
}
 
开发者ID:IKB4Stream,项目名称:IKB4Stream,代码行数:17,代码来源:DatabaseWriter.java


示例2: open

import com.mongodb.async.client.MongoClients; //导入依赖的package包/类
@Override
public CompletableFuture<SecurityDefinitionStore> open() {
  List<ServerAddress> hostList =
      Arrays.stream(hosts).map(h -> new ServerAddress(h)).collect(Collectors.toList());
  ClusterSettings clusterSettings = ClusterSettings.builder().hosts(hostList).build();
  MongoClientSettings settings =
      MongoClientSettings.builder().clusterSettings(clusterSettings).build();
  mongoClient = MongoClients.create(settings);

  database = mongoClient.getDatabase(DATABASE_NAME);
  collection = database.getCollection(SECDEF_COLLECTION_NAME);

  // In the case of MongoDB, open is synchronous because it doesn't
  // actually communicate with the server until a query is invoked.
  return CompletableFuture.completedFuture(this);
}
 
开发者ID:FIXTradingCommunity,项目名称:timpani,代码行数:17,代码来源:MongoDBSecurityDefinitionStore.java


示例3: getMongoClient

import com.mongodb.async.client.MongoClients; //导入依赖的package包/类
/**
 * Get or create the MongoDB client
 * @return the MongoDB client
 */
private MongoClient getMongoClient() {
  if (mongoClient == null) {
    mongoClient = MongoClients.create(connectionString);
  }
  return mongoClient;
}
 
开发者ID:georocket,项目名称:georocket,代码行数:11,代码来源:MongoDBStore.java


示例4: createAsyncClient

import com.mongodb.async.client.MongoClients; //导入依赖的package包/类
/**
 * Create an asynchronous MongoDB client
 * @return the client
 */
private com.mongodb.async.client.MongoClient createAsyncClient() {
  ClusterSettings clusterSettings = ClusterSettings.builder()
      .hosts(Arrays.asList(mongoConnector.serverAddress))
      .build();
  MongoClientSettings settings = MongoClientSettings.builder()
      .clusterSettings(clusterSettings).build();
  return MongoClients.create(settings);
}
 
开发者ID:georocket,项目名称:georocket,代码行数:13,代码来源:MongoDBChunkReadStreamTest.java


示例5: QueryAsync

import com.mongodb.async.client.MongoClients; //导入依赖的package包/类
/**
 *
 * @param mongi
 */
public QueryAsync(Mongi mongi){

    this.mongi = mongi;
    mongiDb = mongi.getMongoDatabase();
    mongoClient = mongi.getMongoClient();
    // Use a Connection String
    mongoClientAsyn = MongoClients.create("mongodb://localhost");
    database = mongoClientAsyn.getDatabase("testingMe");
    coll = database.getCollection("test");

}
 
开发者ID:stump201,项目名称:mongiORM,代码行数:16,代码来源:QueryAsync.java


示例6: onEnable

import com.mongodb.async.client.MongoClients; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void onEnable() {
    saveDefaultConfig();

    CodecRegistry codecRegistry = createCodecRegistry();
    MongoClientSettings settings = MongoClientSettings.builder()
            .clusterSettings(ClusterSettings.builder().applyConnectionString(new ConnectionString(getConfig().getString("mongodb.uri"))).build())
            .codecRegistry(codecRegistry)
            .build();
    client = MongoClients.create(settings);
    MongoDatabase database = client.getDatabase(getConfig().getString("mongodb.database"));
    if (!testConnection(database))
        return;
    RegionStorageAdapter storageAdapter = new RegionStorageAdapter(database);
    MongoRegionDriver driver = new MongoRegionDriver(getServer(), storageAdapter);

    WorldGuardPlugin wgPlugin = WorldGuardPlugin.inst();
    if (getConfig().getBoolean("mongodb.use_oplog")) {
        getLogger().info("OpLog usage enabled.");
        WorldGuardOpLogHandler opLogHandler = new WorldGuardOpLogHandler(codecRegistry.get(ProcessingProtectedRegion.class), storageAdapter, wgPlugin);
        getServer().getScheduler().runTaskAsynchronously(this, new OpLogRetriever(
                OpLogUtils.getCollection(client),
                new OpLogParser(opLogHandler),
                getConfig().getString("mongodb.database") + "." + RegionStorageAdapter.COLLECTION_NAME
        ));
        storageAdapter.setListener(opLogHandler);
    }

    ConfigurationManager config = wgPlugin.getGlobalStateManager();
    RegionContainer container = wgPlugin.getRegionContainer();
    InjectionUtils.injectRegionDriver(container, driver);
    InjectionUtils.callUnload(container);
    InjectionUtils.callLoadWorlds(container);
    config.selectedRegionStoreDriver = driver;
}
 
开发者ID:maxikg,项目名称:mongowg,代码行数:39,代码来源:MongoWGPlugin.java


示例7: mongo

import com.mongodb.async.client.MongoClients; //导入依赖的package包/类
synchronized com.mongodb.async.client.MongoClient mongo() {
  if (mongo == null) {
    MongoClientOptionsParser parser = new MongoClientOptionsParser(config);
    mongo = MongoClients.create(parser.settings());
    db = mongo.getDatabase(parser.database());
  }
  return mongo;
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:9,代码来源:MongoClientImpl.java


示例8: setUp

import com.mongodb.async.client.MongoClients; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
  super.setUp();
  JsonObject config = getConfig();
  mongoClient = MongoClient.createNonShared(vertx, config);
  CountDownLatch latch = new CountDownLatch(1);
  dropCollections(mongoClient, latch);
  awaitLatch(latch);


  actualMongo = MongoClients.create("mongodb://localhost:27018");
  db = actualMongo.getDatabase(io.vertx.ext.mongo.MongoClient.DEFAULT_DB_NAME);
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:14,代码来源:MongoClientTest.java


示例9: start

import com.mongodb.async.client.MongoClients; //导入依赖的package包/类
@Start
public void start() {
    final ClusterSettings clusterSettings = ClusterSettings.builder().hosts(asList(new ServerAddress(host, port))).build();
    final MongoClientSettings settings = MongoClientSettings.builder().clusterSettings(clusterSettings).build();
    mongoClient = MongoClients.create(settings);
    db = mongoClient.getDatabase(this.database);
    launchConsumers();
}
 
开发者ID:kevoree,项目名称:kevoree-library,代码行数:9,代码来源:MongoChan.java


示例10: connect

import com.mongodb.async.client.MongoClients; //导入依赖的package包/类
private void connect() throws ActivecheckReporterException {
    if (mongoClient == null) {
        logger.debug("Cannot run query. MongoDB is not connected. Trying to (re)connect.");
        try {
            // configure credentials
            List<MongoCredential> credentialsList = new ArrayList<MongoCredential>();
            String username = properties
                    .getString("mongodb.username", null);
            String password = properties
                    .getString("mongodb.password", null);
            if (username != null && password != null) {
                credentialsList.add(MongoCredential.createPlainCredential(
                        username, "*", password.toCharArray()));
            }

            // configure server addresses
            List<ServerAddress> addressList = new ArrayList<ServerAddress>();
            String socketPath = properties.getString("socket", null);
            if (socketPath != null) {
                addressList.add(new ServerAddress(new AFUNIXSocketAddress(
                        new File(socketPath))));
            } else {
                String url = properties.getString("url",
                        ServerAddress.defaultHost());
                int port = ServerAddress.defaultPort();
                String[] urlParts = url.split(":");
                if (urlParts.length > 1) {
                    port = Integer.parseInt(urlParts[1]);
                }
                addressList.add(new ServerAddress(urlParts[0], port));
            }
            ServerSelector serverSelector = new ReadPreferenceServerSelector(
                    MONGO_READ_PREFERENCE);
            ClusterSettings clusterSettings = ClusterSettings.builder()
                    .hosts(addressList).serverSelector(serverSelector)
                    .build();

            // actually configure and (re)create mongoClient
            ConnectionPoolSettings connectionPoolSettings = ConnectionPoolSettings
                    .builder().maxSize(MONGO_POOL_SIZE).build();
            MongoClientSettings settings = MongoClientSettings.builder()
                    .readPreference(MONGO_READ_PREFERENCE)
                    .credentialList(credentialsList)
                    .clusterSettings(clusterSettings)
                    .connectionPoolSettings(connectionPoolSettings).build();
            mongoClient = MongoClients.create(settings);
        } catch (Exception e) {
            mongoClient = null;
            String errorMessage = "MongodbReporter Configuration Error for service '"
                    + getOverallServiceName() + "': " + e.getMessage();

            logger.error(errorMessage);
            logger.trace(e.getMessage(), e);

            // set report and status
            setOverallServiceReport(NagiosServiceStatus.CRITICAL,
                    errorMessage);
            throw new ActivecheckReporterException(e);
        }
    }
}
 
开发者ID:frederikhappel,项目名称:activecheck,代码行数:62,代码来源:MongodbReporter.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GetFile类代码示例发布时间:2022-05-23
下一篇:
Java WSDLConstants类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap