Merge pull request #2642 from aspnet/release/2.2

Adding HubConnection State Enum (#2627)
This commit is contained in:
Mikael Mengistu 2018-07-16 14:53:06 -07:00 committed by GitHub
commit 8b4b4a099d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -15,8 +15,7 @@ public class HubConnection {
private CallbackMap handlers = new CallbackMap();
private HubProtocol protocol;
private Gson gson = new Gson();
public Boolean connected = false;
private HubConnectionState connectionState = HubConnectionState.DISCONNECTED;
public HubConnection(String url, Transport transport){
this.url = url;
@ -68,15 +67,19 @@ public class HubConnection {
this(url, null);
}
public HubConnectionState getConnectionState() {
return connectionState;
}
public void start() throws InterruptedException {
transport.setOnReceive(this.callback);
transport.start();
connected = true;
connectionState = HubConnectionState.CONNECTED;
}
public void stop(){
transport.stop();
connected = false;
connectionState = HubConnectionState.DISCONNECTED;
}
public void send(String method, Object... args) throws Exception {

View File

@ -0,0 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
public enum HubConnectionState {
CONNECTED,
DISCONNECTED,
}

View File

@ -13,10 +13,10 @@ public class HubConnectionTest {
Transport mockTransport = new MockEchoTransport();
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport);
hubConnection.start();
assertTrue(hubConnection.connected);
assertEquals(HubConnectionState.CONNECTED, hubConnection.getConnectionState());
hubConnection.stop();
assertFalse(hubConnection.connected);
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
}
@Test