Skip to content

Commit 5ea7b40

Browse files
committed
Minor syntax changes in StreamEnvironment
1 parent a1b1c77 commit 5ea7b40

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

src/main/java/com/rabbitmq/stream/impl/StreamEnvironment.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
package com.rabbitmq.stream.impl;
1515

16+
import static com.rabbitmq.stream.impl.AsyncRetry.asyncRetry;
1617
import static com.rabbitmq.stream.impl.Utils.convertCodeToException;
1718
import static com.rabbitmq.stream.impl.Utils.exceptionMessage;
1819
import static com.rabbitmq.stream.impl.Utils.formatConstant;
@@ -242,10 +243,7 @@ class StreamEnvironment implements Environment {
242243
: clientParametersPrototype.codec();
243244
this.clockRefreshFuture =
244245
this.scheduledExecutorService.scheduleAtFixedRate(
245-
Utils.namedRunnable(() -> this.clock.refresh(), "Background clock refresh"),
246-
1,
247-
1,
248-
SECONDS);
246+
namedRunnable(this.clock::refresh, "Background clock refresh"), 1, 1, SECONDS);
249247
}
250248

251249
private ShutdownListener shutdownListener(
@@ -261,7 +259,7 @@ private ShutdownListener shutdownListener(
261259
try {
262260
Client.ClientParameters newLocatorParameters =
263261
this.locatorParametersCopy().shutdownListener(shutdownListenerReference.get());
264-
AsyncRetry.asyncRetry(
262+
asyncRetry(
265263
() -> {
266264
LOGGER.debug("Locator reconnection...");
267265
Address resolvedAddress = addressResolver.resolve(locator.address());
@@ -285,7 +283,7 @@ private ShutdownListener shutdownListener(
285283
.scheduler(this.scheduledExecutorService)
286284
.delayPolicy(recoveryBackOffDelayPolicy)
287285
.build()
288-
.thenAccept(newClient -> locator.client(newClient))
286+
.thenAccept(locator::client)
289287
.exceptionally(
290288
ex -> {
291289
LOGGER.debug("Locator recovery failed", ex);
@@ -309,7 +307,7 @@ private void scheduleLocatorConnection(
309307
try {
310308
Client.ClientParameters newLocatorParameters =
311309
this.locatorParametersCopy().shutdownListener(shutdownListener);
312-
AsyncRetry.asyncRetry(
310+
asyncRetry(
313311
() -> {
314312
LOGGER.debug("Locator reconnection...");
315313
Address resolvedAddress = addressResolver.resolve(locator.address());
@@ -333,7 +331,7 @@ private void scheduleLocatorConnection(
333331
.scheduler(this.scheduledExecutorService)
334332
.delayPolicy(recoveryBackOffDelayPolicy)
335333
.build()
336-
.thenAccept(newClient -> locator.client(newClient))
334+
.thenAccept(locator::client)
337335
.exceptionally(
338336
ex -> {
339337
LOGGER.debug("Locator recovery failed", ex);
@@ -652,18 +650,16 @@ Runnable registerConsumer(
652650
MessageHandler messageHandler,
653651
Map<String, String> subscriptionProperties,
654652
ConsumerFlowStrategy flowStrategy) {
655-
Runnable closingCallback =
656-
this.consumersCoordinator.subscribe(
657-
consumer,
658-
stream,
659-
offsetSpecification,
660-
trackingReference,
661-
subscriptionListener,
662-
trackingClosingCallback,
663-
messageHandler,
664-
subscriptionProperties,
665-
flowStrategy);
666-
return closingCallback;
653+
return this.consumersCoordinator.subscribe(
654+
consumer,
655+
stream,
656+
offsetSpecification,
657+
trackingReference,
658+
subscriptionListener,
659+
trackingClosingCallback,
660+
messageHandler,
661+
subscriptionProperties,
662+
flowStrategy);
667663
}
668664

669665
Runnable registerProducer(StreamProducer producer, String reference, String stream) {
@@ -674,12 +670,12 @@ Client locator() {
674670
return this.locators.stream()
675671
.filter(Locator::isSet)
676672
.findAny()
677-
.orElseThrow(() -> new LocatorNotAvailableException())
673+
.orElseThrow(LocatorNotAvailableException::new)
678674
.client();
679675
}
680676

681677
<T> T locatorOperation(Function<Client, T> operation) {
682-
return locatorOperation(operation, () -> locator(), this.recoveryBackOffDelayPolicy);
678+
return locatorOperation(operation, this::locator, this.recoveryBackOffDelayPolicy);
683679
}
684680

685681
static <T> T locatorOperation(
@@ -801,7 +797,7 @@ TrackingConsumerRegistration registerTrackingConsumer(
801797
: offsetTrackingRegistration.trackingCallback(),
802798
offsetTrackingRegistration == null
803799
? Utils.NO_OP_LONG_SUPPLIER
804-
: () -> offsetTrackingRegistration.flush());
800+
: offsetTrackingRegistration::flush);
805801
}
806802

807803
@Override
@@ -900,7 +896,7 @@ private boolean isSet() {
900896
}
901897

902898
private Client client() {
903-
return this.client.orElseThrow(() -> new LocatorNotAvailableException());
899+
return this.client.orElseThrow(LocatorNotAvailableException::new);
904900
}
905901

906902
private Client nullableClient() {

0 commit comments

Comments
 (0)