Skip to content

Commit 3e53533

Browse files
authored
Adding HubConnection State Enum (#2627)
1 parent a2942ce commit 3e53533

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

clients/java/signalr/src/main/java/HubConnection.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public class HubConnection {
1515
private CallbackMap handlers = new CallbackMap();
1616
private HubProtocol protocol;
1717
private Gson gson = new Gson();
18-
19-
public Boolean connected = false;
18+
private HubConnectionState connectionState = HubConnectionState.DISCONNECTED;
2019

2120
public HubConnection(String url, Transport transport){
2221
this.url = url;
@@ -68,15 +67,19 @@ public HubConnection(String url) {
6867
this(url, null);
6968
}
7069

70+
public HubConnectionState getConnectionState() {
71+
return connectionState;
72+
}
73+
7174
public void start() throws InterruptedException {
7275
transport.setOnReceive(this.callback);
7376
transport.start();
74-
connected = true;
77+
connectionState = HubConnectionState.CONNECTED;
7578
}
7679

7780
public void stop(){
7881
transport.stop();
79-
connected = false;
82+
connectionState = HubConnectionState.DISCONNECTED;
8083
}
8184

8285
public void send(String method, Object... args) throws Exception {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
public enum HubConnectionState {
5+
CONNECTED,
6+
DISCONNECTED,
7+
}

clients/java/signalr/src/test/java/HubConnectionTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public void checkHubConnectionState() throws InterruptedException {
1313
Transport mockTransport = new MockEchoTransport();
1414
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport);
1515
hubConnection.start();
16-
assertTrue(hubConnection.connected);
16+
assertEquals(HubConnectionState.CONNECTED, hubConnection.getConnectionState());
1717

1818
hubConnection.stop();
19-
assertFalse(hubConnection.connected);
19+
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
2020
}
2121

2222
@Test

0 commit comments

Comments
 (0)