|
48 | 48 | import java.util.function.Consumer;
|
49 | 49 | import java.util.function.Function;
|
50 | 50 | import java.util.function.Supplier;
|
51 |
| -import org.reactivestreams.Publisher; |
52 | 51 | import reactor.core.Disposable;
|
53 |
| -import reactor.core.publisher.Flux; |
54 | 52 | import reactor.core.publisher.Mono;
|
| 53 | +import reactor.util.retry.Retry; |
55 | 54 |
|
56 | 55 | /** Factory for creating RSocket clients and servers. */
|
57 | 56 | public class RSocketFactory {
|
@@ -133,7 +132,7 @@ public static class ClientRSocketFactory implements ClientTransportAcceptor {
|
133 | 132 | private boolean leaseEnabled;
|
134 | 133 | private Supplier<Leases<?>> leasesSupplier = Leases::new;
|
135 | 134 | private boolean reconnectEnabled;
|
136 |
| - private Function<Flux<Throwable>, ? extends Publisher<?>> whenFactory; |
| 135 | + private Retry retrySpec; |
137 | 136 |
|
138 | 137 | private ByteBufAllocator allocator = ByteBufAllocator.DEFAULT;
|
139 | 138 |
|
@@ -355,9 +354,8 @@ public ClientRSocketFactory reconnect() {
|
355 | 354 | * @param whenFactory a retry factory applied for {@link Mono.retryWhen(whenFactory)}
|
356 | 355 | * @return a shared instance of {@code Mono<RSocket>}.
|
357 | 356 | */
|
358 |
| - public ClientRSocketFactory reconnect( |
359 |
| - Function<Flux<Throwable>, ? extends Publisher<?>> whenFactory) { |
360 |
| - this.whenFactory = Objects.requireNonNull(whenFactory); |
| 357 | + public ClientRSocketFactory reconnect(Retry retrySpec) { |
| 358 | + this.retrySpec = Objects.requireNonNull(retrySpec); |
361 | 359 | this.reconnectEnabled = true;
|
362 | 360 | return this;
|
363 | 361 | }
|
@@ -529,7 +527,7 @@ public Mono<RSocket> start() {
|
529 | 527 | source -> {
|
530 | 528 | if (reconnectEnabled) {
|
531 | 529 | return new ReconnectMono<>(
|
532 |
| - whenFactory == null ? source : source.retryWhen(whenFactory), |
| 530 | + retrySpec == null ? source : source.retryWhen(retrySpec), |
533 | 531 | Disposable::dispose,
|
534 | 532 | INVALIDATE_FUNCTION);
|
535 | 533 | } else {
|
@@ -841,9 +839,11 @@ public Mono<T> start() {
|
841 | 839 |
|
842 | 840 | @Override
|
843 | 841 | public Mono<T> get() {
|
844 |
| - return transportServer |
845 |
| - .get() |
846 |
| - .start(duplexConnection -> acceptor(serverSetup, duplexConnection), mtu) |
| 842 | + return Mono.fromSupplier(transportServer) |
| 843 | + .flatMap( |
| 844 | + transport -> |
| 845 | + transport.start( |
| 846 | + duplexConnection -> acceptor(serverSetup, duplexConnection), mtu)) |
847 | 847 | .doOnNext(c -> c.onClose().doFinally(v -> serverSetup.dispose()).subscribe());
|
848 | 848 | }
|
849 | 849 | });
|
|
0 commit comments