Package com.mongodb

Examples of com.mongodb.ServerAddress


    @Before
    public void setUp() throws Exception {
        MemoryBackend memoryBackend = new MemoryBackend();
        writeableServer = new MongoServer(memoryBackend);
        writeClient = new MongoClient(new ServerAddress(writeableServer.bind()));

        mongoServer = new MongoServer(new ReadOnlyProxy(memoryBackend));
        readOnlyClient = new MongoClient(new ServerAddress(mongoServer.bind()));
    }
View Full Code Here


    public void testStopListenting() throws Exception {
        MongoServer server = new MongoServer();
        MongoClient client = null;
        try {
            InetSocketAddress serverAddress = server.bind();
            client = new MongoClient(new ServerAddress(serverAddress));
            // request something
            client.getDB("admin").command("serverStatus").throwOnError();

            server.stopListenting();
View Full Code Here

    @Test(timeout = 10000)
    public void testShutdownNow() {
        MongoServer server = new MongoServer();
        MongoClient client = null;
        InetSocketAddress serverAddress = server.bind();
        client = new MongoClient(new ServerAddress(serverAddress));

        // request something to open a connection
        client.getDB("admin").command("serverStatus").throwOnError();

        server.shutdownNow();
View Full Code Here

    @Test(timeout = 10000)
    public void testShutdownAndRestart() throws Exception {
        MongoServer server = new MongoServer();
        InetSocketAddress serverAddress = server.bind();
        {
            final MongoClient client = new MongoClient(new ServerAddress(serverAddress));

            // request something to open a connection
            client.getDB("admin").command("serverStatus").throwOnError();

            server.shutdownNow();

            try {
                client.getDB("admin").command("serverStatus");
                fail("MongoException expected");
            } catch (MongoException e) {
                // okay
            }

            server.bind(serverAddress);

            client.close();
        }
        {
            // Explicitly reconnect the client.
            // Fails otherwise with mongo-java-driver 2.12.0 unless we would use
            // a Thread.sleep(100) or so.
            final MongoClient client = new MongoClient(new ServerAddress(serverAddress));
            client.getDB("admin").command("serverStatus").throwOnError();
            client.close();
        }
        server.shutdownNow();
    }
View Full Code Here

    @Before
    public void setUp() throws Exception {
        mongoServer = new MongoServer(new MemoryBackend());
        InetSocketAddress serverAddress = mongoServer.bind();
        client = new MongoClient(new ServerAddress(serverAddress));
        db = client.getDB("testdb");
        admin = client.getDB("admin");
        collection = db.getCollection("testcoll");
    }
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

      h.close();
      h = null;
     
      // only one node in replica set ... - use it
      if(addresses.size() == 1) {
        ServerAddress addr = addresses.get(0);
        hosts.add(addr.getHost() + ":" + Integer.toString(addr.getPort()));
      }
     
      else {
        for(ServerAddress addr : addresses) {
         
          // use secondaries and primaries
          if(primaryOk) {
            hosts.add(addr.getHost() + ":" + Integer.toString(addr.getPort()));
          }
         
          // only use secondaries
          else {
            String haddr = addr.getHost() + ":" + Integer.toString(addr.getPort());
            h = new Mongo(haddr);
            if(!(Boolean)h.getDB(h.getDatabaseNames().get(0)).command(cmd).get("ismaster")) {
              hosts.add(haddr);
            }
          }
View Full Code Here

    protected void updateComponentCustom(JPanel old) {
        try {
            MongoClient mongo = getMongoNode().getMongoClient();
            setStringFieldValue(Item.version, mongo.getVersion());

            ServerAddress master = mongo.getAddress();
            if (master != null) {
                setStringFieldValue(Item.masterServer, getServerAddressString(master));
            }
            List<ServerAddress> addrs = mongo.getAllAddress();
            String html = "<html>";
View Full Code Here

    }
   
    public ServerNode(String host, MongoClientOptions opts, boolean isReplica, boolean isConfig) throws UnknownHostException {
        setLabel(host);
        this.host = host;
        this.serverAddress = new ServerAddress(host);
        serverMongo = new MongoClient(serverAddress, opts);
        serverMongo.addOption( Bytes.QUERYOPTION_SLAVEOK );
        this.isReplica = isReplica;
        this.isConfig = isConfig;
       
View Full Code Here

                String[] hostList = hosts.split(",");
                ArrayList<ServerAddress> addrs = new ArrayList<ServerAddress>();
                for (String host : hostList) {
                    int colon = host.indexOf(':');
                    if (colon >= 0) {
                        addrs.add(new ServerAddress(host.substring(0, colon), Integer.parseInt(host.substring(colon + 1))));
                    } else {
                        addrs.add(new ServerAddress(host));
                    }
                }

                if (repl != null || addrs.size() > 1) {
                    addChild(new ReplSetNode(repl, addrs, mongo.getMongoClientOptions(), shardName));
                } else {
                    addChild(new ServerNode(addrs.get(0), mongo.getMongoClientOptions(), false, false));
                }
            } catch (Exception e) {
                getLogger().log(Level.WARNING, null, e);
            }
        }

        // add config servers
        try {
            res = mongo.getDB("admin").command("getCmdLineOpts");
            String configStr = (String) ((BasicDBObject) res.get("parsed")).get("configdb");
            String[] configsvrs = configStr.split(",");
            for (String host : configsvrs) {
                int colon = host.indexOf(':');
                ServerAddress addr;
                if (colon >= 0) {
                    addr = new ServerAddress(host.substring(0, colon), Integer.parseInt(host.substring(colon + 1)));
                } else {
                    addr = new ServerAddress(host);
                }
                addChild(new ServerNode(addr, mongo.getMongoClientOptions(), false, true));
            }
        } catch (Exception e) {
            getLogger().log(Level.WARNING, null, 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.