Package com.mongodb

Examples of com.mongodb.ServerAddress


        Mongo mongo;
        if(host.contains(",")) {
            String[] hosts = host.split(",");
            List<ServerAddress> addresses = new ArrayList<ServerAddress>();
            for (String hostUrl : hosts) {
                ServerAddress serverAddress;
                if(hostUrl.contains(":")) {
                    String[] hostUrlParts = hostUrl.split(":");
                    port = Integer.parseInt(hostUrlParts[1]);
                    serverAddress = new ServerAddress(hostUrlParts[0], port);
                } else {
                    serverAddress = new ServerAddress(hostUrl);
                }
               
                addresses.add(serverAddress);
            }
           
            mongo = new Mongo(addresses, mongoOptions);
        } else {
            mongo = new Mongo(new ServerAddress(host, port), mongoOptions);
        }
        return mongo;
    }
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

                int i = 0;
                for (String host : hosts)
                {
                    int portNum = (onePort) ? portNums.get(0) : portNums.get(i);
                    try {
                        addresses.add(new ServerAddress(host.trim(), portNum));
                    }
                    catch (UnknownHostException e)
                    {
                        errorHandler.error("MongoDB appender hostname property contains unknown host", e,
                                ErrorCode.ADDRESS_PARSE_FAILURE);
View Full Code Here

    protected Mongo openConnection()
        throws MojoFailureException,
        UnknownHostException {

        // get server address
        ServerAddress serverAddr = (dbConnectionSettings.getPort()!=null)
          ? new ServerAddress(dbConnectionSettings.getHostname(), dbConnectionSettings.getPort().intValue())
          : new ServerAddress(dbConnectionSettings.getHostname());

        // get Mongo
        Mongo mongo = (dbConnectionSettings.getOptions()!=null)
        ? new Mongo(serverAddr, dbConnectionSettings.getOptions())
        : new Mongo(serverAddr);
View Full Code Here

import java.util.Arrays;

public class WriteConcernTest {
    public static void main(String[] args) throws UnknownHostException, InterruptedException {
        MongoClient client = new MongoClient(Arrays.asList(
                new ServerAddress("localhost", 27017),
                new ServerAddress("localhost", 27018),
                new ServerAddress("localhost", 27019)));

        client.setWriteConcern(WriteConcern.JOURNALED);

        DB db = client.getDB("course");
        db.setWriteConcern(WriteConcern.JOURNALED);
View Full Code Here

import java.util.Arrays;

public class ReplicaSetFailoverTest {
    public static void main(String[] args) throws UnknownHostException, InterruptedException {
        MongoClient client = new MongoClient(Arrays.asList(
                new ServerAddress("localhost", 27017),
                new ServerAddress("localhost", 27018),
                new ServerAddress("localhost", 27019)));

        DBCollection test = client.getDB("course").getCollection("replica.test");
        test.drop();

        for (int i = 0; i < Integer.MAX_VALUE; i++) {
View Full Code Here

public class ReplicaSetTest {

    public static void main(String[] args) throws UnknownHostException, InterruptedException {
        MongoClient client = new MongoClient(Arrays.asList(
                new ServerAddress("localhost", 27017),
                new ServerAddress("localhost", 27018),
                new ServerAddress("localhost", 27019)));

        DBCollection test = client.getDB("course").getCollection("replica.test");
        test.drop();

        for (int i = 0; i < Integer.MAX_VALUE; i++) {
View Full Code Here

import java.util.Arrays;

public class ReadPreferenceTest {
    public static void main(String[] args) throws UnknownHostException, InterruptedException {
        MongoClient client = new MongoClient(Arrays.asList(
                new ServerAddress("localhost", 27017),
                new ServerAddress("localhost", 27018),
                new ServerAddress("localhost", 27019)));
        client.setReadPreference(ReadPreference.primary());

        DB db = client.getDB("course");
        db.setReadPreference(ReadPreference.primary());
        DBCollection coll = db.getCollection("write.test");
View Full Code Here

import java.net.UnknownHostException;

public class HelloWorldMongoDBStyle {
    public static void main(String[] args) throws UnknownHostException {
        MongoClient client =
                new MongoClient(new ServerAddress("localhost", 27017));

        DB database = client.getDB("course");
        DBCollection collection = database.getCollection("hello");

        DBObject document = collection.findOne();
View Full Code Here

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

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

        DB database = client.getDB("course");
        final DBCollection collection = database.getCollection("hello");

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.