Package com.mongodb

Examples of com.mongodb.MongoClientURI


        int changesSize = PropertiesUtil.toInteger(prop(PROP_CHANGES_SIZE), DEFAULT_CHANGES_SIZE);
        boolean useMK = PropertiesUtil.toBoolean(context.getProperties().get(PROP_USE_MK), false);


        MongoClientOptions.Builder builder = MongoConnection.getDefaultBuilder();
        MongoClientURI mongoURI = new MongoClientURI(uri, builder);

        if (log.isInfoEnabled()) {
            // Take care around not logging the uri directly as it
            // might contain passwords
            String type = useMK ? "MK" : "NodeStore";
            log.info("Starting Document{} with host={}, db={}, cache size (MB)={}, Off Heap Cache size (MB)={}, " +
                            "'changes' collection size (MB)={}, maxReplicationLagInSecs={}",
                    type, mongoURI.getHosts(), db, cacheSize, offHeapCache, changesSize, maxReplicationLagInSecs);
            log.info("Mongo Connection details {}", MongoConnection.toString(mongoURI.getOptions()));
        }

        MongoClient client = new MongoClient(mongoURI);
        DB mongoDB = client.getDB(db);
View Full Code Here


    @Override
    protected MongoGraphDatabase createDatabase(Platform platform) throws Exception {
        final IniMongoProperties properties = new IniMongoProperties();
        final String uri = properties.get("mongodb.uri", String.class).or("mongodb://localhost:27017/");
        final String database = properties.get("mongodb.database", String.class).or("geogig");
        MongoClient client = new MongoClient(new MongoClientURI(uri));
        DB db = client.getDB(database);
        db.dropDatabase();

        MongoConnectionManager manager = new MongoConnectionManager();
        ConfigDatabase config = new TestConfigDatabase(platform);
View Full Code Here

public final class MongoConnectionManager extends
        ConnectionManager<MongoAddress, MongoClient> {
    @Override
    protected MongoClient connect(MongoAddress address) {
        try {
            MongoClientURI uri = new MongoClientURI(address.getUri());
            return new MongoClient(uri);
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

    localEStoreProvider = new LocalEStoreProvider();
  }

  @Override
  public void start() throws IOException {
    MongoClientURI clientURI = new MongoClientURI(mongoURL);
    client = new MongoClient(clientURI);
    DB db = client.getDB(clientURI.getDatabase());
    collection = db.getCollection(clientURI.getCollection());
    collection.setWriteConcern(WriteConcern.JOURNALED);
    DBObject index = new BasicDBObject(1).append(pKey, Integer.valueOf(1));
    collection.createIndex(index);
  }
View Full Code Here

  @SuppressWarnings("rawtypes")
  private void init() throws IOException {
    MongoClient client = null;
    try {
      MongoClientURI clientURI = new MongoClientURI(
          this.storagePluginConfig.getConnection());
      client = new MongoClient(clientURI);

      chunksMapping = Maps.newHashMap();
      chunksInverseMapping = Maps.newLinkedHashMap();
      if (isShardedCluster(client)) {
        DB db = client.getDB(CONFIG);
        db.setReadPreference(ReadPreference.nearest());
        DBCollection chunksCollection = db.getCollectionFromString(CHUNKS);

        DBObject query = new BasicDBObject(1);
        query
            .put(
                NS,
                this.scanSpec.getDbName() + "."
                    + this.scanSpec.getCollectionName());

        DBObject fields = new BasicDBObject();
        fields.put(SHARD, select);
        fields.put(MIN, select);
        fields.put(MAX, select);

        DBCursor chunkCursor = chunksCollection.find(query, fields);

        DBCollection shardsCollection = db.getCollectionFromString(SHARDS);

        fields = new BasicDBObject();
        fields.put(HOST, select);

        while (chunkCursor.hasNext()) {
          DBObject chunkObj = chunkCursor.next();
          String shardName = (String) chunkObj.get(SHARD);
          String chunkId = (String) chunkObj.get(ID);
          query = new BasicDBObject().append(ID, shardName);
          DBCursor hostCursor = shardsCollection.find(query, fields);
          while (hostCursor.hasNext()) {
            DBObject hostObj = hostCursor.next();
            String hostEntry = (String) hostObj.get(HOST);
            String[] tagAndHost = StringUtils.split(hostEntry, '/');
            String[] hosts = tagAndHost.length > 1 ? StringUtils.split(
                tagAndHost[1], ',') : StringUtils.split(tagAndHost[0], ',');
            Set<ServerAddress> addressList = chunksMapping.get(chunkId);
            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));
        }
View Full Code Here

    return toString();
  }

  @Override
  public ScanStats getScanStats() {
    MongoClientURI clientURI = new MongoClientURI(
        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());
      DBCollection collection = db.getCollectionFromString(scanSpec
          .getCollectionName());
      CommandResult stats = collection.getStats();
View Full Code Here

    String connection = schema.getConfig().getConnection();

    this.plugin = schema;
    this.schemaName = schemaName;

    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() //
        .expireAfterAccess(1, TimeUnit.MINUTES) //
        .build(new DatabaseLoader());
View Full Code Here

    return this.connection != null ? this.connection.hashCode() : 0;
  }

  @JsonIgnore
  public MongoClientOptions getMongoOptions() {
    MongoClientURI clientURI = new MongoClientURI(connection);
    return clientURI.getOptions();
  }
View Full Code Here

    public Object getObjectInstance(final Object obj,
                                    final Name name,
                                    final Context nameCtx,
                                    final Hashtable<?, ?> environment) throws Exception {
        final MongoClient mongoClient;
        final MongoClientURI clientURI;
        final String uri = (String) environment.get("uri");
        if (uri != null) {
            clientURI = new MongoClientURI(uri);
        } else {
            clientURI = createMongoClientURI((String) environment.get("host"),
                    (String) environment.get("database"),
                    (String) environment.get("collection"),
                    (String) environment.get("options"),
View Full Code Here

        }

        if (options != null) {
            uriVal.append('?').append(options);
        }
        return new MongoClientURI(uriVal.toString());
    }
View Full Code Here

TOP

Related Classes of com.mongodb.MongoClientURI

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.