com.mongodb.connection.Cluster Java Examples

The following examples show how to use com.mongodb.connection.Cluster. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomMongoHealthIndicator.java    From hesperides with GNU General Public License v3.0 5 votes vote down vote up
static Cluster getCluster(MongoClient mongoClient) {
    try {
        Method privateMethod = Mongo.class.getDeclaredMethod("getCluster", null);
        privateMethod.setAccessible(true);
        return (Cluster) privateMethod.invoke(mongoClient);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: MongoDBClientDelegateInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    Cluster cluster = (Cluster) allArguments[0];
    String remotePeer = MongoRemotePeerHelper.getRemotePeer(cluster);
    objInst.setSkyWalkingDynamicField(remotePeer);
}
 
Example #3
Source File: MongoRemotePeerHelper.java    From skywalking with Apache License 2.0 5 votes vote down vote up
public static String getRemotePeer(Cluster cluster) {
    StringBuilder peersBuilder = new StringBuilder();
    for (ServerDescription description : cluster.getDescription().getAll()) {
        ServerAddress address = description.getAddress();
        peersBuilder.append(address.getHost()).append(":").append(address.getPort()).append(";");
    }
    return peersBuilder.substring(0, peersBuilder.length() - 1);
}
 
Example #4
Source File: MongoDriverConnectInterceptor3_0.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private List<String> getHostList(Object arg) {
    if (!(arg instanceof Cluster)) {
        return Collections.emptyList();
    }

    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;
}
 
Example #5
Source File: MongoDBInterceptor.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    Cluster cluster = (Cluster) allArguments[0];
    String peers = MongoRemotePeerHelper.getRemotePeer(cluster);
    objInst.setSkyWalkingDynamicField(peers);
}