當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。