Skip to content

Commit 37ecebc

Browse files
add example of progressive call results
1 parent 2fd5a49 commit 37ecebc

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

autobahn/src/main/java/io/crossbar/autobahn/wamp/Session.java

-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ private void onPreSessionMessage(IMessage message) throws Exception {
322322
private void onMessage(IMessage message) throws Exception {
323323
if (message instanceof Result) {
324324
Result msg = (Result) message;
325-
326325
CallRequest request = getOrDefault(mCallRequests, msg.request, null);
327326
if (request == null) {
328327
throw new ProtocolError(String.format(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package io.crossbar.autobahn.demogallery;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.Map;
6+
import java.util.concurrent.CompletableFuture;
7+
8+
import io.crossbar.autobahn.wamp.Client;
9+
import io.crossbar.autobahn.wamp.Session;
10+
import io.crossbar.autobahn.wamp.types.CallOptions;
11+
import io.crossbar.autobahn.wamp.types.CallResult;
12+
import io.crossbar.autobahn.wamp.types.ExitInfo;
13+
import io.crossbar.autobahn.wamp.types.InvocationDetails;
14+
import io.crossbar.autobahn.wamp.types.InvocationResult;
15+
import io.crossbar.autobahn.wamp.types.Registration;
16+
17+
public class ProgressiveCallResultsExample {
18+
19+
public static CompletableFuture<ExitInfo> registerProgressive(String wsAddress, String realm) {
20+
Session wampSession = new Session();
21+
wampSession.addOnJoinListener((session, details) -> {
22+
CompletableFuture<Registration> regFuture = session.register(
23+
"io.crossbar.longop",
24+
(List<Object> args, Map<String, Object> kwargs, InvocationDetails invocationDetails) -> {
25+
for (int i = 0; i < 5; i++) {
26+
List<Object> argsList = new ArrayList<>();
27+
argsList.add(i);
28+
invocationDetails.progress.sendProgress(argsList, null);
29+
}
30+
List<Object> resultArgs = new ArrayList<>();
31+
resultArgs.add(7);
32+
return CompletableFuture.completedFuture(new InvocationResult(resultArgs));
33+
});
34+
35+
regFuture.whenComplete((registration, throwable) -> {
36+
System.out.println(String.format(
37+
"Registered procedure %s", registration.procedure));
38+
});
39+
});
40+
41+
Client wampClient = new Client(wampSession, wsAddress, realm);
42+
return wampClient.connect();
43+
}
44+
45+
46+
public static CompletableFuture<ExitInfo> callProgressive(String wsAddress, String realm) {
47+
Session wampSession = new Session();
48+
wampSession.addOnJoinListener((session, details) -> {
49+
CompletableFuture<CallResult> callFuture = session.call(
50+
"io.crossbar.longop",
51+
new CallOptions(result -> System.out.println("Receive Progress: " + result.results)));
52+
53+
callFuture.whenComplete((callResult, throwable) -> {
54+
System.out.println(String.format("Call result: %s", callResult.results));
55+
});
56+
});
57+
58+
Client wampClient = new Client(wampSession, wsAddress, realm);
59+
return wampClient.connect();
60+
}
61+
}

0 commit comments

Comments
 (0)