Package com.mongodb

Examples of com.mongodb.ServerAddress


  @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


        final List<ServerAddress> replicaServers = new ArrayList<>(mongoReplicaSet.size());
        for (String host : mongoReplicaSet) {
            try {
                final HostAndPort hostAndPort = HostAndPort.fromString(host)
                        .withDefaultPort(27017);
                replicaServers.add(new ServerAddress(
                        InetAddress.getByName(hostAndPort.getHostText()), hostAndPort.getPort()));
            } catch (IllegalArgumentException e) {
                LOG.error("Malformed mongodb_replica_set configuration.", e);
                return null;
            } catch (UnknownHostException e) {
View Full Code Here

                // Connect to replica servers if given. Else the standard way to one server.
                if (replicaServers != null && replicaServers.size() > 0) {
                    m = new MongoClient(replicaServers, options.build());
                } else {
                    ServerAddress address = new ServerAddress(host, port);
                    m = new MongoClient(address, options.build());
                }
                db = m.getDB(database);
                db.setWriteConcern(WriteConcern.SAFE);
View Full Code Here

            try {
                int colonPos = part.indexOf(":");
                if (colonPos > 0 && (colonPos < part.length() - 1)) {
                    String name = part.substring(0, colonPos);
                    String portStr = part.substring(colonPos + 1);
                    servers.add(new ServerAddress(name, Integer.valueOf(portStr)));
                }
            }
            catch (NumberFormatException e) {
                throw new IllegalArgumentException("Illegal port number in: " + part);
            }
View Full Code Here

     * @param database The database name.
     * @throws Exception If an error occurred while trying to connect.
     */
    public MongoConnection(String host, int port, String database) throws Exception {
        MongoClientOptions options = getDefaultBuilder().build();
        ServerAddress serverAddress = new ServerAddress(host, port);
        mongo = new MongoClient(serverAddress, options);
        db = mongo.getDB(database);
    }
View Full Code Here

  @Override
  public void start() {
    if ( !isCacheStarted ) {
      try {
        ServerAddress serverAddress = new ServerAddress( config.getHost(), config.getPort() );
        this.mongo = new MongoClient( serverAddress, config.buildOptions() );
        this.isCacheStarted = true;
      }
      catch ( UnknownHostException e ) {
        throw log.mongoOnUnknownHost( config.getHost() );
View Full Code Here

                    String host = connectionSpec.getHosts().get(index);
                    int port = ServerAddress.defaultPort();
                    if (connectionSpec.getPorts().size() > index) {
                        port = connectionSpec.getPorts().get(index);
                    }
                    ServerAddress server = new ServerAddress(host, port);
                    servers.add(server);
                }
                if (connectionSpec.getHosts().isEmpty()) {
                    ServerAddress server = new ServerAddress("localhost", ServerAddress.defaultPort());
                    servers.add(server);                   
                }
                Mongo mongo = this.mongo;
                if (mongo == null) {
                    isExternal = false;
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

            int port = DEFAULT_PORT;
            String[] hostPort = connection.split(":");
            if(hostPort.length > 1 && !StringUtils.isEmpty(hostPort[1])) {
                port = Integer.parseInt(hostPort[1].trim());
            }
            addresses.add(new ServerAddress(hostPort[0], port));
        }
        return addresses;
    }
View Full Code Here

    private Mongo getMongo() throws UnknownHostException {
        if (null != __mongo) {
            return __mongo;
        }
        //-- creates new mongo --//
        final ServerAddress address = new ServerAddress(_host, _port);
        __mongo = new Mongo(address);
        return __mongo;
    }
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.