Adding HubConnection State Enum (#2627)
This commit is contained in:
parent
a2942ce885
commit
3e53533db3
|
|
@ -15,8 +15,7 @@ public class HubConnection {
|
||||||
private CallbackMap handlers = new CallbackMap();
|
private CallbackMap handlers = new CallbackMap();
|
||||||
private HubProtocol protocol;
|
private HubProtocol protocol;
|
||||||
private Gson gson = new Gson();
|
private Gson gson = new Gson();
|
||||||
|
private HubConnectionState connectionState = HubConnectionState.DISCONNECTED;
|
||||||
public Boolean connected = false;
|
|
||||||
|
|
||||||
public HubConnection(String url, Transport transport){
|
public HubConnection(String url, Transport transport){
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
|
@ -68,15 +67,19 @@ public class HubConnection {
|
||||||
this(url, null);
|
this(url, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HubConnectionState getConnectionState() {
|
||||||
|
return connectionState;
|
||||||
|
}
|
||||||
|
|
||||||
public void start() throws InterruptedException {
|
public void start() throws InterruptedException {
|
||||||
transport.setOnReceive(this.callback);
|
transport.setOnReceive(this.callback);
|
||||||
transport.start();
|
transport.start();
|
||||||
connected = true;
|
connectionState = HubConnectionState.CONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop(){
|
public void stop(){
|
||||||
transport.stop();
|
transport.stop();
|
||||||
connected = false;
|
connectionState = HubConnectionState.DISCONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(String method, Object... args) throws Exception {
|
public void send(String method, Object... args) throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
}
|
||||||
|
|
@ -13,10 +13,10 @@ public class HubConnectionTest {
|
||||||
Transport mockTransport = new MockEchoTransport();
|
Transport mockTransport = new MockEchoTransport();
|
||||||
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport);
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport);
|
||||||
hubConnection.start();
|
hubConnection.start();
|
||||||
assertTrue(hubConnection.connected);
|
assertEquals(HubConnectionState.CONNECTED, hubConnection.getConnectionState());
|
||||||
|
|
||||||
hubConnection.stop();
|
hubConnection.stop();
|
||||||
assertFalse(hubConnection.connected);
|
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue