@@ -97,16 +97,10 @@ private DeprioritizingSelector(final ServerSelector wrapped) {
97
97
@ Override
98
98
public List <ServerDescription > select (final ClusterDescription clusterDescription ) {
99
99
if (isEnabled (clusterDescription .getType ())) {
100
- List <ServerDescription > filteredServerDescriptions = ClusterDescriptionHelper .getServersByPredicate (
100
+ List <ServerDescription > nonDeprioritizedServerDescriptions = ClusterDescriptionHelper .getServersByPredicate (
101
101
clusterDescription , serverDescription -> !deprioritized .contains (serverDescription .getAddress ()));
102
- ClusterDescription filteredClusterDescription = new ClusterDescription (
103
- clusterDescription .getConnectionMode (),
104
- clusterDescription .getType (),
105
- clusterDescription .getSrvResolutionException (),
106
- filteredServerDescriptions ,
107
- clusterDescription .getClusterSettings (),
108
- clusterDescription .getServerSettings ());
109
- List <ServerDescription > result = wrapped .select (filteredClusterDescription );
102
+ List <ServerDescription > result = wrapped .select (
103
+ copyWithServerDescriptions (clusterDescription , nonDeprioritizedServerDescriptions ));
110
104
if (result .isEmpty ()) {
111
105
// fall back to selecting from all servers ignoring the deprioritized ones
112
106
result = wrapped .select (clusterDescription );
@@ -116,6 +110,17 @@ public List<ServerDescription> select(final ClusterDescription clusterDescriptio
116
110
return wrapped .select (clusterDescription );
117
111
}
118
112
}
113
+
114
+ private ClusterDescription copyWithServerDescriptions (
115
+ final ClusterDescription clusterDescription , final List <ServerDescription > serverDescriptions ) {
116
+ return new ClusterDescription (
117
+ clusterDescription .getConnectionMode (),
118
+ clusterDescription .getType (),
119
+ clusterDescription .getSrvResolutionException (),
120
+ serverDescriptions ,
121
+ clusterDescription .getClusterSettings (),
122
+ clusterDescription .getServerSettings ());
123
+ }
119
124
}
120
125
}
121
126
}
0 commit comments