Package com.mongodb

Examples of com.mongodb.ServerAddress


        System.out.println("user: " + user);
        System.out.println("database: " + databaseName);

        System.out.println();

        MongoClient mongoClient = new MongoClient(new ServerAddress(server),
                                                  asList(MongoCredential.createGSSAPICredential(user)
                                                                        .withMechanismProperty("SERVICE_NAME", "mongodb")),
                                                  new MongoClientOptions.Builder().socketKeepAlive(true).socketTimeout(30000).build());
        DB testDB = mongoClient.getDB(databaseName);
View Full Code Here


        System.out.println("server: " + server);
        System.out.println("user: " + user);

        System.out.println();

        MongoClient mongoClient = new MongoClient(new ServerAddress(server),
                                                  Arrays.asList(MongoCredential.createMongoX509Credential(user)),
                                                  new MongoClientOptions.Builder().socketFactory(SSLSocketFactory.getDefault()).build());
        DB testDB = mongoClient.getDB("test");

        System.out.println("Count: " + testDB.getCollection("test").count());
View Full Code Here

        System.out.println("user: " + user);
        System.out.println("source: " + source);

        System.out.println();

        MongoClient mongoClient = new MongoClient(new ServerAddress(server),
                                                  Arrays.asList(MongoCredential.createPlainCredential(user, source,
                                                                                                      password.toCharArray())),
                                                  new MongoClientOptions.Builder().build());
        DB testDB = mongoClient.getDB("test");
View Full Code Here

        System.out.println("user: " + user);
        System.out.println("source: " + source);

        System.out.println();

        MongoClient mongoClient = new MongoClient(new ServerAddress(server),
                                                  Arrays.asList(MongoCredential.createScramSha1Credential(user, source,
                                                                                                      password.toCharArray())),
                                                  new MongoClientOptions.Builder().build());
        DB testDB = mongoClient.getDB("test");
View Full Code Here

        options.safe = safe;
        options.connectTimeout = timeout;
        log.useSafe( safe );
        log.connectingToMongo( host, port, timeout );

        ServerAddress serverAddress = new ServerAddress( host, port );

        this.mongo = new Mongo( serverAddress, options );
        this.isCacheStarted = true;
      }
      catch ( UnknownHostException e ) {
View Full Code Here

            }
        }
        List<ServerAddress> addrs = new ArrayList<ServerAddress>(ha.length);
        for (int i = 0; i < len; ++i) {
            try {
                addrs.add(new ServerAddress(ha[i], Integer.parseInt(pa[i])));
            } catch (Exception e) {
                error(e, "Error creating mongo connection to %s:%s", host, port);
            }
        }
        if (addrs.isEmpty()) {
View Full Code Here

            int port = 27017;
            if (hp.length > 1) {
                port = Integer.parseInt(hp[1]);
            }
            try {
                addrs.add(new ServerAddress(host, port));
            } catch (UnknownHostException e) {
                error(e, "error creating mongo connection to %s:%s", host, port);
            }
        }
        if (addrs.isEmpty()) {
View Full Code Here

    private MongoClient createClient(final String databaseUri,
        final int port) throws UnknownHostException {
      final MongoClientOptions options = MongoClientOptions.builder()
          .connectionsPerHost(100)
          .threadsAllowedToBlockForConnectionMultiplier(1500).build();
      final MongoClient client = new MongoClient(new ServerAddress(
          databaseUri, port), options);
      return client;
    }
View Full Code Here

    if(StrUtil.isBlank(tmpHost)) {
      throw new NotInitedException("Host name is empy of group: " + group);
    }
   
    final int defaultPort = setting.getInt("port", group, 27017);
    return new ServerAddress(NetUtil.buildInetSocketAddress(tmpHost, defaultPort));
  }
View Full Code Here

   * @param port 端口(如果为空默认为)
   * @return ServerAddress
   */
  private ServerAddress createServerAddress(String host, int port) {
    try {
      return new ServerAddress(host, port);
    } catch (UnknownHostException e) {
      throw new UtilException(StrUtil.format("Unknow Host: [{}]", host), e);
    }
  }
View Full Code Here

TOP

Related Classes of com.mongodb.ServerAddress

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.