List of usage examples for com.mongodb ServerAddress sameHost
@Deprecated public boolean sameHost(final String hostName)
From source file:com.nec.strudel.tkvs.store.mongodb.MongodbStore.java
License:Apache License
ServerAddress chooseOne(List<ServerAddress> addrs) { if (addrs.size() == 1) { return addrs.get(0); }//from w ww . j a v a 2 s. c om InetAddress local = thisHost(); String host = local.getHostName(); for (ServerAddress a : addrs) { if (a.sameHost("localhost")) { return a; } else if (a.sameHost(host)) { return a; } else { try { InetAddress addr = InetAddress.getByName(a.getHost()); if (local.equals(addr)) { return a; } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } Random rand = new Random(); return addrs.get(rand.nextInt(addrs.size())); }