Search in sources :

Example 6 with Registration

use of io.crossbar.autobahn.wamp.types.Registration in project autobahn-java by crossbario.

the class ReflectionServices method registerCallee.

public List<CompletableFuture<Registration>> registerCallee(Object instance) {
    List<CompletableFuture<Registration>> registrations = new ArrayList<CompletableFuture<Registration>>();
    Class<?> classType = instance.getClass();
    for (Method method : classType.getMethods()) {
        if (method.isAnnotationPresent(WampProcedure.class)) {
            CompletableFuture<Registration> currentRegistration = RegisterSingleMethod(instance, method);
            registrations.add(currentRegistration);
        }
    }
    for (Class<?> interfaceType : classType.getInterfaces()) {
        for (Method method : interfaceType.getMethods()) {
            if (method.isAnnotationPresent(WampProcedure.class)) {
                CompletableFuture<Registration> currentRegistration = RegisterSingleMethod(instance, method);
                registrations.add(currentRegistration);
            }
        }
    }
    return registrations;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Registration(io.crossbar.autobahn.wamp.types.Registration) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method)

Example 7 with Registration

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

Example 8 with Registration

use of io.crossbar.autobahn.wamp.types.Registration in project autobahn-java by crossbario.

the class ReflectionPOJORegisterSample method registerReflectionPOJO.

public static CompletableFuture<ExitInfo> registerReflectionPOJO(String wsAddress, String realm) {
    Session wampSession = new Session();
    wampSession.addOnJoinListener((session, details) -> {
        final IPOJOService service = new IPOJOService() {

            @Override
            public Person getPerson() {
                return new Person("john", "doe", "hr");
            }

            @Override
            public List<Person> getPeople() {
                List<Person> persons = new ArrayList<>();
                for (int i = 0; i < 7; i++) {
                    persons.add(new Person("john", "doe", "hr"));
                }
                return persons;
            }
        };
        List<CompletableFuture<Registration>> registrations = session.getReflectionServices().registerCallee(service);
        for (CompletableFuture<Registration> registrationCompletableFuture : registrations) {
            registrationCompletableFuture.whenComplete((registration, throwable) -> {
                System.out.println(String.format("Registered procedure %s", registration.procedure));
            });
        }
    });
    Client wampClient = new Client(wampSession, wsAddress, realm);
    return wampClient.connect();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Registration(io.crossbar.autobahn.wamp.types.Registration) ArrayList(java.util.ArrayList) Client(io.crossbar.autobahn.wamp.Client) Person(io.crossbar.autobahn.demogallery.data.Person) Session(io.crossbar.autobahn.wamp.Session)

Aggregations

Registration (io.crossbar.autobahn.wamp.types.Registration)8 CompletableFuture (java.util.concurrent.CompletableFuture)4 Client (io.crossbar.autobahn.wamp.Client)3 Session (io.crossbar.autobahn.wamp.Session)3 Publication (io.crossbar.autobahn.wamp.types.Publication)3 PublishOptions (io.crossbar.autobahn.wamp.types.PublishOptions)3 ArrayList (java.util.ArrayList)3 Register (io.crossbar.autobahn.wamp.messages.Register)2 RegisterRequest (io.crossbar.autobahn.wamp.requests.RegisterRequest)2 RegisterOptions (io.crossbar.autobahn.wamp.types.RegisterOptions)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Person (io.crossbar.autobahn.demogallery.data.Person)1 ABLogger (io.crossbar.autobahn.utils.ABLogger)1 IABLogger (io.crossbar.autobahn.utils.IABLogger)1 ChallengeResponseAuth (io.crossbar.autobahn.wamp.auth.ChallengeResponseAuth)1 CryptosignAuth (io.crossbar.autobahn.wamp.auth.CryptosignAuth)1 TicketAuth (io.crossbar.autobahn.wamp.auth.TicketAuth)1 ApplicationError (io.crossbar.autobahn.wamp.exceptions.ApplicationError)1 ProtocolError (io.crossbar.autobahn.wamp.exceptions.ProtocolError)1 IAuthenticator (io.crossbar.autobahn.wamp.interfaces.IAuthenticator)1