类com.mongodb.async.client.MongoClientSettings源码实例Demo

下面列出了怎么用com.mongodb.async.client.MongoClientSettings的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ditto   文件: MongoClientWrapperTest.java
private static void assertWithExpected(final DittoMongoClient mongoClient, final boolean sslEnabled,
        final boolean withCredentials) {

    final MongoClientSettings mongoClientSettings = mongoClient.getSettings();
    assertThat(mongoClientSettings.getClusterSettings().getHosts())
            .isEqualTo(Collections.singletonList(new ServerAddress(KNOWN_SERVER_ADDRESS)));

    final List<MongoCredential> expectedCredentials = withCredentials ? Collections.singletonList(
            MongoCredential.createCredential(KNOWN_USER, KNOWN_DB_NAME, KNOWN_PASSWORD.toCharArray())) :
            Collections.emptyList();
    assertThat(mongoClientSettings.getCredentialList()).isEqualTo(
            expectedCredentials);
    assertThat(mongoClientSettings.getSslSettings().isEnabled()).isEqualTo(sslEnabled);

    final MongoDatabase mongoDatabase = mongoClient.getDefaultDatabase();
    assertThat(mongoDatabase).isNotNull();
    assertThat(mongoDatabase.getName()).isEqualTo(KNOWN_DB_NAME);
}
 
@Override
public void afterPropertiesSet() throws Exception {

    final IMongodConfig mongodConfig = new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION).build();

    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
            .defaultsWithLogger(Command.MongoD, logger)
            .processOutput(ProcessOutput.getDefaultInstanceSilent())
            .build();

    MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);

    MongodExecutable mongodExecutable = runtime.prepare(mongodConfig);
    mongod = mongodExecutable.start();

    // cluster configuration
    ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(new ServerAddress(mongodConfig.net().getServerAddress().getHostName(), mongodConfig.net().getPort()))).build();
    // codec configuration
    CodecRegistry pojoCodecRegistry = fromRegistries(MongoClients.getDefaultCodecRegistry(),
            fromProviders(PojoCodecProvider.builder().automatic(true).build()));

    MongoClientSettings settings = MongoClientSettings.builder().clusterSettings(clusterSettings).codecRegistry(pojoCodecRegistry).writeConcern(WriteConcern.ACKNOWLEDGED).build();
    mongoClient = MongoClients.create(settings);
    mongoDatabase = mongoClient.getDatabase(databaseName);
}
 
@Override
public void afterPropertiesSet() throws Exception {
    final IMongodConfig mongodConfig = new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION).build();

    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
            .defaultsWithLogger(Command.MongoD, logger)
            .processOutput(ProcessOutput.getDefaultInstanceSilent())
            .build();

    MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);

    MongodExecutable mongodExecutable = runtime.prepare(mongodConfig);
    mongod = mongodExecutable.start();

    // cluster configuration
    ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(new ServerAddress(mongodConfig.net().getServerAddress().getHostName(), mongodConfig.net().getPort()))).build();
    // codec configuration
    CodecRegistry pojoCodecRegistry = fromRegistries(MongoClients.getDefaultCodecRegistry(),
            fromProviders(PojoCodecProvider.builder().automatic(true).build()));

    MongoClientSettings settings = MongoClientSettings.builder().clusterSettings(clusterSettings).codecRegistry(pojoCodecRegistry).writeConcern(WriteConcern.ACKNOWLEDGED).build();
    mongoClient = MongoClients.create(settings);
    mongoDatabase = mongoClient.getDatabase(databaseName);
}
 
@Bean
public MongoClient mongoClient() throws IOException {
  ServerAddress serverAddress = getServerAddress();
  MongoClientSettings settings = MongoClientSettings.builder()
                                                    .clusterSettings(ClusterSettings.builder()
                                                                                    .hosts(singletonList(serverAddress))
                                                                                    .requiredClusterType(STANDALONE)
                                                                                    .build()).build();
  return MongoClients.create(settings);
}
 
源代码5 项目: mongo-java-driver-rx   文件: MongoClientImpl.java
@Override
public MongoClientSettings getSettings() {
    return wrapped.getSettings();
}
 
源代码6 项目: mongo-java-driver-rx   文件: MongoClient.java
/**
 * Gets the settings that this client uses to connect to server.
 *
 * <p>Note: {@link MongoClientSettings} is immutable.</p>
 *
 * @return the settings
 */
MongoClientSettings getSettings();
 
源代码7 项目: mongo-java-driver-rx   文件: MongoClients.java
/**
 * Create a new client with the given client settings.
 *
 * @param settings the settings
 * @return the client
 */
public static MongoClient create(final MongoClientSettings settings) {
    return create(settings, new NoopObservableAdapter());
}
 
源代码8 项目: mongo-java-driver-rx   文件: MongoClients.java
/**
 * Create a new client with the given client settings.
 *
 * @param settings the settings
 * @param observableAdapter the {@link ObservableAdapter} to adapt all {@code Observables}
 * @return the client
 * @since 1.2
 */
public static MongoClient create(final MongoClientSettings settings, final ObservableAdapter observableAdapter) {
    return create(settings, observableAdapter, null);
}
 
源代码9 项目: mongo-java-driver-rx   文件: MongoClients.java
/**
 * Creates a new client with the given client settings.
 *
 * <p>Note: Intended for driver and library authors to associate extra driver metadata with the connections.</p>
 *
 * @param settings the settings
 * @param observableAdapter the {@link ObservableAdapter} to adapt all {@code Observables}.
 * @param mongoDriverInformation any driver information to associate with the MongoClient
 * @return the client
 * @since 1.3
 */
public static MongoClient create(final MongoClientSettings settings, final ObservableAdapter observableAdapter,
                                 final MongoDriverInformation mongoDriverInformation) {
    return create(com.mongodb.async.client.MongoClients.create(settings, getMongoDriverInformation(mongoDriverInformation)),
            observableAdapter);
}
 
 类所在包
 类方法
 同包方法