Search in sources :

Example 6 with Callback

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));
    });
}
Also used : Callback(org.nustaq.kontraktor.Callback) SerializerType(org.nustaq.kontraktor.remoting.encoding.SerializerType) Actor(org.nustaq.kontraktor.Actor) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Callback(org.nustaq.kontraktor.Callback) Actor(org.nustaq.kontraktor.Actor) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 7 with Callback

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);
}
Also used : Callback(org.nustaq.kontraktor.Callback) Test(org.junit.Test)

Aggregations

Callback (org.nustaq.kontraktor.Callback)7 Test (org.junit.Test)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 LockSupport (java.util.concurrent.locks.LockSupport)4 Ignore (org.junit.Ignore)4 EventSink (org.nustaq.kontraktor.reactivestreams.EventSink)4 KxPublisher (org.nustaq.kontraktor.reactivestreams.KxPublisher)4 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)4 ActorClientConnector (org.nustaq.kontraktor.remoting.base.ActorClientConnector)4 ActorPublisher (org.nustaq.kontraktor.remoting.base.ActorPublisher)4 ConnectableActor (org.nustaq.kontraktor.remoting.base.ConnectableActor)4 org.nustaq.kontraktor.remoting.tcp (org.nustaq.kontraktor.remoting.tcp)4 org.nustaq.kontraktor.util (org.nustaq.kontraktor.util)4 Actor (org.nustaq.kontraktor.Actor)1 IPromise (org.nustaq.kontraktor.IPromise)1 Promise (org.nustaq.kontraktor.Promise)1 SerializerType (org.nustaq.kontraktor.remoting.encoding.SerializerType)1 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)1