Example usage for com.mongodb ServerAddress ServerAddress

List of usage examples for com.mongodb ServerAddress ServerAddress

Introduction

In this page you can find the example usage for com.mongodb ServerAddress ServerAddress.

Prototype

public ServerAddress(@Nullable final String host, final int port) 

Source Link

Document

Creates a ServerAddress

Usage

From source file:it.f2informatica.mongodb.MongoDBReplicaSetApplicationConfig.java

License:Apache License

private List<ServerAddress> replicaSet() throws UnknownHostException {
    return Arrays.asList(new ServerAddress(host, nodeAlpha), new ServerAddress(host, nodeBeta),
            new ServerAddress(host, nodeOmega));
}

From source file:it.wami.map.mongodeploy.OsmToMongoDB.java

License:Apache License

/**
 * //from w w  w.  j  av a  2 s.  c  om
 * @param host
 * @param port
 * @param mco 
 * @return
 */
private static MongoClient createMongo(String host, int port, MongoClientOptions mco) {
    MongoClient mongo = null;
    try {
        mongo = new MongoClient(new ServerAddress(host, port), mco);
        System.out.println(mongo.getConnectPoint());
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return mongo;
}

From source file:joliex.mongodb.MongoDbConnector.java

@RequestResponse
public void connect(Value request) throws FaultException {
    try {/*w  w w.ja v a  2  s .co  m*/
        host = request.getFirstChild("host").strValue();
        port = request.getFirstChild("port").intValue();
        dbname = request.getFirstChild("dbname").strValue();
        timeZone = request.getFirstChild("timeZone").strValue();
        password = request.getFirstChild("password").strValue();
        username = request.getFirstChild("username").strValue();
        log = Logger.getLogger("org.mongodb.driver");
        log.setLevel(Level.OFF);
        if (request.hasChildren("jsonStringDebug")) {
            jsonDebuger = request.getFirstChild("jsonStringDebug").boolValue();
        }
        if (request.hasChildren("logStreamDebug")) {
            logStream = request.getFirstChild("logStreamDebug").boolValue();
            logString = "Processing Steps at " + System.currentTimeMillis();
        }
        if (System.getProperty("os.arch").contains("64")) {
            is64 = true;
        } else {
            is64 = false;
        }

        zone = DateTimeZone.forID(timeZone);

        ServerAddress serverAddress = new ServerAddress(host, port);
        MongoCredential credential = MongoCredential.createCredential(username, dbname, password.toCharArray());
        mongoClientOptions = MongoClientOptions.builder().build();

        if (null != mongoClient) {
            System.out.println("recovering client");
            db = mongoClient.getDatabase(dbname);
        } else {

            mongoClient = new MongoClient(serverAddress, credential, mongoClientOptions);
            db = mongoClient.getDatabase(dbname);
        }

    } catch (MongoException ex) {
        throw new FaultException("LoginConnection", ex);
    }
}

From source file:jp.co.ctc_g.jse.data.mongo.showcase.config.MongoContextConfig.java

License:Apache License

/**
 * MongoDB???????/*  w  w w . j  a  v a  2s  . c om*/
 * @return {@link MongoClient} ?
 */
@Bean
public MongoClient mongo() {
    try {
        return new MongoClient(new ServerAddress(host, port), options());
    } catch (UnknownHostException e) {
        throw new InternalException(MongoContextConfig.class, "E-MONGO-CONFIG#0001",
                Maps.hash("host", host).map("port", Integer.toString(port)), e);
    }
}

From source file:jp.co.ctc_g.jse.data.mongo.showcase.config.MongoShowcaseContextConfig.java

License:Apache License

/**
 * MongoDB???????//from   w ww.  ja  va2  s . c o m
 * @return {@link MongoClient} ?
 */
@Bean
public MongoClient mongo() {
    try {
        return new MongoClient(new ServerAddress(host, port), options());
    } catch (UnknownHostException e) {
        throw new InternalException(MongoShowcaseContextConfig.class, "E-MONGO-CONFIG#0001",
                Maps.hash("host", host).map("port", Integer.toString(port)), e);
    }
}

From source file:jp.co.ctc_g.rack.core.config.RackMongoContextConfig.java

License:Apache License

/**
 * MongoDI????/*w  w  w .j  a v a  2  s.com*/
 * @return Mongo
 * @throws Exception 
 */
@Bean
public Mongo mongo() throws Exception {

    return new Mongo(new ServerAddress(host, port), mongoOptions());
}

From source file:MDBInt.DBMongo.java

License:Apache License

private void connectReplication() {

    MongoCredential credential;//from  www.ja  v  a  2 s  . c o  m
    ArrayList<ServerAddress> lista = new ArrayList();
    List<Element> servers = serverList.getChildren();
    //  System.out.println("dentro connect");
    String ip;
    int porta;
    try {
        for (int s = 0; s < servers.size(); s++) {
            ip = servers.get(s).getChildText("serverUrl");
            porta = Integer.decode(servers.get(s).getChildText("port"));
            //    lista.add(new ServerAddress(servers.get(s).getChildText("serverUrl"),Integer.decode(servers.get(s).getChildText("port"))));
            lista.add(new ServerAddress(ip, porta));
        }

        credential = MongoCredential.createMongoCRCredential(user, dbName, password.toCharArray());
        mongoClient = new MongoClient(lista, Arrays.asList(credential));
        connection = true;
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:me.lucko.luckperms.common.storage.backing.MongoDBBacking.java

License:Open Source License

@Override
public void init() {
    MongoCredential credential = null;/*from   w ww  .ja  va  2s.c om*/

    if (configuration.getUsername() != null && !configuration.getUsername().equals("")
            && configuration.getDatabase() != null && !configuration.getDatabase().equals("")) {
        if (configuration.getPassword() == null || configuration.getPassword().equals("")) {
            credential = MongoCredential.createCredential(configuration.getUsername(),
                    configuration.getDatabase(), null);
        } else {
            credential = MongoCredential.createCredential(configuration.getUsername(),
                    configuration.getDatabase(), configuration.getPassword().toCharArray());
        }
    }

    String[] addressSplit = configuration.getAddress().split(":");
    String host = addressSplit[0];
    int port = addressSplit.length > 1 ? Integer.parseInt(addressSplit[1]) : 27017;
    ServerAddress address = new ServerAddress(host, port);

    if (credential == null) {
        mongoClient = new MongoClient(address, Collections.emptyList());
    } else {
        mongoClient = new MongoClient(address, Collections.singletonList(credential));
    }

    database = mongoClient.getDatabase(configuration.getDatabase());
    setAcceptingLogins(true);
}

From source file:me.lucko.luckperms.common.storage.dao.mongodb.MongoDao.java

License:MIT License

@Override
public void init() {
    MongoCredential credential = null;/*from   www.  jav a 2 s .  co m*/
    if (!Strings.isNullOrEmpty(configuration.getUsername())) {
        credential = MongoCredential.createCredential(configuration.getUsername(), configuration.getDatabase(),
                Strings.isNullOrEmpty(configuration.getPassword()) ? null
                        : configuration.getPassword().toCharArray());
    }

    String[] addressSplit = configuration.getAddress().split(":");
    String host = addressSplit[0];
    int port = addressSplit.length > 1 ? Integer.parseInt(addressSplit[1]) : 27017;
    ServerAddress address = new ServerAddress(host, port);

    if (credential == null) {
        mongoClient = new MongoClient(address, Collections.emptyList());
    } else {
        mongoClient = new MongoClient(address, Collections.singletonList(credential));
    }

    database = mongoClient.getDatabase(configuration.getDatabase());
}

From source file:me.lucko.luckperms.storage.methods.MongoDBDatastore.java

License:Open Source License

@Override
public void init() {
    MongoCredential credential = MongoCredential.createCredential(configuration.getUsername(),
            configuration.getDatabase(), configuration.getPassword().toCharArray());

    ServerAddress address = new ServerAddress(configuration.getAddress().split(":")[0],
            Integer.parseInt(configuration.getAddress().split(":")[1]));

    mongoClient = new MongoClient(address, Collections.singletonList(credential));
    database = mongoClient.getDatabase(configuration.getDatabase());
    setAcceptingLogins(true);//from  www  .  ja v a2  s  .c o  m
}