use of com.mongodb.connection.ServerType in project mongo-java-driver by mongodb.
the class DefaultSdamServerDescriptionManager method update.
@Override
public void update(final ServerDescription candidateDescription) {
cluster.withLock(() -> {
if (TopologyVersionHelper.newer(description.getTopologyVersion(), candidateDescription.getTopologyVersion())) {
return;
}
ServerType newServerType = candidateDescription.getType();
boolean markedPoolReady = false;
/* A paused pool should not be exposed and used. Calling `ready` before updating description and calling `invalidate` after
* facilitates achieving this. However, because once the pool is observed, it may be used concurrently with the pool being
* invalidated by either the current method or the `handleException` method, the pool still may be used in a paused state.
* For those cases `MongoConnectionPoolClearedException` was introduced. */
if (ServerTypeHelper.isDataBearing(newServerType) || (newServerType != UNKNOWN && connectionMode == ClusterConnectionMode.SINGLE)) {
connectionPool.ready();
markedPoolReady = true;
}
updateDescription(candidateDescription);
Throwable candidateDescriptionException = candidateDescription.getException();
if (candidateDescriptionException != null) {
assertTrue(newServerType == UNKNOWN);
assertFalse(markedPoolReady);
connectionPool.invalidate(candidateDescriptionException);
}
});
}
Aggregations