|
43 | 43 | import com.mongodb.operation.ReadOperation;
|
44 | 44 | import com.mongodb.operation.WriteOperation;
|
45 | 45 | import com.mongodb.selector.LatencyMinimizingServerSelector;
|
| 46 | +import com.mongodb.selector.ServerSelector; |
46 | 47 | import org.bson.BsonBoolean;
|
47 | 48 | import org.bson.BsonDocument;
|
48 | 49 | import org.bson.BsonTimestamp;
|
@@ -853,13 +854,31 @@ ClientSession getClientSession(final ClientSession clientSessionFromOperation) {
|
853 | 854 | }
|
854 | 855 |
|
855 | 856 | ClientSession createClientSession(final ClientSessionOptions options) {
|
856 |
| - if (cluster.getDescription().getLogicalSessionTimeoutMinutes() != null && credentialsList.size() < 2) { |
| 857 | + if (credentialsList.size() > 1) { |
| 858 | + return null; |
| 859 | + } |
| 860 | + if (getConnectedClusterDescription().getLogicalSessionTimeoutMinutes() != null) { |
857 | 861 | return new ClientSessionImpl(this, options);
|
858 | 862 | } else {
|
859 | 863 | return null;
|
860 | 864 | }
|
861 | 865 | }
|
862 | 866 |
|
| 867 | + @SuppressWarnings("deprecation") |
| 868 | + private ClusterDescription getConnectedClusterDescription() { |
| 869 | + ClusterDescription clusterDescription = cluster.getDescription(); |
| 870 | + if (clusterDescription.getAny().isEmpty()) { |
| 871 | + cluster.selectServer(new ServerSelector() { |
| 872 | + @Override |
| 873 | + public List<ServerDescription> select(final ClusterDescription clusterDescription) { |
| 874 | + return clusterDescription.getAny(); |
| 875 | + } |
| 876 | + }); |
| 877 | + clusterDescription = cluster.getDescription(); |
| 878 | + } |
| 879 | + return clusterDescription; |
| 880 | + } |
| 881 | + |
863 | 882 | static class ClientSessionImpl implements ClientSession {
|
864 | 883 | private static final String CLUSTER_TIME_KEY = "clusterTime";
|
865 | 884 |
|
|
0 commit comments