当前位置: 首页>>代码示例>>Java>>正文


Java MongoClientURI.getHosts方法代码示例

本文整理汇总了Java中com.mongodb.MongoClientURI.getHosts方法的典型用法代码示例。如果您正苦于以下问题:Java MongoClientURI.getHosts方法的具体用法?Java MongoClientURI.getHosts怎么用?Java MongoClientURI.getHosts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.MongoClientURI的用法示例。


在下文中一共展示了MongoClientURI.getHosts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createUser

import com.mongodb.MongoClientURI; //导入方法依赖的package包/类
public static void createUser() throws IOException, InterruptedException {
    String mongoHost = MultiValueConfigLoader.getConfig("MONGODB-integrationTest");
    log.info("Host is " + mongoHost);
    if (mongoHost != null) {
        MongoClientURI uri = new MongoClientURI(mongoHost);
        List<String> hosts = uri.getHosts();
        for (String host : hosts) {
            String[] cmdarray = createSetupCommand(host, uri.getDatabase(), uri.getUsername(), new String(uri.getPassword()));
            Process process = Runtime.getRuntime().exec(cmdarray);
            int retVal = process.waitFor();
            log.info(String.format("retVal=%s", retVal));
            log.info("output is " + IOUtils.toString(process.getInputStream()));
            if (retVal != 0) {
                log.info("error is " + IOUtils.toString(process.getErrorStream()));
            }
        }
    } else {
        log.error("mongo host is not defined!");
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:21,代码来源:LocalTestSetup.java

示例2: extractServerAddresses

import com.mongodb.MongoClientURI; //导入方法依赖的package包/类
private ServerAddress[] extractServerAddresses(MongoClientURI mongoClientURI) {
    final List<String> hosts = mongoClientURI.getHosts();
    final List<ServerAddress> serverAddresses = new ArrayList<>(hosts.size());
    for (String host : hosts) {
        final HostAndPort hostAndPort = HostAndPort.fromString(host).withDefaultPort(ServerAddress.defaultPort());
        final ServerAddress serverAddress = new ServerAddress(hostAndPort.getHostText(), hostAndPort.getPort());
        serverAddresses.add(serverAddress);
    }
    return serverAddresses.toArray(new ServerAddress[serverAddresses.size()]);
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:11,代码来源:MongoDBReporterProvider.java

示例3: validateMongoClientURI

import com.mongodb.MongoClientURI; //导入方法依赖的package包/类
/**
 * Validates MongoClientURI 
 * @param mongoClientURI {MongoClientURI} must not be null and contain valid host and (optional) port. 
 */
private void validateMongoClientURI(MongoClientURI mongoClientURI)
{
    // 1. Argument not optional
    if (null== mongoClientURI)
    {
        throw new IllegalArgumentException("'mongoClientURI' argument may not be null.");
    }
    
    // 2.  Validate host
    for(String host : mongoClientURI.getHosts())
    {
        // ensure not null or empty or just whitespace chars
        if ( null != host && host.trim().length() > 0)
        {
            try
            {
                // create a URI from the host name - may throw URISyntaxException
                URI uri = new URI("my://" + host); 
                
                // get host without port from URI
                host = uri.getHost();

                if (null == host || host.trim().length() == 0 )
                {
                    throw new IllegalArgumentException("'mongoClientURI' argument must contain a valid host: " + mongoClientURI);
                }
            }
            catch (URISyntaxException ex)
            {
                // validation failed due to malformed host
                throw new IllegalArgumentException("'mongoClientURI' argument must contain a valid host: " + mongoClientURI);
            }
        }
        else
        {
            throw new IllegalArgumentException("'mongoClientURI' argument: host is mandatory: " + mongoClientURI);
        }
    }
}
 
开发者ID:AlfrescoBenchmark,项目名称:alfresco-benchmark,代码行数:44,代码来源:MongoClientFactory.java


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