@@ -33,20 +33,20 @@ public class HubConnection implements AutoCloseable {
3333 private static final List <Type > emptyArray = new ArrayList <>();
3434 private static final int MAX_NEGOTIATE_ATTEMPTS = 100 ;
3535
36- private String baseUrl ;
3736 private final CallbackMap handlers = new CallbackMap ();
3837 private final HubProtocol protocol ;
3938 private final boolean skipNegotiate ;
4039 private final Map <String , String > headers ;
4140 private final int negotiateVersion = 1 ;
4241 private final Logger logger = LoggerFactory .getLogger (HubConnection .class );
4342 private final HttpClient httpClient ;
44- private Completable start ;
4543 private final Transport customTransport ;
4644 private final OnReceiveCallBack callback ;
4745 private final Single <String > accessTokenProvider ;
46+ private final TransportEnum transportEnum ;
4847
4948 // These are all user-settable properties
49+ private String baseUrl ;
5050 private List <OnClosedCallback > onClosedCallbackList ;
5151 private long keepAliveInterval = 15 * 1000 ;
5252 private long serverTimeout = 30 * 1000 ;
@@ -55,7 +55,6 @@ public class HubConnection implements AutoCloseable {
5555 // Private property, modified for testing
5656 private long tickRate = 1000 ;
5757
58- private TransportEnum transportEnum = TransportEnum .ALL ;
5958
6059 // Holds all mutable state other than user-defined handlers and settable properties.
6160 private final ReconnectingConnectionState state ;
@@ -116,7 +115,7 @@ void setTickRate(long tickRateInMilliseconds) {
116115
117116 // For testing purposes
118117 TransportEnum getTransportEnum () {
119- return this .transportEnum ;
118+ return this .state . currentTransport ;
120119 }
121120
122121 // For testing purposes
@@ -148,6 +147,7 @@ Transport getTransport() {
148147 }
149148
150149 if (transport != null ) {
150+ this .transportEnum = TransportEnum .ALL ;
151151 this .customTransport = transport ;
152152 } else if (transportEnum != null ) {
153153 this .transportEnum = transportEnum ;
@@ -233,11 +233,11 @@ public Completable start() {
233233 try {
234234 if (this .state .getHubConnectionState () != HubConnectionState .DISCONNECTED ) {
235235 logger .debug ("The connection is in the '{}' state. Waiting for in-progress start to complete or completing this start immediately." , this .state .getHubConnectionState ());
236- return start ;
236+ return this . state . startTask ;
237237 }
238238
239239 this .state .changeState (HubConnectionState .DISCONNECTED , HubConnectionState .CONNECTING );
240- start = localStart ;
240+ this . state . startTask = localStart ;
241241
242242 CompletableSubject tokenCompletable = CompletableSubject .create ();
243243 Map <String , String > localHeaders = new HashMap <>();
@@ -269,7 +269,7 @@ public Completable start() {
269269 Transport transport = customTransport ;
270270 if (transport == null ) {
271271 Single <String > tokenProvider = negotiateResponse .getAccessToken () != null ? Single .just (negotiateResponse .getAccessToken ()) : accessTokenProvider ;
272- switch (transportEnum ) {
272+ switch (this . state . currentTransport ) {
273273 case LONG_POLLING :
274274 transport = new LongPollingTransport (localHeaders , httpClient , tokenProvider );
275275 break ;
@@ -296,7 +296,7 @@ public Completable start() {
296296 logger .info ("HubConnection started." );
297297 connectionState .resetServerTimeout ();
298298 // Don't send pings if we're using long polling.
299- if (transportEnum != TransportEnum .LONG_POLLING ) {
299+ if (this . state . currentTransport != TransportEnum .LONG_POLLING ) {
300300 connectionState .activatePingTimer ();
301301 }
302302 } finally {
@@ -337,15 +337,17 @@ private Single<NegotiateResponse> startNegotiate(String url, int negotiateAttemp
337337 Set <String > transports = response .getAvailableTransports ();
338338 if (this .transportEnum == TransportEnum .ALL ) {
339339 if (transports .contains ("WebSockets" )) {
340- this .transportEnum = TransportEnum .WEBSOCKETS ;
340+ this .state . currentTransport = TransportEnum .WEBSOCKETS ;
341341 } else if (transports .contains ("LongPolling" )) {
342- this .transportEnum = TransportEnum .LONG_POLLING ;
342+ this .state . currentTransport = TransportEnum .LONG_POLLING ;
343343 } else {
344344 throw new RuntimeException ("There were no compatible transports on the server." );
345345 }
346346 } else if (this .transportEnum == TransportEnum .WEBSOCKETS && !transports .contains ("WebSockets" ) ||
347347 (this .transportEnum == TransportEnum .LONG_POLLING && !transports .contains ("LongPolling" ))) {
348348 throw new RuntimeException ("There were no compatible transports on the server." );
349+ } else {
350+ this .state .currentTransport = this .transportEnum ;
349351 }
350352
351353 String connectionToken = "" ;
@@ -497,7 +499,6 @@ private void stopConnection(String errorMessage) {
497499
498500 logger .info ("HubConnection stopped." );
499501 this .state .changeState (HubConnectionState .CONNECTED , HubConnectionState .DISCONNECTED );
500- transportEnum = TransportEnum .ALL ;
501502 } finally {
502503 this .state .unlock ();
503504 }
@@ -1426,6 +1427,8 @@ private final class ReconnectingConnectionState {
14261427 private final Lock lock = new ReentrantLock ();
14271428 private ConnectionState state ;
14281429 private HubConnectionState hubConnectionState = HubConnectionState .DISCONNECTED ;
1430+ public Completable startTask ;
1431+ public TransportEnum currentTransport ;
14291432
14301433 public ReconnectingConnectionState (Logger logger ) {
14311434 this .logger = logger ;
0 commit comments