Skip to content

Commit 40243e0

Browse files
committed
Introduce AddressSelector interface
Used to be Function<List<Address>,Address>. Having a dedicated interface can make changes and evolution easier.
1 parent 8723a98 commit 40243e0

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2024 Broadcom. All Rights Reserved.
2+
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
// If you have any questions regarding licensing, please contact us at
17+
18+
package com.rabbitmq.client.amqp;
19+
20+
import java.util.List;
21+
22+
public interface AddressSelector {
23+
24+
Address select(List<Address> addresses);
25+
}

src/main/java/com/rabbitmq/client/amqp/ConnectionSettings.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
package com.rabbitmq.client.amqp;
1919

2020
import java.time.Duration;
21-
import java.util.List;
22-
import java.util.function.Function;
2321
import javax.net.ssl.SSLContext;
2422

2523
public interface ConnectionSettings<T> {
@@ -45,7 +43,7 @@ public interface ConnectionSettings<T> {
4543

4644
T idleTimeout(Duration idleTimeout);
4745

48-
T addressSelector(Function<List<Address>, Address> selector);
46+
T addressSelector(AddressSelector selector);
4947

5048
T saslMechanism(String mechanism);
5149

src/main/java/com/rabbitmq/client/amqp/impl/AmqpConnectionBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.time.Duration;
2222
import java.util.ArrayList;
2323
import java.util.List;
24-
import java.util.function.Function;
2524

2625
class AmqpConnectionBuilder implements ConnectionBuilder {
2726

@@ -86,7 +85,7 @@ public ConnectionBuilder idleTimeout(Duration idleTimeout) {
8685
}
8786

8887
@Override
89-
public ConnectionBuilder addressSelector(Function<List<Address>, Address> selector) {
88+
public ConnectionBuilder addressSelector(AddressSelector selector) {
9089
return this.connectionSettings.addressSelector(selector);
9190
}
9291

src/main/java/com/rabbitmq/client/amqp/impl/DefaultConnectionSettings.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.List;
3333
import java.util.Random;
3434
import java.util.concurrent.CopyOnWriteArrayList;
35-
import java.util.function.Function;
3635
import javax.net.ssl.SSLContext;
3736
import javax.net.ssl.TrustManager;
3837
import org.apache.qpid.protonj2.client.ConnectionOptions;
@@ -58,7 +57,7 @@ abstract class DefaultConnectionSettings<T> implements ConnectionSettings<T> {
5857
private List<URI> uris = Collections.emptyList();
5958
private Duration idleTimeout = Duration.ofMillis(ConnectionOptions.DEFAULT_IDLE_TIMEOUT);
6059
private static final Random RANDOM = new Random();
61-
private Function<List<Address>, Address> addressSelector =
60+
private AddressSelector addressSelector =
6261
addresses -> {
6362
if (addresses.isEmpty()) {
6463
throw new IllegalStateException("There should at least one node to connect to");
@@ -150,7 +149,7 @@ public T idleTimeout(Duration idleTimeout) {
150149
}
151150

152151
@Override
153-
public T addressSelector(Function<List<Address>, Address> selector) {
152+
public T addressSelector(AddressSelector selector) {
154153
this.addressSelector = selector;
155154
return this.toReturn();
156155
}
@@ -180,7 +179,7 @@ Duration idleTimeout() {
180179
}
181180

182181
Address selectAddress() {
183-
return this.addressSelector.apply(this.addresses);
182+
return this.addressSelector.select(this.addresses);
184183
}
185184

186185
String saslMechanism() {

0 commit comments

Comments
 (0)