Java Client API review cleanup (#2956)
This commit is contained in:
parent
48b3f18642
commit
529cfeeff8
|
|
@ -5,9 +5,9 @@ package com.microsoft.aspnet.signalr;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.Collections;
|
||||
|
||||
class CallbackMap {
|
||||
private ConcurrentHashMap<String, List<InvocationHandler>> handlers = new ConcurrentHashMap<>();
|
||||
|
|
|
|||
|
|
@ -249,6 +249,24 @@ public class HubConnection {
|
|||
transport.send(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all handlers associated with the method with the specified method name.
|
||||
*
|
||||
* @param name The name of the hub method from which handlers are being removed.
|
||||
*/
|
||||
public void remove(String name) {
|
||||
handlers.remove(name);
|
||||
logger.log(LogLevel.Trace, "Removing handlers for client method %s", name);
|
||||
}
|
||||
|
||||
public void onClosed(Consumer<Exception> callback) {
|
||||
if (onClosedCallbackList == null) {
|
||||
onClosedCallbackList = new ArrayList<>();
|
||||
}
|
||||
|
||||
onClosedCallbackList.add(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a handler that will be invoked when the hub method with the specified method name is invoked.
|
||||
*
|
||||
|
|
@ -515,24 +533,6 @@ public class HubConnection {
|
|||
return new Subscription(handlers, handler, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all handlers associated with the method with the specified method name.
|
||||
*
|
||||
* @param name The name of the hub method from which handlers are being removed.
|
||||
*/
|
||||
public void remove(String name) {
|
||||
handlers.remove(name);
|
||||
logger.log(LogLevel.Trace, "Removing handlers for client method %s", name);
|
||||
}
|
||||
|
||||
public void onClosed(Consumer<Exception> callback) {
|
||||
if (onClosedCallbackList == null) {
|
||||
onClosedCallbackList = new ArrayList<>();
|
||||
}
|
||||
|
||||
onClosedCallbackList.add(callback);
|
||||
}
|
||||
|
||||
private class ConnectionState implements InvocationBinder {
|
||||
HubConnection connection;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A protocol abstraction for communicating with SignalR hubs.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -12,7 +11,6 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
|
||||
class JsonHubProtocol implements HubProtocol {
|
||||
private final JsonParser jsonParser = new JsonParser();
|
||||
|
|
@ -31,7 +29,7 @@ class JsonHubProtocol implements HubProtocol {
|
|||
|
||||
@Override
|
||||
public TransferFormat getTransferFormat() {
|
||||
return TransferFormat.Text;
|
||||
return TransferFormat.TEXT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -120,7 +118,7 @@ class JsonHubProtocol implements HubProtocol {
|
|||
case CANCEL_INVOCATION:
|
||||
throw new UnsupportedOperationException(String.format("The message type %s is not supported yet.", messageType));
|
||||
case PING:
|
||||
hubMessages.add(new PingMessage());
|
||||
hubMessages.add(PingMessage.getInstance());
|
||||
break;
|
||||
case CLOSE:
|
||||
if (error != null) {
|
||||
|
|
|
|||
|
|
@ -3,12 +3,18 @@
|
|||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
class PingMessage extends HubMessage {
|
||||
class PingMessage extends HubMessage
|
||||
{
|
||||
private static PingMessage instance = new PingMessage();
|
||||
|
||||
int type = HubMessageType.PING.value;
|
||||
private PingMessage()
|
||||
{
|
||||
}
|
||||
|
||||
public static PingMessage getInstance() {return instance;}
|
||||
|
||||
@Override
|
||||
public HubMessageType getMessageType() {
|
||||
return HubMessageType.PING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,6 @@
|
|||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public enum TransferFormat {
|
||||
Text,
|
||||
Binary
|
||||
TEXT,
|
||||
BINARY
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,13 +8,11 @@ import static org.junit.Assert.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
public class JsonHubProtocolTest {
|
||||
private JsonHubProtocol jsonHubProtocol = new JsonHubProtocol();
|
||||
|
|
@ -31,7 +29,7 @@ public class JsonHubProtocolTest {
|
|||
|
||||
@Test
|
||||
public void checkTransferFormat() {
|
||||
assertEquals(TransferFormat.Text, jsonHubProtocol.getTransferFormat());
|
||||
assertEquals(TransferFormat.TEXT, jsonHubProtocol.getTransferFormat());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -45,7 +43,7 @@ public class JsonHubProtocolTest {
|
|||
@Test
|
||||
public void parsePingMessage() throws Exception {
|
||||
String stringifiedMessage = "{\"type\":6}\u001E";
|
||||
TestBinder binder = new TestBinder(new PingMessage());
|
||||
TestBinder binder = new TestBinder(PingMessage.getInstance());
|
||||
|
||||
HubMessage[] messages = jsonHubProtocol.parseMessages(stringifiedMessage, binder);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue