本文整理汇总了Java中com.mongodb.async.client.MongoClientSettings类的典型用法代码示例。如果您正苦于以下问题:Java MongoClientSettings类的具体用法?Java MongoClientSettings怎么用?Java MongoClientSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoClientSettings类属于com.mongodb.async.client包,在下文中一共展示了MongoClientSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: open
import com.mongodb.async.client.MongoClientSettings; //导入依赖的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.async.client.MongoClientSettings; //导入依赖的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: onEnable
import com.mongodb.async.client.MongoClientSettings; //导入依赖的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
示例4: start
import com.mongodb.async.client.MongoClientSettings; //导入依赖的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
示例5: createMongoClient
import com.mongodb.async.client.MongoClientSettings; //导入依赖的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
示例6: mongoSettings
import com.mongodb.async.client.MongoClientSettings; //导入依赖的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
示例7: getSettings
import com.mongodb.async.client.MongoClientSettings; //导入依赖的package包/类
@Override
public MongoClientSettings getSettings() {
return wrapped.getSettings();
}
开发者ID:mongodb,项目名称:mongo-java-driver-rx,代码行数:5,代码来源:MongoClientImpl.java
示例8: MongoClientOptionsParser
import com.mongodb.async.client.MongoClientSettings; //导入依赖的package包/类
public MongoClientOptionsParser(JsonObject config) {
Objects.requireNonNull(config);
MongoClientSettings.Builder options = MongoClientSettings.builder();
options.codecRegistry(CodecRegistries.fromRegistries(commonCodecRegistry, CodecRegistries.fromCodecs(new JsonObjectCodec(config))));
// All parsers should support connection_string first
String cs = config.getString("connection_string");
ConnectionString connectionString = (cs == null) ? null : new ConnectionString(cs);
String csDatabase = (connectionString != null) ? connectionString.getDatabase() : null;
this.database = csDatabase != null ? csDatabase : config.getString("db_name", MongoClient.DEFAULT_DB_NAME);
// ClusterSettings
ClusterSettings clusterSettings = new ClusterSettingsParser(connectionString, config).settings();
options.clusterSettings(clusterSettings);
// ConnectionPoolSettings
ConnectionPoolSettings connectionPoolSettings = new ConnectionPoolSettingsParser(connectionString, config).settings();
options.connectionPoolSettings(connectionPoolSettings);
// Credentials
List<MongoCredential> credentials = new CredentialListParser(connectionString, config).credentials();
options.credentialList(credentials);
// SocketSettings
SocketSettings socketSettings = new SocketSettingsParser(connectionString, config).settings();
options.socketSettings(socketSettings);
// SSLSettings
SslSettings sslSettings = new SSLSettingsParser(connectionString, config).settings();
options.sslSettings(sslSettings);
// WriteConcern
WriteConcern writeConcern = new WriteConcernParser(connectionString, config).writeConcern();
if (writeConcern != null) {
options.writeConcern(writeConcern);
}
// ReadConcern
maybeReadConcern(connectionString, config).ifPresent(options::readConcern);
// ReadPreference
ReadPreference readPreference = new ReadPreferenceParser(connectionString, config).readPreference();
if (readPreference != null) {
options.readPreference(readPreference);
}
// Heartbeat SocketSettings
JsonObject hbConfig = config.getJsonObject("heartbeat.socket");
if (hbConfig != null) {
SocketSettings heartBeatSocketSettings = new SocketSettingsParser(null, hbConfig).settings();
options.heartbeatSocketSettings(heartBeatSocketSettings);
}
// ServerSettings
ServerSettings serverSettings = new ServerSettingsParser(config).settings();
options.serverSettings(serverSettings);
this.settings = options.build();
}
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:61,代码来源:MongoClientOptionsParser.java
示例9: settings
import com.mongodb.async.client.MongoClientSettings; //导入依赖的package包/类
public MongoClientSettings settings() {
return settings;
}
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:4,代码来源:MongoClientOptionsParser.java
示例10: configure
import com.mongodb.async.client.MongoClientSettings; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
/** connection string */
ConnectionString cstr = Try.apply(() -> new ConnectionString(db))
.orElseGet(() -> new ConnectionString(conf.getString(db)));
log.debug("Starting {}", cstr);
boolean first = instances.getAndIncrement() == 0;
Throwing.Function3<Class, String, Object, Void> bind = (type, name, value) -> {
binder.bind(Key.get(type, Names.named(name))).toInstance(value);
if (first) {
binder.bind(Key.get(type)).toInstance(value);
}
return null;
};
/** settings */
MongoClientSettings.Builder settings = settings(cstr, dbconf(db, conf));
if (configurer != null) {
configurer.accept(settings, conf);
}
MongoClient client = MongoClients.create(settings.build());
bind.apply(MongoClient.class, db, client);
/** bind database */
Optional.ofNullable(cstr.getDatabase()).ifPresent(dbname -> {
// observable adapter
MongoDatabase predb = adapter
.map(a -> client.getDatabase(dbname).withObservableAdapter(a))
.orElseGet(() -> client.getDatabase(dbname));
// codec registry
MongoDatabase database = codecRegistry
.map(predb::withCodecRegistry)
.orElse(predb);
bind.apply(MongoDatabase.class, dbname, database);
/** bind collection */
Optional.ofNullable(cstr.getCollection()).ifPresent(cname -> {
MongoCollection<Document> collection = database.getCollection(cname);
bind.apply(MongoCollection.class, cname, collection);
});
});
/** mapper */
env.router()
.map(mapper());
log.info("Started {}", cstr);
env.onStop(() -> {
log.debug("Stopping {}", cstr);
client.close();
log.info("Stopped {}", cstr);
});
}
开发者ID:jooby-project,项目名称:jooby,代码行数:59,代码来源:MongoRx.java
示例11: connect
import com.mongodb.async.client.MongoClientSettings; //导入依赖的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
示例12: getSettings
import com.mongodb.async.client.MongoClientSettings; //导入依赖的package包/类
/**
* Gets the settings that this client uses to connect to server.
*
* <p>Note: {@link MongoClientSettings} is immutable.</p>
*
* @return the settings
*/
MongoClientSettings getSettings();
开发者ID:mongodb,项目名称:mongo-java-driver-rx,代码行数:9,代码来源:MongoClient.java
示例13: create
import com.mongodb.async.client.MongoClientSettings; //导入依赖的package包/类
/**
* 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());
}
开发者ID:mongodb,项目名称:mongo-java-driver-rx,代码行数:10,代码来源:MongoClients.java
示例14: create
import com.mongodb.async.client.MongoClientSettings; //导入依赖的package包/类
/**
* 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, null);
}
开发者ID:mongodb,项目名称:mongo-java-driver-reactivestreams,代码行数:10,代码来源:MongoClients.java
示例15: doWith
import com.mongodb.async.client.MongoClientSettings; //导入依赖的package包/类
/**
* Allow further configuration on the {@link MongoClientSettings}.
*
* @param configurer Configurer callback.
* @return This module.
*/
public MongoRx doWith(final BiConsumer<MongoClientSettings.Builder, Config> configurer) {
this.configurer = requireNonNull(configurer, "Configurer is required.");
return this;
}
开发者ID:jooby-project,项目名称:jooby,代码行数:11,代码来源:MongoRx.java
注:本文中的com.mongodb.async.client.MongoClientSettings类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论