Search in sources :

Example 1 with Person

use of io.crossbar.autobahn.demogallery.data.Person in project autobahn-java by crossbario.

the class POJOCallExamples method callResultSimplePOJO.

public static CompletableFuture<ExitInfo> callResultSimplePOJO(String wsAddress, String realm) {
    Session wampSession = new Session();
    wampSession.addOnJoinListener((session, details) -> {
        CompletableFuture<Person> callFuture = session.call("com.example.get_person", Person.class);
        callFuture.whenComplete((person, throwable) -> {
            System.out.println(String.format("Person: %s %s in department %s", person.firstname, person.lastname, person.department));
        });
    });
    Client wampClient = new Client(wampSession, wsAddress, realm);
    return wampClient.connect();
}
Also used : Client(io.crossbar.autobahn.wamp.Client) Person(io.crossbar.autobahn.demogallery.data.Person) Session(io.crossbar.autobahn.wamp.Session)

Example 2 with Person

use of io.crossbar.autobahn.demogallery.data.Person in project autobahn-java by crossbario.

the class CIService method POJOCalls.

private void POJOCalls() throws InterruptedException, ExecutionException {
    LOGGER.i("POJOCalls fired");
    // call a remote procedure that returns a Person
    CompletableFuture<Person> f1 = mSession.call("com.example.get_person", Person.class);
    f1.whenCompleteAsync((person, throwable) -> {
        if (throwable != null) {
            LOGGER.i(String.format("get_person() ERROR: %s", throwable.getMessage()));
            System.exit(1);
        } else {
            LOGGER.i(String.format("get_person() [typed]: %s %s (%s)", person.firstname, person.lastname, person.department));
        }
    }, mExecutor);
    // call a remote procedure that returns a Person .. slowly (3 secs delay)
    CompletableFuture<Person> f2 = mSession.call("com.example.get_person_delayed", Person.class);
    f2.whenCompleteAsync((person, throwable) -> {
        if (throwable != null) {
            LOGGER.i(String.format("get_person_delayed() ERROR: %s", throwable.getMessage()));
            System.exit(1);
        } else {
            LOGGER.i(String.format("get_person_delayed() [typed]: %s %s (%s)", person.firstname, person.lastname, person.department));
        }
    }, mExecutor);
    // call a remote procedure that returns a List<Person>
    CompletableFuture<List<Person>> f3 = mSession.call("com.example.get_all_persons", new TypeReference<List<Person>>() {
    });
    f3.whenCompleteAsync((persons, throwable) -> {
        if (throwable != null) {
            LOGGER.i(String.format("get_all_persons() ERROR: %s", throwable.getMessage()));
            System.exit(1);
        } else {
            LOGGER.i("get_all_persons() [typed]:");
            for (Person person : persons) {
                LOGGER.i(String.format("%s %s (%s)", person.firstname, person.lastname, person.department));
            }
        }
    }, mExecutor);
    // call a remote procedure that returns a List<Person>
    List<Object> args = new ArrayList<>();
    args.add("development");
    CompletableFuture<List<Person>> f4 = mSession.call("com.example.get_persons_by_department", args, new TypeReference<List<Person>>() {
    });
    f4.whenCompleteAsync((persons, throwable) -> {
        if (throwable != null) {
            LOGGER.i(String.format("get_persons_by_department() ERROR: %s", throwable.getMessage()));
            System.exit(1);
        } else {
            LOGGER.i("get_persons_by_department() [typed]:");
            for (Person person : persons) {
                LOGGER.i(String.format("%s %s (%s)", person.firstname, person.lastname, person.department));
            }
        }
    }, mExecutor);
    // call a remote procedure that returns a Map<String, List<Person>>
    CompletableFuture<Map<String, List<Person>>> f5 = mSession.call("com.example.get_persons_by_department", new TypeReference<Map<String, List<Person>>>() {
    });
    f5.whenCompleteAsync((persons_by_department, throwable) -> {
        if (throwable != null) {
            LOGGER.i(String.format("get_persons_by_department() ERROR: %s", throwable.getMessage()));
            System.exit(1);
        } else {
            LOGGER.i("get_persons_by_department() [typed]:");
            for (String department : persons_by_department.keySet()) {
                LOGGER.i(String.format("department '%s:'", department));
                List<Person> persons = persons_by_department.get(department);
                for (Person person : persons) {
                    LOGGER.i(String.format("%s %s", person.firstname, person.lastname));
                }
            }
        }
    }, mExecutor);
    CompletableFuture.allOf(f1, f2, f3, f4, f5).thenRunAsync(() -> {
        LOGGER.i("all done!");
        mSession.publish("io.crossbar.example.client2.all_done").whenComplete((publication, throwable) -> mSession.leave("wamp.close.normal", "all done!"));
    }, mExecutor);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Person(io.crossbar.autobahn.demogallery.data.Person) Map(java.util.Map)

Example 3 with Person

use of io.crossbar.autobahn.demogallery.data.Person in project autobahn-java by crossbario.

the class POJOCallExamples method callResultListPOJOs.

public static CompletableFuture<ExitInfo> callResultListPOJOs(String wsAddress, String realm) {
    Session wampSession = new Session();
    wampSession.addOnJoinListener((session, details) -> {
        CompletableFuture<List<Person>> callFuture = session.call("com.example.get_all_persons", new TypeReference<List<Person>>() {
        });
        callFuture.whenComplete((persons, throwable) -> {
            System.out.println(String.format("Got %s persons", persons.size()));
            for (Person p : persons) {
                System.out.println(String.format("Person: %s %s in department %s", p.firstname, p.lastname, p.department));
            }
        });
    });
    Client wampClient = new Client(wampSession, wsAddress, realm);
    return wampClient.connect();
}
Also used : List(java.util.List) Client(io.crossbar.autobahn.wamp.Client) Person(io.crossbar.autobahn.demogallery.data.Person) Session(io.crossbar.autobahn.wamp.Session)

Example 4 with Person

use of io.crossbar.autobahn.demogallery.data.Person in project autobahn-java by crossbario.

the class Service method onJoinHandler4.

private void onJoinHandler4(Session session, SessionDetails details) {
    LOGGER.info("onJoinHandler4 fired");
    // call a remote procedure that returns a Person
    CompletableFuture<Person> f1 = mSession.call("com.example.get_person", Person.class);
    f1.whenCompleteAsync((person, throwable) -> {
        if (throwable != null) {
            LOGGER.info(String.format("get_person() ERROR: %s", throwable.getMessage()));
            System.exit(1);
        } else {
            LOGGER.info(String.format("get_person() [typed]: %s %s (%s)", person.firstname, person.lastname, person.department));
        }
    }, mExecutor);
    // call a remote procedure that returns a Person .. slowly (3 secs delay)
    CompletableFuture<Person> f2 = mSession.call("com.example.get_person_delayed", Person.class);
    f2.whenCompleteAsync((person, throwable) -> {
        if (throwable != null) {
            LOGGER.info(String.format("get_person_delayed() ERROR: %s", throwable.getMessage()));
            System.exit(1);
        } else {
            LOGGER.info(String.format("get_person_delayed() [typed]: %s %s (%s)", person.firstname, person.lastname, person.department));
        }
    }, mExecutor);
    // call a remote procedure that returns a List<Person>
    CompletableFuture<List<Person>> f3 = mSession.call("com.example.get_all_persons", new TypeReference<List<Person>>() {
    });
    f3.whenCompleteAsync((persons, throwable) -> {
        if (throwable != null) {
            LOGGER.info(String.format("get_all_persons() ERROR: %s", throwable.getMessage()));
            System.exit(1);
        } else {
            LOGGER.info("get_all_persons() [typed]:");
            for (Person person : persons) {
                LOGGER.info(String.format("%s %s (%s)", person.firstname, person.lastname, person.department));
            }
        }
    }, mExecutor);
    // call a remote procedure that returns a List<Person>
    List<Object> args = new ArrayList<>();
    args.add("development");
    CompletableFuture<List<Person>> f4 = mSession.call("com.example.get_persons_by_department", args, new TypeReference<List<Person>>() {
    });
    f4.whenCompleteAsync((persons, throwable) -> {
        if (throwable != null) {
            LOGGER.info(String.format("get_persons_by_department() ERROR: %s", throwable.getMessage()));
            System.exit(1);
        } else {
            LOGGER.info("get_persons_by_department() [typed]:");
            for (Person person : persons) {
                LOGGER.info(String.format("%s %s (%s)", person.firstname, person.lastname, person.department));
            }
        }
    }, mExecutor);
    // call a remote procedure that returns a Map<String, List<Person>>
    CompletableFuture<Map<String, List<Person>>> f5 = mSession.call("com.example.get_persons_by_department", new TypeReference<Map<String, List<Person>>>() {
    });
    f5.whenCompleteAsync((persons_by_department, throwable) -> {
        if (throwable != null) {
            LOGGER.info(String.format("get_persons_by_department() ERROR: %s", throwable.getMessage()));
            System.exit(1);
        } else {
            LOGGER.info("get_persons_by_department() [typed]:");
            for (String department : persons_by_department.keySet()) {
                LOGGER.info(String.format("department '%s:'", department));
                List<Person> persons = persons_by_department.get(department);
                for (Person person : persons) {
                    LOGGER.info(String.format("%s %s", person.firstname, person.lastname));
                }
            }
        }
    });
    CompletableFuture.allOf(f1, f2, f3, f4, f5).thenRunAsync(() -> {
        LOGGER.info("all done!");
        mSession.leave("wamp.close.normal", "all done!");
    }, mExecutor);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Person(io.crossbar.autobahn.demogallery.data.Person) Map(java.util.Map)

Example 5 with Person

use of io.crossbar.autobahn.demogallery.data.Person in project autobahn-java by crossbario.

the class ReflectionPOJOCallSample method callReflectionPOJOResult.

public static CompletableFuture<ExitInfo> callReflectionPOJOResult(String wsAddress, String realm) {
    Session wampSession = new Session();
    wampSession.addOnJoinListener((session, details) -> {
        IPOJOServiceProxy proxy = session.getReflectionServices().getCalleeProxy(IPOJOServiceProxy.class);
        CompletableFuture<Person> personFuture = proxy.getPersonAsync();
        personFuture.whenComplete((person, throwable) -> {
            System.out.println(String.format("Person: %s %s in department %s", person.firstname, person.lastname, person.department));
        });
        CompletableFuture<List<Person>> peopleFuture = proxy.getPeopleAsync();
        peopleFuture.whenComplete((persons, throwable) -> {
            System.out.println(String.format("Got %s persons", persons.size()));
            for (Person p : persons) {
                System.out.println(String.format("Person: %s %s in department %s", p.firstname, p.lastname, p.department));
            }
        });
    });
    Client wampClient = new Client(wampSession, wsAddress, realm);
    return wampClient.connect();
}
Also used : List(java.util.List) Client(io.crossbar.autobahn.wamp.Client) Person(io.crossbar.autobahn.demogallery.data.Person) Session(io.crossbar.autobahn.wamp.Session)

Aggregations

Person (io.crossbar.autobahn.demogallery.data.Person)6 Client (io.crossbar.autobahn.wamp.Client)4 Session (io.crossbar.autobahn.wamp.Session)4 List (java.util.List)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)2 Registration (io.crossbar.autobahn.wamp.types.Registration)1 CompletableFuture (java.util.concurrent.CompletableFuture)1