Move Java client into com.microsoft.aspnet.signalr (#2763)
This commit is contained in:
parent
2265acde78
commit
c9104d4932
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface Action {
|
||||
void invoke();
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface Action1<T1> {
|
||||
void invoke(T1 param1);
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface Action2<T1, T2> {
|
||||
void invoke(T1 param1, T2 param2);
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface Action3<T1, T2, T3> {
|
||||
void invoke(T1 param1, T2 param2, T3 param3);
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface Action4<T1, T2, T3, T4> {
|
||||
void invoke(T1 param1, T2 param2, T3 param3, T4 param4);
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface Action5<T1, T2, T3, T4, T5> {
|
||||
void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5);
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface Action6<T1, T2, T3, T4, T5, T6> {
|
||||
void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6);
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface Action7<T1, T2, T3, T4, T5, T6, T7> {
|
||||
void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7);
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface Action8<T1, T2, T3, T4, T5, T6, T7, T8> {
|
||||
void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7, T8 param8);
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface ActionBase {
|
||||
void invoke(Object ... params);
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import com.microsoft.aspnet.signalr.HubConnection;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Chat {
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public class ConsoleLogger implements Logger {
|
||||
private LogLevel logLevel;
|
||||
public ConsoleLogger(LogLevel logLevel) {
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class HandshakeProtocol {
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public class HandshakeRequestMessage {
|
||||
String protocol;
|
||||
int version;
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public class HandshakeResponseMessage {
|
||||
public String error;
|
||||
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public enum HubConnectionState {
|
||||
CONNECTED,
|
||||
DISCONNECTED,
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
/**
|
||||
* A base class for hub messages.
|
||||
*/
|
||||
public abstract class HubMessage {
|
||||
abstract HubMessageType getMessageType();
|
||||
public abstract HubMessageType getMessageType();
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public enum HubMessageType {
|
||||
INVOCATION(1),
|
||||
STREAM_ITEM(2),
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
/**
|
||||
* A protocol abstraction for communicating with SignalR hubs.
|
||||
*/
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public class InvocationMessage extends HubMessage {
|
||||
int type = HubMessageType.INVOCATION.value;
|
||||
String invocationId;
|
||||
|
|
@ -37,7 +39,7 @@ public class InvocationMessage extends HubMessage {
|
|||
}
|
||||
|
||||
@Override
|
||||
HubMessageType getMessageType() {
|
||||
public HubMessageType getMessageType() {
|
||||
return HubMessageType.INVOCATION;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public enum LogLevel {
|
||||
Trace(0),
|
||||
Debug(1),
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface Logger {
|
||||
void log(LogLevel logLevel, String message);
|
||||
void log(LogLevel logLevel, String formattedMessage, Object ... args);
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public class NullLogger implements Logger {
|
||||
@Override
|
||||
public void log(LogLevel logLevel, String message) { }
|
||||
|
|
@ -1,7 +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.
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface OnReceiveCallBack {
|
||||
void invoke(String message) throws Exception;
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public class PingMessage extends HubMessage {
|
||||
|
||||
int type = HubMessageType.PING.value;
|
||||
|
||||
@Override
|
||||
HubMessageType getMessageType() {
|
||||
public HubMessageType getMessageType() {
|
||||
return HubMessageType.PING;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,15 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Subscription {
|
||||
private CallbackMap handlers;
|
||||
private ActionBase action;
|
||||
private String target;
|
||||
|
||||
public Subscription(CallbackMap handlers, ActionBase action, String target) {
|
||||
this.handlers = handlers;
|
||||
this.action = action;
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public enum TransferFormat {
|
||||
Text,
|
||||
Binary
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
public interface Transport {
|
||||
void start() throws InterruptedException;
|
||||
void send(String message) throws Exception;
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
// 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.
|
||||
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
|
||||
public class WebSocketTransport implements Transport {
|
||||
private WebSocketClient webSocketClient;
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
// 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.
|
||||
|
||||
import com.microsoft.aspnet.signalr.HandshakeProtocol;
|
||||
import com.microsoft.aspnet.signalr.HandshakeRequestMessage;
|
||||
import com.microsoft.aspnet.signalr.HandshakeResponseMessage;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// 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.
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.microsoft.aspnet.signalr.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.microsoft.aspnet.signalr.*;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
|
@ -57,10 +58,10 @@ public class JsonHubProtocolTest {
|
|||
//We can safely cast here because we know that it's an invocation message.
|
||||
InvocationMessage invocationMessage = (InvocationMessage) messages[0];
|
||||
|
||||
assertEquals("test", invocationMessage.target);
|
||||
assertEquals(null, invocationMessage.invocationId);
|
||||
assertEquals("test", invocationMessage.getTarget());
|
||||
assertEquals(null, invocationMessage.getInvocationId());
|
||||
|
||||
JsonArray messageResult = (JsonArray) invocationMessage.arguments[0];
|
||||
JsonArray messageResult = (JsonArray) invocationMessage.getArguments()[0];
|
||||
assertEquals(42, messageResult.getAsInt());
|
||||
}
|
||||
|
||||
|
|
@ -95,9 +96,9 @@ public class JsonHubProtocolTest {
|
|||
//Now that we know we have an invocation message we can cast the hubMessage.
|
||||
InvocationMessage invocationMessage = (InvocationMessage) messages[0];
|
||||
|
||||
assertEquals("one", invocationMessage.target);
|
||||
assertEquals(null, invocationMessage.invocationId);
|
||||
JsonArray messageResult = (JsonArray) invocationMessage.arguments[0];
|
||||
assertEquals("one", invocationMessage.getTarget());
|
||||
assertEquals(null, invocationMessage.getInvocationId());
|
||||
JsonArray messageResult = (JsonArray) invocationMessage.getArguments()[0];
|
||||
assertEquals(42, messageResult.getAsInt());
|
||||
|
||||
// Check the second message
|
||||
|
|
@ -106,9 +107,9 @@ public class JsonHubProtocolTest {
|
|||
//Now that we know we have an invocation message we can cast the hubMessage.
|
||||
InvocationMessage invocationMessage2 = (InvocationMessage) messages[1];
|
||||
|
||||
assertEquals("two", invocationMessage2.target);
|
||||
assertEquals(null, invocationMessage2.invocationId);
|
||||
JsonArray secondMessageResult = (JsonArray) invocationMessage2.arguments[0];
|
||||
assertEquals("two", invocationMessage2.getTarget());
|
||||
assertEquals(null, invocationMessage2.getInvocationId());
|
||||
JsonArray secondMessageResult = (JsonArray) invocationMessage2.getArguments()[0];
|
||||
assertEquals(43, secondMessageResult.getAsInt());
|
||||
}
|
||||
|
||||
|
|
@ -121,9 +122,9 @@ public class JsonHubProtocolTest {
|
|||
assertEquals(HubMessageType.INVOCATION, messages[0].getMessageType());
|
||||
|
||||
InvocationMessage message = (InvocationMessage)messages[0];
|
||||
assertEquals("test", message.target);
|
||||
assertEquals(null, message.invocationId);
|
||||
JsonArray messageResult = ((JsonArray) message.arguments[0]);
|
||||
assertEquals("test", message.getTarget());
|
||||
assertEquals(null, message.getInvocationId());
|
||||
JsonArray messageResult = ((JsonArray) message.getArguments()[0]);
|
||||
assertEquals(42, messageResult.get(0).getAsInt());
|
||||
assertEquals(24, messageResult.get(1).getAsInt());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
// 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.
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import com.microsoft.aspnet.signalr.NullLogger;
|
||||
import com.microsoft.aspnet.signalr.WebSocketTransport;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue