use of org.nustaq.kontraktor.Callback in project kontraktor by RuedigerMoeller.
the class UntypedSampleServiceClient method main.
public static void main(String[] args) {
Actor remote = (Actor) new WebSocketConnectable().actorClass(Actor.class).url("ws://localhost:3998").serType(SerializerType.JsonNoRef).connect((x, y) -> System.out.println("disconnect " + x + " " + y)).await();
remote.ask("withPromise", "Hello").then((r, e) -> System.out.println(r + " " + e));
remote.tell("withCallback", "Hi", (Callback) (r, e) -> System.out.println("callback:" + r + " " + e));
remote.ask("withCallbackAndPromise", "Hi CB+P ", (Callback) (r, e) -> System.out.println("callback:" + r + " " + e)).then((r, e) -> System.out.println(r + " " + e));
remote.ask("getSingletonSubservice", "lol").then((subremote, err) -> {
Actor subrem = (Actor) subremote;
subrem.tell("voidFun");
subrem.ask("withCallbackAndPromise", "Hi sub", (Callback) (r, e) -> System.out.println("from sub" + r + " " + e));
});
}
use of org.nustaq.kontraktor.Callback in project kontraktor by RuedigerMoeller.
the class CallbackTest method callbackTest.
@Test
public void callbackTest() throws InterruptedException {
CBTCallActor act = Actors.AsActor(CBTCallActor.class);
act.init();
for (// higher vals create deadlock, detect it !
int i = 0; // higher vals create deadlock, detect it !
i < 10000; // higher vals create deadlock, detect it !
i++) {
act.sendPing();
}
final CBTActor cbt = Actors.AsActor(CBTActor.class);
cbt.pongong((r, e) -> System.out.println(r));
cbt.method(new Callback() {
@Override
public void complete(Object result, Object error) {
System.out.println("Completion Caller Thread:" + result);
System.out.println("Thread:" + Thread.currentThread());
System.out.println("DispThread:" + cbt.__currentDispatcher.getName());
assertTrue(Thread.currentThread() == cbt.__currentDispatcher);
}
});
Thread.sleep(500);
cbt.stop();
act.stop();
assertTrue(errors.get() == 0);
}
Aggregations