Skip to content

Commit

Permalink
add example of progressive call results
Browse files Browse the repository at this point in the history
  • Loading branch information
muzzammilshahid committed Mar 25, 2024
1 parent 09d4702 commit 6869188
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ private void onPreSessionMessage(IMessage message) throws Exception {
private void onMessage(IMessage message) throws Exception {
if (message instanceof Result) {
Result msg = (Result) message;

CallRequest request = getOrDefault(mCallRequests, msg.request, null);
if (request == null) {
throw new ProtocolError(String.format(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.crossbar.autobahn.demogallery;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import io.crossbar.autobahn.wamp.Client;
import io.crossbar.autobahn.wamp.Session;
import io.crossbar.autobahn.wamp.types.CallOptions;
import io.crossbar.autobahn.wamp.types.CallResult;
import io.crossbar.autobahn.wamp.types.ExitInfo;
import io.crossbar.autobahn.wamp.types.InvocationDetails;
import io.crossbar.autobahn.wamp.types.InvocationResult;
import io.crossbar.autobahn.wamp.types.Registration;

public class ProgressiveCallResultsExample {

public static CompletableFuture<ExitInfo> registerProgressive(String wsAddress, String realm) {
Session wampSession = new Session();
wampSession.addOnJoinListener((session, details) -> {
CompletableFuture<Registration> regFuture = session.register(
"io.crossbar.longop",
(List<Object> args, Map<String, Object> kwargs, InvocationDetails invocationDetails) -> {
for (int i = 0; i < 5; i++) {
List<Object> argsList = new ArrayList<>();
argsList.add(i);
invocationDetails.progress.sendProgress(argsList, null);
}
List<Object> resultArgs = new ArrayList<>();
resultArgs.add(7);
return CompletableFuture.completedFuture(new InvocationResult(resultArgs));
});

regFuture.whenComplete((registration, throwable) -> {
System.out.println(String.format(
"Registered procedure %s", registration.procedure));
});
});

Client wampClient = new Client(wampSession, wsAddress, realm);
return wampClient.connect();
}


public static CompletableFuture<ExitInfo> callProgressive(String wsAddress, String realm) {
Session wampSession = new Session();
wampSession.addOnJoinListener((session, details) -> {
CompletableFuture<CallResult> callFuture = session.call(
"io.crossbar.longop",
new CallOptions(result -> System.out.println("Receive Progress: " + result.results)));

callFuture.whenComplete((callResult, throwable) -> {
System.out.println(String.format("Call result: %s", callResult.results));
});
});

Client wampClient = new Client(wampSession, wsAddress, realm);
return wampClient.connect();
}
}

0 comments on commit 6869188

Please sign in to comment.