Search in sources :

Example 1 with RegisterOptions

use of io.crossbar.autobahn.wamp.types.RegisterOptions 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);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Registration(io.crossbar.autobahn.wamp.types.Registration) Publication(io.crossbar.autobahn.wamp.types.Publication) PublishOptions(io.crossbar.autobahn.wamp.types.PublishOptions) ExecutionException(java.util.concurrent.ExecutionException) RegisterOptions(io.crossbar.autobahn.wamp.types.RegisterOptions)

Aggregations

Publication (io.crossbar.autobahn.wamp.types.Publication)1 PublishOptions (io.crossbar.autobahn.wamp.types.PublishOptions)1 RegisterOptions (io.crossbar.autobahn.wamp.types.RegisterOptions)1 Registration (io.crossbar.autobahn.wamp.types.Registration)1 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1