Package com.mongodb

Examples of com.mongodb.ServerAddress


  private void init(MongoSubScan.MongoSubScanSpec subScanSpec) {
    try {
      List<String> hosts = subScanSpec.getHosts();
      List<ServerAddress> addresses = Lists.newArrayList();
      for (String host : hosts) {
        addresses.add(new ServerAddress(host));
      }
      MongoClient client = MongoCnxnManager.getClient(addresses, clientOptions);
      DB db = client.getDB(subScanSpec.getDbName());
      db.setReadPreference(ReadPreference.nearest());
      collection = db.getCollection(subScanSpec.getCollectionName());
View Full Code Here


    chunksMapping = Maps.newHashMap();
    chunksInverseMapping = Maps.newLinkedHashMap();

    // entry1
    Set<ServerAddress> hosts_A = Sets.newHashSet();
    hosts_A.add(new ServerAddress(HOST_A));
    chunksMapping.put(dbName + "." + collectionName + "-01", hosts_A);
    chunksMapping.put(dbName + "." + collectionName + "-05", hosts_A);

    ChunkInfo chunk1Info = new ChunkInfo(Arrays.asList(HOST_A), dbName + "."
        + collectionName + "-01");
    chunk1Info.setMinFilters(Collections.<String, Object> emptyMap());
    Map<String, Object> chunk1MaxFilters = Maps.newHashMap();
    chunk1MaxFilters.put("name", Integer.valueOf(5));
    chunk1Info.setMaxFilters(chunk1MaxFilters);

    ChunkInfo chunk5Info = new ChunkInfo(Arrays.asList(HOST_A), dbName + "."
        + collectionName + "-05");
    Map<String, Object> chunk5MinFilters = Maps.newHashMap();
    chunk5MinFilters.put("name", Integer.valueOf(25));
    chunk5Info.setMinFilters(chunk5MinFilters);
    Map<String, Object> chunk5MaxFilters = Maps.newHashMap();
    chunk5MaxFilters.put("name", Integer.valueOf(30));
    chunk5Info.setMaxFilters(chunk5MaxFilters);
    List<ChunkInfo> chunkList = Arrays.asList(chunk1Info, chunk5Info);
    chunksInverseMapping.put(HOST_A, chunkList);

    // entry2
    Set<ServerAddress> hosts_B = Sets.newHashSet();
    hosts_A.add(new ServerAddress(HOST_B));
    chunksMapping.put(dbName + "." + collectionName + "-02", hosts_B);

    ChunkInfo chunk2Info = new ChunkInfo(Arrays.asList(HOST_B), dbName + "."
        + collectionName + "-02");
    Map<String, Object> chunk2MinFilters = Maps.newHashMap();
    chunk2MinFilters.put("name", Integer.valueOf(5));
    chunk2Info.setMinFilters(chunk2MinFilters);
    Map<String, Object> chunk2MaxFilters = Maps.newHashMap();
    chunk2MaxFilters.put("name", Integer.valueOf(15));
    chunk2Info.setMaxFilters(chunk2MaxFilters);
    chunkList = Arrays.asList(chunk2Info);
    chunksInverseMapping.put(HOST_B, chunkList);

    // enty3
    Set<ServerAddress> hosts_C = Sets.newHashSet();
    hosts_A.add(new ServerAddress(HOST_C));
    chunksMapping.put(dbName + "." + collectionName + "-03", hosts_C);
    chunksMapping.put(dbName + "." + collectionName + "-06", hosts_C);

    ChunkInfo chunk3Info = new ChunkInfo(Arrays.asList(HOST_C), dbName + "."
        + collectionName + "-03");
    Map<String, Object> chunk3MinFilters = Maps.newHashMap();
    chunk5MinFilters.put("name", Integer.valueOf(15));
    chunk3Info.setMinFilters(chunk3MinFilters);
    Map<String, Object> chunk3MaxFilters = Maps.newHashMap();
    chunk3MaxFilters.put("name", Integer.valueOf(20));
    chunk3Info.setMaxFilters(chunk3MaxFilters);

    ChunkInfo chunk6Info = new ChunkInfo(Arrays.asList(HOST_C), dbName + "."
        + collectionName + "-06");
    Map<String, Object> chunk6MinFilters = Maps.newHashMap();
    chunk5MinFilters.put("name", Integer.valueOf(25));
    chunk6Info.setMinFilters(chunk6MinFilters);
    Map<String, Object> chunk6MaxFilters = Maps.newHashMap();
    chunk5MaxFilters.put("name", Integer.valueOf(30));
    chunk6Info.setMaxFilters(chunk6MaxFilters);
    chunkList = Arrays.asList(chunk3Info, chunk6Info);
    chunksInverseMapping.put(HOST_C, chunkList);

    // entry4
    Set<ServerAddress> hosts_D = Sets.newHashSet();
    hosts_A.add(new ServerAddress(HOST_D));
    chunksMapping.put(dbName + "." + collectionName + "-04", hosts_D);

    ChunkInfo chunk4Info = new ChunkInfo(Arrays.asList(HOST_D), dbName + "."
        + collectionName + "-04");
    Map<String, Object> chunk4MinFilters = Maps.newHashMap();
View Full Code Here

        // It has multiple nodes
        StringTokenizer st = new StringTokenizer(seeds, ",");
        List<ServerAddress> addrs = new ArrayList<ServerAddress>();
        while (st.hasMoreElements()) {
          String serverName = st.nextElement().toString();
          ServerAddress server = new ServerAddress(serverName);
          addrs.add(server);
        }
        mongoClient = new MongoClient(addrs);
      } else
        mongoClient = new MongoClient(seeds);
View Full Code Here

                port = Integer.parseInt(tokens[1]);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("Wrong address format: " + address);
            }

            list.add(new ServerAddress(host, port));
        }

        return list;
    }
View Full Code Here

    {
    host = array[ i ].substring( 0, index );
    port = MStringUtil.parseInt( array[ i ].substring( index ), 27017 );
    }
 
  addrList.add( new ServerAddress( host, port ) );
  }

if( options == null )
  {
  return new Mongo( addrList );
View Full Code Here

  }

  @Test
  public void translateCursorNotFound() throws UnknownHostException {

    MongoException.CursorNotFound exception = new MongoException.CursorNotFound(1, new ServerAddress());
    DataAccessException translatedException = translator.translateExceptionIfPossible(exception);

    expectExceptionWithCauseMessage(translatedException, DataAccessResourceFailureException.class);
  }
View Full Code Here

    assertThat(result, is(instanceOf(ServerAddress[].class)));
    Collection<ServerAddress> addresses = Arrays.asList((ServerAddress[]) result);
    assertThat(addresses, hasSize(1));
    if (port == null) {
      assertThat(addresses, hasItem(new ServerAddress(InetAddress.getByName(hostAddress))));
    } else {
      assertThat(addresses, hasItem(new ServerAddress(InetAddress.getByName(hostAddress), port)));
    }
  }
View Full Code Here

    List<ServerAddress> replicaSetSeeds = (List<ServerAddress>) ReflectionTestUtils.getField(mfb, "replicaSetSeeds");

    assertThat(replicaSetSeeds, is(notNullValue()));
    assertThat(
        replicaSetSeeds,
        hasItems(new ServerAddress(InetAddress.getByName("127.0.0.1"), 10001),
            new ServerAddress(InetAddress.getByName("localhost"), 10002)));
  }
View Full Code Here

    assertThat(replicaSetSeeds, is(notNullValue()));
    assertThat(replicaSetSeeds, hasSize(3));
    assertThat(
        replicaSetSeeds,
        hasItems(new ServerAddress("192.168.174.130", 27017), new ServerAddress("192.168.174.130", 27018),
            new ServerAddress("192.168.174.130", 27019)));
  }
View Full Code Here

   */
  @SuppressWarnings("deprecation")
  public void afterPropertiesSet() throws Exception {

    Mongo mongo;
    ServerAddress defaultOptions = new ServerAddress();

    if (mongoOptions == null) {
      mongoOptions = new MongoOptions();
    }

    if (!isNullOrEmpty(replicaPair)) {
      if (replicaPair.size() < 2) {
        throw new CannotGetMongoDbConnectionException("A replica pair must have two server entries");
      }
      mongo = new Mongo(replicaPair.get(0), replicaPair.get(1), mongoOptions);
    } else if (!isNullOrEmpty(replicaSetSeeds)) {
      mongo = new Mongo(replicaSetSeeds, mongoOptions);
    } else {
      String mongoHost = StringUtils.hasText(host) ? host : defaultOptions.getHost();
      mongo = port != null ? new Mongo(new ServerAddress(mongoHost, port), mongoOptions) : new Mongo(mongoHost,
          mongoOptions);
    }

    if (writeConcern != null) {
      mongo.setWriteConcern(writeConcern);
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.