Example usage for com.mongodb.connection ServerDescription getAddress

List of usage examples for com.mongodb.connection ServerDescription getAddress

Introduction

In this page you can find the example usage for com.mongodb.connection ServerDescription getAddress.

Prototype

public ServerAddress getAddress() 

Source Link

Document

Gets the address of this server

Usage

From source file:com.navercorp.pinpoint.plugin.mongo.interceptor.MongoDriverConnectInterceptor3_0.java

License:Apache License

private List<String> getHostList(Object arg) {
    if (!(arg instanceof Cluster)) {
        return Collections.emptyList();
    }/*from w w  w .ja v a2 s .c  o m*/

    final Cluster cluster = (Cluster) arg;

    final List<String> hostList = new ArrayList<String>();

    Collection<ServerDescription> serverDescriptions;// = cluster.getDescription().getAll();//.getServerDescriptions();

    try {
        ClusterDescription.class.getDeclaredMethod("getServerDescriptions");
        serverDescriptions = cluster.getDescription().getServerDescriptions();
    } catch (NoSuchMethodException e) {
        serverDescriptions = cluster.getDescription().getAll();
    }

    for (ServerDescription serverDescription : serverDescriptions) {

        ServerAddress serverAddress = serverDescription.getAddress();
        final String hostAddress = HostAndPort.toHostAndPortString(serverAddress.getHost(),
                serverAddress.getPort());
        hostList.add(hostAddress);
    }

    return hostList;
}