Package com.mongodb

Examples of com.mongodb.ServerAddress


            if (node.isConfig) {
                ((Menu)getBoundUnit(Item.replica)).enabled = false;
            }
           
            MongoClient svrMongo = node.getServerMongoClient();
            ServerAddress addr = getServerNode().getServerAddress();
            if (addr != null) {
                setStringFieldValue(Item.host, addr.toString());
                setStringFieldValue(Item.address, addr.getSocketAddress().toString());
            }

            CommandResult res = svrMongo.getDB("local").command("isMaster");
            boolean master = res.getBoolean("ismaster");
            String replication = MongoUtils.makeInfoString("master", master,
View Full Code Here


    }

    @Override
    protected void updateComponentCustom(JPanel comp) {
        try {
            ServerAddress addr = getRouterNode().getAddress();
            setStringFieldValue(Item.host, addr.getHost() + ":" + addr.getPort());
            setStringFieldValue(Item.address, addr.getSocketAddress().toString());
            ((DocField) getBoundUnit(Item.shards)).setDoc(((RouterNode)node).shards);
        } catch (Exception e) {
            UMongo.instance.showError(this.getClass().getSimpleName() + " update", e);
        }
    }
View Full Code Here

            server = tokens[0];
            String shard = tokens[1];
            if (primaryShard == null) {
                primaryShard = shard;
            }
            ServerAddress addr = new ServerAddress(server);

            // filter out if replset already exists
            for (MongoClient replset : mongoToShard.keySet()) {
                if (replset.getServerAddressList().contains(addr)) {
                    continue sLoop;
View Full Code Here

                String[] serverList = servers.split(",");
                ArrayList<ServerAddress> addrs = new ArrayList<ServerAddress>();
                for (String server : serverList) {
                    String[] tmp = server.split(":");
                    if (tmp.length > 1) {
                        addrs.add(new ServerAddress(tmp[0], Integer.valueOf(tmp[1]).intValue()));
                    } else {
                        addrs.add(new ServerAddress(tmp[0]));
                    }
                }
                if ("Direct".equals(dialog.getStringFieldValue(ConnectDialog.Item.connectionMode)))
                    mongo = new MongoClient(addrs.get(0), dialog.getMongoClientOptions());
                else
View Full Code Here

     * @throws Exception If an error occurred while trying to connect.
     */
    public MongoConnection(String host, int port, String database) throws Exception {
        MongoClientOptions options = new MongoClientOptions.Builder().
                threadsAllowedToBlockForConnectionMultiplier(100).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

            if (addressList == null) {
              addressList = Sets.newHashSet();
              chunksMapping.put(chunkId, addressList);
            }
            for (String host : hosts) {
              addressList.add(new ServerAddress(host));
            }
            ServerAddress address = addressList.iterator().next();

            List<ChunkInfo> chunkList = chunksInverseMapping.get(address
                .getHost());
            if (chunkList == null) {
              chunkList = Lists.newArrayList();
              chunksInverseMapping.put(address.getHost(), chunkList);
            }
            ChunkInfo chunkInfo = new ChunkInfo(Arrays.asList(hosts), chunkId);
            DBObject minObj = (BasicDBObject) chunkObj.get(MIN);

            Map<String, Object> minFilters = Maps.newHashMap();
            Map minMap = minObj.toMap();
            Set keySet = minMap.keySet();
            for (Object keyObj : keySet) {
              Object object = minMap.get(keyObj);
              if (!(object instanceof MinKey)) {
                minFilters.put(keyObj.toString(), object);
              }
            }
            chunkInfo.setMinFilters(minFilters);

            DBObject maxObj = (BasicDBObject) chunkObj.get(MAX);
            Map<String, Object> maxFilters = Maps.newHashMap();
            Map maxMap = maxObj.toMap();
            keySet = maxMap.keySet();
            for (Object keyObj : keySet) {
              Object object = maxMap.get(keyObj);
              if (!(object instanceof MaxKey)) {
                maxFilters.put(keyObj.toString(), object);
              }
            }

            chunkInfo.setMaxFilters(maxFilters);
            chunkList.add(chunkInfo);
          }
        }
      } else {
        String chunkName = scanSpec.getDbName() + "."
            + scanSpec.getCollectionName();
        List<String> hosts = clientURI.getHosts();
        Set<ServerAddress> addressList = Sets.newHashSet();

        for (String host : hosts) {
          addressList.add(new ServerAddress(host));
        }
        chunksMapping.put(chunkName, addressList);

        String host = hosts.get(0);
        ServerAddress address = new ServerAddress(host);
        ChunkInfo chunkInfo = new ChunkInfo(hosts, chunkName);
        chunkInfo.setMinFilters(Collections.<String, Object> emptyMap());
        chunkInfo.setMaxFilters(Collections.<String, Object> emptyMap());
        List<ChunkInfo> chunksList = Lists.newArrayList();
        chunksList.add(chunkInfo);
        chunksInverseMapping.put(address.getHost(), chunksList);
      }
    } catch (UnknownHostException e) {
      throw new DrillRuntimeException(e.getMessage(), e);
    } finally {
      if (client != null) {
View Full Code Here

        this.storagePluginConfig.getConnection());
    try {
      List<String> hosts = clientURI.getHosts();
      List<ServerAddress> addresses = Lists.newArrayList();
      for (String host : hosts) {
        addresses.add(new ServerAddress(host));
      }
      MongoClient client = MongoCnxnManager.getClient(addresses,
          clientURI.getOptions());
      DB db = client.getDB(scanSpec.getDbName());
      db.setReadPreference(ReadPreference.nearest());
View Full Code Here

  public synchronized static MongoClient getClient(
      List<ServerAddress> addresses, MongoClientOptions clientOptions)
      throws UnknownHostException {
    // Take the first replica from the replicated servers
    ServerAddress serverAddress = addresses.get(0);
    MongoClient client = addressClientMap.getIfPresent(serverAddress);
    if (client == null) {
      client = new MongoClient(addresses, clientOptions);
      addressClientMap.put(serverAddress, client);
      logger.debug("Created connection to {}.", serverAddress.toString());
      logger.debug("Number of connections opened are {}.",
          addressClientMap.size());
    }
    return client;
  }
View Full Code Here

    MongoClientURI clientURI = new MongoClientURI(connection);
    List<String> hosts = clientURI.getHosts();
    addresses = Lists.newArrayList();
    for (String host : hosts) {
      addresses.add(new ServerAddress(host));
    }
    options = clientURI.getOptions();

    databases = CacheBuilder //
        .newBuilder() //
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.