Skip to content

Commit c109492

Browse files
Add SignalR client results to Java client (#41774)
1 parent 1b15d0e commit c109492

17 files changed

+932
-156
lines changed

src/SignalR/clients/java/signalr/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66
}
77
dependencies {
8-
classpath "com.diffplug.spotless:spotless-plugin-gradle:3.14.0"
8+
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.6.1"
99
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'
1010
}
1111
}
@@ -17,7 +17,7 @@ plugins {
1717

1818
allprojects {
1919
apply plugin: "java-library"
20-
apply plugin: "com.diffplug.gradle.spotless"
20+
apply plugin: "com.diffplug.spotless"
2121

2222
// If we're run from outside MSBuild, just assign a bogus dev version.
2323
version project.findProperty('packageVersion') ?: "99.99.99-dev"

src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/ActionBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
package com.microsoft.signalr;
55

6+
import io.reactivex.rxjava3.core.Completable;
7+
68
interface ActionBase {
79
// We can't use the @FunctionalInterface annotation because it's only
810
// available on Android API Level 24 and above.
9-
void invoke(Object ... params);
11+
Completable invoke(Object ... params);
1012
}

src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/CallbackMap.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,24 @@ class CallbackMap {
1414
private final Map<String, List<InvocationHandler>> handlers = new HashMap<>();
1515
private final ReentrantLock lock = new ReentrantLock();
1616

17-
public InvocationHandler put(String target, ActionBase action, Type... types) {
17+
public InvocationHandler put(String target, Object action, Type... types) {
1818
try {
1919
lock.lock();
2020
InvocationHandler handler = new InvocationHandler(action, types);
2121
if (!handlers.containsKey(target)) {
2222
handlers.put(target, new ArrayList<>());
2323
}
24-
handlers.get(target).add(handler);
24+
25+
List<InvocationHandler> methodHandlers;
26+
methodHandlers = handlers.get(target);
27+
if (handler.getHasResult()) {
28+
for (InvocationHandler existingHandler : methodHandlers) {
29+
if (existingHandler.getHasResult()) {
30+
throw new RuntimeException(String.format("'%s' already has a value returning handler. Multiple return values are not supported.", target));
31+
}
32+
}
33+
}
34+
methodHandlers.add(handler);
2535
return handler;
2636
} finally {
2737
lock.unlock();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
package com.microsoft.signalr;
5+
6+
import io.reactivex.rxjava3.core.Single;
7+
8+
/**
9+
* A callback that takes one parameter.
10+
*
11+
* @param <T1> The type of the first parameter to the callback.
12+
*/
13+
public interface Function1Single<T1, TResult> {
14+
// We can't use the @FunctionalInterface annotation because it's only
15+
// available on Android API Level 24 and above.
16+
Single<TResult> invoke(T1 param1);
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
package com.microsoft.signalr;
5+
6+
import io.reactivex.rxjava3.core.Single;
7+
8+
/**
9+
* A callback that takes one parameter.
10+
*
11+
* @param <T1> The type of the first parameter to the callback.
12+
* @param <T2> The type of the second parameter to the callback.
13+
*/
14+
public interface Function2Single<T1, T2, TResult> {
15+
// We can't use the @FunctionalInterface annotation because it's only
16+
// available on Android API Level 24 and above.
17+
Single<TResult> invoke(T1 param1, T2 param2);
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
package com.microsoft.signalr;
5+
6+
import io.reactivex.rxjava3.core.Single;
7+
8+
/**
9+
* A callback that takes one parameter.
10+
*
11+
* @param <T1> The type of the first parameter to the callback.
12+
* @param <T2> The type of the second parameter to the callback.
13+
* @param <T3> The type of the third parameter to the callback.
14+
*/
15+
public interface Function3Single<T1, T2, T3, TResult> {
16+
// We can't use the @FunctionalInterface annotation because it's only
17+
// available on Android API Level 24 and above.
18+
Single<TResult> invoke(T1 param1, T2 param2, T3 param3);
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
package com.microsoft.signalr;
5+
6+
import io.reactivex.rxjava3.core.Single;
7+
8+
/**
9+
* A callback that takes one parameter.
10+
*
11+
* @param <T1> The type of the first parameter to the callback.
12+
* @param <T2> The type of the second parameter to the callback.
13+
* @param <T3> The type of the third parameter to the callback.
14+
* @param <T4> The type of the fourth parameter to the callback.
15+
*/
16+
public interface Function4Single<T1, T2, T3, T4, TResult> {
17+
// We can't use the @FunctionalInterface annotation because it's only
18+
// available on Android API Level 24 and above.
19+
Single<TResult> invoke(T1 param1, T2 param2, T3 param3, T4 param4);
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
package com.microsoft.signalr;
5+
6+
import io.reactivex.rxjava3.core.Single;
7+
8+
/**
9+
* A callback that takes one parameter.
10+
*
11+
* @param <T1> The type of the first parameter to the callback.
12+
* @param <T2> The type of the second parameter to the callback.
13+
* @param <T3> The type of the third parameter to the callback.
14+
* @param <T4> The type of the fourth parameter to the callback.
15+
* @param <T5> The type of the fifth parameter to the callback.
16+
*/
17+
public interface Function5Single<T1, T2, T3, T4, T5, TResult> {
18+
// We can't use the @FunctionalInterface annotation because it's only
19+
// available on Android API Level 24 and above.
20+
Single<TResult> invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5);
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
package com.microsoft.signalr;
5+
6+
import io.reactivex.rxjava3.core.Single;
7+
8+
/**
9+
* A callback that takes one parameter.
10+
*
11+
* @param <T1> The type of the first parameter to the callback.
12+
* @param <T2> The type of the second parameter to the callback.
13+
* @param <T3> The type of the third parameter to the callback.
14+
* @param <T4> The type of the fourth parameter to the callback.
15+
* @param <T5> The type of the fifth parameter to the callback.
16+
* @param <T6> The type of the sixth parameter to the callback.
17+
*/
18+
public interface Function6Single<T1, T2, T3, T4, T5, T6, TResult> {
19+
// We can't use the @FunctionalInterface annotation because it's only
20+
// available on Android API Level 24 and above.
21+
Single<TResult> invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6);
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
package com.microsoft.signalr;
5+
6+
import io.reactivex.rxjava3.core.Single;
7+
8+
/**
9+
* A callback that takes one parameter.
10+
*
11+
* @param <T1> The type of the first parameter to the callback.
12+
* @param <T2> The type of the second parameter to the callback.
13+
* @param <T3> The type of the third parameter to the callback.
14+
* @param <T4> The type of the fourth parameter to the callback.
15+
* @param <T5> The type of the fifth parameter to the callback.
16+
* @param <T6> The type of the sixth parameter to the callback.
17+
* @param <T7> The type of the seventh parameter to the callback.
18+
*/
19+
public interface Function7Single<T1, T2, T3, T4, T5, T6, T7, TResult> {
20+
// We can't use the @FunctionalInterface annotation because it's only
21+
// available on Android API Level 24 and above.
22+
Single<TResult> invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7);
23+
}

0 commit comments

Comments
 (0)