Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example of progressive call results
Browse files Browse the repository at this point in the history
muzzammilshahid committed Mar 21, 2024

Verified

This commit was signed with the committer’s verified signature.
ktwrd kate
1 parent 2fd5a49 commit cb1d491
Showing 1 changed file with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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 cb1d491

Please sign in to comment.