Skip to content

Commit f04572f

Browse files
committed
Document optional shuffling in AddressResolver
References #691. (cherry picked from commit 3415f88)
1 parent d366c98 commit f04572f

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

src/main/java/com/rabbitmq/client/AddressResolver.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,33 @@
2020
import java.util.Collections;
2121
import java.util.List;
2222

23-
/**
24-
* Strategy interface to get the potential servers to connect to.
25-
*/
23+
/** Strategy interface to get the potential servers to connect to. */
2624
public interface AddressResolver {
2725

28-
/**
29-
* Get the potential {@link Address}es to connect to.
30-
* @return candidate {@link Address}es
31-
* @throws IOException if it encounters a problem
32-
*/
33-
List<Address> getAddresses() throws IOException;
26+
/**
27+
* Get the potential {@link Address}es to connect to.
28+
*
29+
* @return candidate {@link Address}es
30+
* @throws IOException if it encounters a problem
31+
*/
32+
List<Address> getAddresses() throws IOException;
3433

35-
default List<Address> maybeShuffle(List<Address> input) {
36-
List<Address> list = new ArrayList<Address>(input);
37-
Collections.shuffle(list);
38-
return list;
39-
}
34+
/**
35+
* Optionally shuffle the list of addresses returned by {@link #getAddresses()}.
36+
*
37+
* <p>The automatic connection recovery calls this method after {@link #getAddresses()} to pick a
38+
* random address for reconnecting.
39+
*
40+
* <p>The default method implementation calls {@link Collections#shuffle(List)}. Custom
41+
* implementations can choose to not do any shuffling to have more predictability in the
42+
* reconnection.
43+
*
44+
* @param input
45+
* @return potentially shuffled list of addresses.
46+
*/
47+
default List<Address> maybeShuffle(List<Address> input) {
48+
List<Address> list = new ArrayList<Address>(input);
49+
Collections.shuffle(list);
50+
return list;
51+
}
4052
}

src/main/java/com/rabbitmq/client/impl/recovery/RecoveryAwareAMQConnectionFactory.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ public RecoveryAwareAMQConnection newConnection() throws IOException, TimeoutExc
8282
throw new IOException("failed to connect");
8383
}
8484

85-
private static List<Address> shuffle(List<Address> addrs) {
86-
List<Address> list = new ArrayList<Address>(addrs);
87-
Collections.shuffle(list);
88-
return list;
89-
}
90-
9185
protected RecoveryAwareAMQConnection createConnection(ConnectionParams params, FrameHandler handler, MetricsCollector metricsCollector) {
9286
return new RecoveryAwareAMQConnection(params, handler, metricsCollector);
9387
}

0 commit comments

Comments
 (0)