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