11/*
2- * Copyright 2015-2019 the original author or authors.
2+ * Copyright 2015-2020 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2626import io .rsocket .internal .ClientServerInputMultiplexer ;
2727import java .time .Duration ;
2828import java .util .concurrent .atomic .AtomicBoolean ;
29- import java .util .function .Supplier ;
3029import org .slf4j .Logger ;
3130import org .slf4j .LoggerFactory ;
31+ import reactor .core .publisher .Flux ;
3232import reactor .core .publisher .Mono ;
33+ import reactor .util .retry .Retry ;
3334
3435public class ClientRSocketSession implements RSocketSession <Mono <DuplexConnection >> {
3536 private static final Logger logger = LoggerFactory .getLogger (ClientRSocketSession .class );
@@ -42,7 +43,7 @@ public class ClientRSocketSession implements RSocketSession<Mono<DuplexConnectio
4243 public ClientRSocketSession (
4344 DuplexConnection duplexConnection ,
4445 Duration resumeSessionDuration ,
45- Supplier < ResumeStrategy > resumeStrategy ,
46+ Retry retry ,
4647 ResumableFramesStore resumableFramesStore ,
4748 Duration resumeStreamTimeout ,
4849 boolean cleanupStoreOnKeepAlive ) {
@@ -63,24 +64,13 @@ public ClientRSocketSession(
6364 .flatMap (
6465 err -> {
6566 logger .debug ("Client session connection error. Starting new connection" );
66- ResumeStrategy reconnectOnError = resumeStrategy .get ();
67- ClientResume clientResume = new ClientResume (resumeSessionDuration , resumeToken );
6867 AtomicBoolean once = new AtomicBoolean ();
6968 return newConnection
7069 .delaySubscription (
7170 once .compareAndSet (false , true )
72- ? reconnectOnError . apply ( clientResume , err )
71+ ? retry . generateCompanion ( Flux . just ( new RetrySignal ( err )) )
7372 : Mono .empty ())
74- .retryWhen (
75- errors ->
76- errors
77- .doOnNext (
78- retryErr ->
79- logger .debug ("Resumption reconnection error" , retryErr ))
80- .flatMap (
81- retryErr ->
82- Mono .from (reconnectOnError .apply (clientResume , retryErr ))
83- .doOnNext (v -> logger .debug ("Retrying with: {}" , v ))))
73+ .retryWhen (retry )
8474 .timeout (resumeSessionDuration );
8575 })
8676 .map (ClientServerInputMultiplexer ::new )
@@ -177,4 +167,28 @@ private static long remotePos(ByteBuf resumeOkFrame) {
177167 private static ConnectionErrorException errorFrameThrowable (long impliedPos ) {
178168 return new ConnectionErrorException ("resumption_server_pos=[" + impliedPos + "]" );
179169 }
170+
171+ private static class RetrySignal implements Retry .RetrySignal {
172+
173+ private final Throwable ex ;
174+
175+ RetrySignal (Throwable ex ) {
176+ this .ex = ex ;
177+ }
178+
179+ @ Override
180+ public long totalRetries () {
181+ return 0 ;
182+ }
183+
184+ @ Override
185+ public long totalRetriesInARow () {
186+ return 0 ;
187+ }
188+
189+ @ Override
190+ public Throwable failure () {
191+ return ex ;
192+ }
193+ }
180194}
0 commit comments