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

Java ClusterSettings类代码示例

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

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



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

示例1: open

import com.mongodb.connection.ClusterSettings; //导入依赖的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


示例2: createAsyncClient

import com.mongodb.connection.ClusterSettings; //导入依赖的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


示例3: extractServerAddresses

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
private List<ServerAddress> extractServerAddresses(MongoClient client) {
	Cluster cluster = (Cluster) ReflectionTestUtils.getField(client, "cluster");
	ClusterSettings clusterSettings = (ClusterSettings) ReflectionTestUtils
			.getField(cluster, "settings");
	List<ServerAddress> allAddresses = clusterSettings.getHosts();
	return allAddresses;
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:8,代码来源:MongoPropertiesTests.java


示例4: onEnable

import com.mongodb.connection.ClusterSettings; //导入依赖的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


示例5: ClusterSettingsParser

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
public ClusterSettingsParser(ConnectionString connectionString, JsonObject config) {
  ClusterSettings.Builder settings = ClusterSettings.builder();
  // ConnectionString takes precedence
  if (connectionString != null) {
    settings.applyConnectionString(connectionString);
  } else {
    // hosts
    List<ServerAddress> hosts = parseHosts(config);
    settings.hosts(hosts);

    // replica set / mode
    String replicaSet = config.getString("replicaSet");
    if (hosts.size() == 1 && replicaSet == null) {
      settings.mode(ClusterConnectionMode.SINGLE);
    } else {
      settings.mode(ClusterConnectionMode.MULTIPLE);
    }
    if (replicaSet != null) {
      settings.requiredReplicaSetName(replicaSet);
    }

    // serverSelectionTimeoutMS
    Long serverSelectionTimeoutMS = config.getLong("serverSelectionTimeoutMS");
    if(serverSelectionTimeoutMS != null) {
      settings.serverSelectionTimeout(serverSelectionTimeoutMS, MILLISECONDS);
    }

    Integer waitQueueMultiple = config.getInteger("waitQueueMultiple");
    if (waitQueueMultiple != null) {
      Integer waitQueueSize = waitQueueMultiple * DEFAULT_MONGO_DRIVER_WAIT_Q_SIZE;
      settings.maxWaitQueueSize(waitQueueSize);
    }
  }

  this.settings = settings.build();
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:37,代码来源:ClusterSettingsParser.java


示例6: assertSingleHost

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
private static void assertSingleHost(ClusterConnectionMode mode, ClusterSettings settings) {
  List<ServerAddress> hosts = settings.getHosts();
  assertNotNull(hosts);
  assertEquals(1, hosts.size());
  assertEquals(new ServerAddress("single.host", 1111), hosts.get(0));
  assertEquals(mode, settings.getMode());
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:8,代码来源:ClusterSettingsParserTest.java


示例7: assertMultipleHosts

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
private static void assertMultipleHosts(ClusterSettings settings) {
  List<ServerAddress> hosts = settings.getHosts();
  assertNotNull(hosts);
  assertEquals(2, hosts.size());
  assertEquals(new ServerAddress("multiple.1", 2222), hosts.get(0));
  assertEquals(new ServerAddress("multiple.2", 3333), hosts.get(1));
  assertEquals(ClusterConnectionMode.MULTIPLE, settings.getMode());
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:9,代码来源:ClusterSettingsParserTest.java


示例8: cluster

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
private Block cluster(final String db) {
  return unit -> {
    ClusterSettings settings = unit.mock(ClusterSettings.class);
    unit.registerMock(ClusterSettings.class, settings);

    ClusterSettings.Builder builder = unit.mock(ClusterSettings.Builder.class);
    expect(builder.applyConnectionString(new ConnectionString(db))).andReturn(builder);
    expect(builder.build()).andReturn(settings);

    unit.mockStatic(ClusterSettings.class);
    expect(ClusterSettings.builder()).andReturn(builder);
  };
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:14,代码来源:MongodbRxTest.java


示例9: start

import com.mongodb.connection.ClusterSettings; //导入依赖的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: createMongoClient

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
/**
 * Lazily instantiate the {@link MongoClient} instance.
 *
 * @return
 */
private MongoClient createMongoClient() {
  String host = applicationConfiguration.getMongoHost();
  int port = applicationConfiguration.getMongoPort();
  ConnectionString connectionString = new ConnectionString("mongodb://" + host + ":" + port);

  logger.info("Creating Mongo client for: {}:{}", host, port);

  MongoClientSettings mongoClientSettings =
      MongoClientSettings.builder()
          .applicationName("dragoman")
          .serverSettings(
              ServerSettings.builder()
                  .applyConnectionString(connectionString)
                  .addServerMonitorListener(new LoggingServerMonitorListener())
                  .addServerListener(new LoggingServerListener())
                  .build())
          .clusterSettings(
              ClusterSettings.builder()
                  .applyConnectionString(connectionString)
                  .serverSelectionTimeout(
                      applicationConfiguration.getMongoServerSelectionTimeout(), MILLISECONDS)
                  .addClusterListener(new LoggingClusterListener())
                  .build())
          .connectionPoolSettings(
              ConnectionPoolSettings.builder()
                  .applyConnectionString(connectionString)
                  .maxWaitTime(
                      applicationConfiguration.getConnectionPoolMaxWaitTime(), MILLISECONDS)
                  .minSize(applicationConfiguration.getConnectionPoolMinSize())
                  .maxSize(applicationConfiguration.getConnectionPoolMaxSize())
                  .addConnectionPoolListener(new LoggingConnectionPoolListener())
                  .build())
          .socketSettings(
              SocketSettings.builder()
                  .applyConnectionString(connectionString)
                  .connectTimeout(
                      applicationConfiguration.getMongoSocketConnectionTimeout(), MILLISECONDS)
                  .readTimeout(applicationConfiguration.getMongoReadTimeout(), MILLISECONDS)
                  .build())
          .build();

  return MongoClients.create(mongoClientSettings);
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:49,代码来源:MongoProviderImpl.java


示例11: mongoSettings

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
private MongoClientSettings mongoSettings(String host, int port) {
  return MongoClientSettings.builder()
      .clusterSettings(
          ClusterSettings.builder().hosts(newArrayList(new ServerAddress(host, port))).build())
      .build();
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:7,代码来源:IsMongoConnectedTest.java


示例12: settings

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
public ClusterSettings settings() {
  return settings;
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:4,代码来源:ClusterSettingsParser.java


示例13: testReplicaSetSingleHost

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
@Test
public void testReplicaSetSingleHost() {
  ClusterSettings settings = settings(singleHost().put("replicaSet", "foo"));
  assertSingleHost(ClusterConnectionMode.MULTIPLE, settings);
  assertEquals("foo", settings.getRequiredReplicaSetName());
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:7,代码来源:ClusterSettingsParserTest.java


示例14: testReplicaSetMultipleHosts

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
@Test
public void testReplicaSetMultipleHosts() {
  ClusterSettings settings = settings(multipleHosts().put("replicaSet", "foobar"));
  assertMultipleHosts(settings);
  assertEquals("foobar", settings.getRequiredReplicaSetName());
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:7,代码来源:ClusterSettingsParserTest.java


示例15: testServerSelectionTimeoutMS

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
@Test
public void testServerSelectionTimeoutMS() {
  ClusterSettings settings = settings(multipleHosts().put("serverSelectionTimeoutMS", 7533L));
  assertMultipleHosts(settings);
  assertEquals(7533L, settings.getServerSelectionTimeout(TimeUnit.MILLISECONDS));
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:7,代码来源:ClusterSettingsParserTest.java


示例16: testMaxWaitQueueSize

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
@Test
public void testMaxWaitQueueSize() {
  ClusterSettings settings = settings(multipleHosts().put("waitQueueMultiple", 10));
  assertEquals(ClusterSettingsParser.DEFAULT_MONGO_DRIVER_WAIT_Q_SIZE * 10, settings.getMaxWaitQueueSize());
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:6,代码来源:ClusterSettingsParserTest.java


示例17: settings

import com.mongodb.connection.ClusterSettings; //导入依赖的package包/类
private static ClusterSettings settings(JsonObject config) {
  return new ClusterSettingsParser(null, config).settings();
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:4,代码来源:ClusterSettingsParserTest.java


示例18: connect

import com.mongodb.connection.ClusterSettings; //导入依赖的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.connection.ClusterSettings类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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