Example usage for com.mongodb ServerAddress sameHost

List of usage examples for com.mongodb ServerAddress sameHost

Introduction

In this page you can find the example usage for com.mongodb ServerAddress sameHost.

Prototype

@Deprecated
public boolean sameHost(final String hostName) 

Source Link

Document

Determines whether this address is the same as a given host.

Usage

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()));
}