Example usage for com.mongodb.connection Cluster getDescription

List of usage examples for com.mongodb.connection Cluster getDescription

Introduction

In this page you can find the example usage for com.mongodb.connection Cluster getDescription.

Prototype

ClusterDescription getDescription();

Source Link

Document

Get the description of this cluster.

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   www . ja v  a 2 s.co 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;
}