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;
}
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);
}
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();
}
Aggregations