Search in sources :

Example 1 with Cluster

use of com.mongodb.connection.Cluster in project spring-boot by spring-projects.

the class MongoClientFactoryTests method extractServerAddresses.

private List<ServerAddress> extractServerAddresses(MongoClient client) {
    Cluster cluster = (Cluster) ReflectionTestUtils.getField(client, "cluster");
    ClusterSettings clusterSettings = (ClusterSettings) ReflectionTestUtils.getField(cluster, "settings");
    List<ServerAddress> allAddresses = clusterSettings.getHosts();
    return allAddresses;
}
Also used : ClusterSettings(com.mongodb.connection.ClusterSettings) ServerAddress(com.mongodb.ServerAddress) Cluster(com.mongodb.connection.Cluster)

Example 2 with Cluster

use of com.mongodb.connection.Cluster in project incubator-skywalking by apache.

the class MongoDBMethodInterceptor method onConstruct.

@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    Cluster cluster = (Cluster) allArguments[0];
    StringBuilder peers = new StringBuilder();
    for (ServerDescription description : cluster.getDescription().getServerDescriptions()) {
        ServerAddress address = description.getAddress();
        peers.append(address.getHost() + ":" + address.getPort() + ";");
    }
    objInst.setSkyWalkingDynamicField(peers.subSequence(0, peers.length() - 1).toString());
}
Also used : ServerDescription(com.mongodb.connection.ServerDescription) ServerAddress(com.mongodb.ServerAddress) Cluster(com.mongodb.connection.Cluster)

Example 3 with Cluster

use of com.mongodb.connection.Cluster in project pinpoint by naver.

the class MongoDriverConnectInterceptor3_0 method getHostList.

private List<String> getHostList(Object arg) {
    if (!(arg instanceof Cluster)) {
        return Collections.emptyList();
    }
    final Cluster cluster = (Cluster) arg;
    final List<String> hostList = new ArrayList<>();
    // = cluster.getDescription().getAll();//.getServerDescriptions();
    Collection<ServerDescription> serverDescriptions;
    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;
}
Also used : ServerDescription(com.mongodb.connection.ServerDescription) ArrayList(java.util.ArrayList) ServerAddress(com.mongodb.ServerAddress) Cluster(com.mongodb.connection.Cluster)

Aggregations

ServerAddress (com.mongodb.ServerAddress)3 Cluster (com.mongodb.connection.Cluster)3 ServerDescription (com.mongodb.connection.ServerDescription)2 ClusterSettings (com.mongodb.connection.ClusterSettings)1 ArrayList (java.util.ArrayList)1