use of io.crossbar.autobahn.wamp.types.PublishOptions in project autobahn-java by crossbario.
the class CIService method producer.
private void producer(Session session) {
RegisterOptions options = new RegisterOptions(null, "roundrobin");
CompletableFuture<Registration> regFuture = session.register("io.crossbar.example.client2.stop_producing", this::stopProducing, options);
regFuture.whenComplete((registration, throwable) -> {
if (throwable == null) {
System.out.println("----------------------------");
System.out.println("procedure registered: io.crossbar.example.client2.add2");
}
});
final int[] counter = { 0 };
final PublishOptions publishOptions = new PublishOptions(true, true);
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(() -> {
CompletableFuture<Publication> pubFuture = session.publish("io.crossbar.example.client2.oncounter", publishOptions, counter[0]);
pubFuture.whenComplete((publication, throwable) -> {
if (throwable == null) {
LOGGER.i("published to 'oncounter' with counter " + counter[0]);
counter[0] += 1;
} else {
LOGGER.i(String.format("ERROR - pub failed: %s", throwable.getMessage()));
}
});
if (!mProduce) {
executorService.shutdown();
try {
POJOCalls();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
System.exit(1);
}
}
}, 0, 2, TimeUnit.SECONDS);
}
use of io.crossbar.autobahn.wamp.types.PublishOptions in project autobahn-java by crossbario.
the class ExampleClient method onJoinCallback.
private void onJoinCallback(Session session, SessionDetails details) {
CompletableFuture<Registration> regFuture = session.register(PROC_ADD2, this::add2);
regFuture.thenAccept(reg -> LOGGER.info("Registered procedure: com.example.add2"));
CompletableFuture<Subscription> subFuture = session.subscribe(TOPIC_COUNTER, this::onCounter);
subFuture.thenAccept(subscription -> LOGGER.info(String.format("Subscribed to topic: %s", subscription.topic)));
final int[] x = { 0 };
final int[] counter = { 0 };
final PublishOptions publishOptions = new PublishOptions(true, false);
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(() -> {
// here we CALL every second
CompletableFuture<CallResult> f = session.call(PROC_ADD2, x[0], 3);
f.whenComplete((callResult, throwable) -> {
if (throwable == null) {
LOGGER.info(String.format("Got result: %s, ", callResult.results.get(0)));
x[0] += 1;
} else {
LOGGER.info(String.format("ERROR - call failed: %s", throwable.getMessage()));
}
});
CompletableFuture<Publication> p = session.publish(TOPIC_COUNTER, publishOptions, counter[0], session.getID(), "Java");
p.whenComplete((publication, throwable) -> {
if (throwable == null) {
LOGGER.info("published to 'oncounter' with counter " + counter[0]);
counter[0] += 1;
} else {
LOGGER.info(String.format("ERROR - pub failed: %s", throwable.getMessage()));
}
});
}, 0, 2, TimeUnit.SECONDS);
}
Aggregations