Package com.mongodb

Examples of com.mongodb.ServerAddress


    String[] replicaSetStringArray = StringUtils.commaDelimitedListToStringArray(replicaSetString);
    Set<ServerAddress> serverAddresses = new HashSet<ServerAddress>(replicaSetStringArray.length);

    for (String element : replicaSetStringArray) {

      ServerAddress address = parseServerAddress(element);

      if (address != null) {
        serverAddresses.add(address);
      }
    }
View Full Code Here


    try {
      InetAddress hostAddress = InetAddress.getByName(hostAndPort[0]);
      Integer port = hostAndPort.length == 1 ? null : Integer.parseInt(hostAndPort[1]);

      return port == null ? new ServerAddress(hostAddress) : new ServerAddress(hostAddress, port);
    } catch (UnknownHostException e) {
      LOG.warn(COULD_NOT_PARSE_ADDRESS_MESSAGE, "host", hostAndPort[0]);
    } catch (NumberFormatException e) {
      LOG.warn(COULD_NOT_PARSE_ADDRESS_MESSAGE, "port", hostAndPort[1]);
    }
View Full Code Here

  @Override
  public void start() {
    if ( mongo == null ) {
      try {
        ServerAddress serverAddress = new ServerAddress( config.getHost(), config.getPort() );
        MongoClientOptions clientOptions = config.buildOptions();

        log.connectingToMongo( config.getHost(), config.getPort(), clientOptions.getConnectTimeout() );

        this.mongo = new MongoClient( serverAddress, clientOptions );
View Full Code Here

            for (String serverAuthority : StringUtils.split(_serverAuthorities, ',')) {
                String[] serverAuthorityParts = StringUtils.split(StringUtils.trimToEmpty(serverAuthority), ":");

                if (serverAuthorityParts.length == 1) {
                    serverAddressList.add(new ServerAddress(serverAuthorityParts[0]));
                } else {
                    serverAddressList.add(new ServerAddress(serverAuthorityParts[0], Integer.parseInt(serverAuthorityParts[1])));
                }
            }

            if (_sLog.isInfoEnabled()) {
                _sLog.info("Initializing mongoDB '" + _databaseName + "' with servers: " + serverAddressList);
View Full Code Here

  @Override
  public void start() {
    if ( mongo == null ) {
      try {
        ServerAddress serverAddress = new ServerAddress( config.getHost(), config.getPort() );
        MongoClientOptions clientOptions = config.buildOptions();

        log.connectingToMongo( config.getHost(), config.getPort(), clientOptions.getConnectTimeout() );

        this.mongo = new MongoClient( serverAddress, clientOptions );
View Full Code Here

  @Override
  public void start() {
    if ( !isCacheStarted ) {
      try {
        ServerAddress serverAddress = new ServerAddress( config.getHost(), config.getPort() );
        MongoClientOptions clientOptions = config.buildOptions();

        log.connectingToMongo( config.getHost(), config.getPort(), clientOptions.getConnectTimeout() );

        this.mongo = new MongoClient( serverAddress, clientOptions );
View Full Code Here

    // (this could mean a real server is running on our port)

    mockMongo = new MockMongo();

    try {
      new DBPort(new ServerAddress("0.0.0.0", mockMongo.getPort()))
          .ensureOpen();
      fail("something is already listening at the Mongo port! Is a real mongo process running?");
    } catch (IOException e) {
    }
    mockMongo.start();
View Full Code Here

        List<MongoCredential> credentials = null;
        if (this.password != null && this.username != null) {
          credentials = Arrays.asList(MongoCredential.createMongoCRCredential(
              this.username, getMongoClientDatabase(), this.password));
        }
        return new MongoClient(Arrays.asList(new ServerAddress(this.host,
            this.port)), credentials, options);
      }
      // The options and credentials are in the URI
      return new MongoClient(new MongoClientURI(this.uri, builder(options)));
    }
View Full Code Here

    public static void main(String[] args) throws UnknownHostException {
        final Configuration configuration = new Configuration();
        configuration.setClassForTemplateLoading(
                Week1Homework4.class, "/");

        MongoClient client = new MongoClient(new ServerAddress("localhost", 27017));

        DB database = client.getDB("m101");
        final DBCollection collection = database.getCollection("funnynumbers");

        Spark.get(new Route("/") {
View Full Code Here

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

        System.out.println();

        MongoClient mongoClient = new MongoClient(new ServerAddress(server),
                                                  asList(MongoCredential.createMongoCRCredential(user,
                                                                                                 "test",
                                                                                                 password.toCharArray())),
                                                  new MongoClientOptions.Builder().socketKeepAlive(true).socketTimeout(30000).build());
        DB testDB = mongoClient.getDB(databaseName);
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.