Search in sources :

Example 21 with WebSocketConnectable

use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable 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 22 with WebSocketConnectable

use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.

the class RemotingTest method runWS.

public void runWS(Coding coding) throws InterruptedException {
    checkSequenceErrors = true;
    RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
    ActorServer publisher = new WebSocketPublisher(service, "localhost", "/ws", 8081).coding(coding).publish().await();
    RemotingTestService client = (RemotingTestService) new WebSocketConnectable(RemotingTestService.class, "ws://localhost:8081/ws").coding(coding).connect().await(9999999);
    CountDownLatch latch = new CountDownLatch(1);
    runWithClient(client, latch);
    latch.await();
    // wait for outstanding callbacks
    Thread.sleep(2000);
    publisher.close();
}
Also used : ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) CountDownLatch(java.util.concurrent.CountDownLatch) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 23 with WebSocketConnectable

use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.

the class RemotingTest method testWSMany.

@Test
public void testWSMany() throws Exception {
    checkSequenceErrors = false;
    RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
    ActorServer publisher = new WebSocketPublisher(service, "localhost", "/ws", 8081).publish().await();
    RemotingTestService client = (RemotingTestService) new WebSocketConnectable(RemotingTestService.class, "ws://localhost:8081/ws").connect().await(9999999);
    ExecutorService exec = Executors.newCachedThreadPool();
    CountDownLatch latch = new CountDownLatch(10);
    for (int i = 0; i < 10; i++) {
        exec.execute(() -> {
            try {
                runWithClient(client, latch);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
    latch.await();
    // wait for outstanding callbacks
    Thread.sleep(2000);
    publisher.close();
}
Also used : ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Test(org.junit.Test)

Example 24 with WebSocketConnectable

use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.

the class JSServerClient method main.

public static void main(String[] args) {
    WebSocketConnectable webSocketConnectable = new WebSocketConnectable(BrowseriBabelify.class, "ws://localhost:3998/").serType(SerializerType.JsonNoRef).actorClass(JSServerClient.class);
    JSServerClient remote = (JSServerClient) webSocketConnectable.connect().await();
    remote.withCallback("java", (r, e) -> System.out.println(r + " " + e));
}
Also used : WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 25 with WebSocketConnectable

use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.

the class RemotingTest method test.

@Test
public void test() {
    RemotingTA serv = Actors.AsActor(RemotingTA.class);
    // websocket
    WebSocketPublisher pub = new WebSocketPublisher().facade(serv).hostName("0.0.0.0").urlPath("/websocket").port(7777).serType(SerializerType.FSTSer);
    pub.publish().await();
    WebSocketConnectable con = new WebSocketConnectable().actorClass(RemotingTA.class).url("ws://localhost:7777/websocket");
    fromRemote(con);
    // TCP NIO
    new TCPNIOPublisher(serv, 7778).publish().await();
    fromRemote(new TCPConnectable(RemotingTA.class, "localhost", 7778));
    // TCP Sync
    new TCPPublisher(serv, 7780).publish().await();
    fromRemote(new TCPConnectable(RemotingTA.class, "localhost", 7780));
    // Http-Longpoll
    new HttpPublisher(serv, "0.0.0.0", "/httpapi", 7779).publish().await();
    fromRemote(new HttpConnectable(RemotingTA.class, "http://localhost:7779/httpapi"));
}
Also used : HttpConnectable(org.nustaq.kontraktor.remoting.http.HttpConnectable) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) HttpPublisher(org.nustaq.kontraktor.remoting.http.undertow.HttpPublisher) TCPPublisher(org.nustaq.kontraktor.remoting.tcp.TCPPublisher) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Test(org.junit.Test)

Aggregations

WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)25 Test (org.junit.Test)10 WebSocketPublisher (org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 RateMeasure (org.nustaq.kontraktor.util.RateMeasure)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 SerializerType (org.nustaq.kontraktor.remoting.encoding.SerializerType)6 Log (org.nustaq.kontraktor.util.Log)6 Assert (org.junit.Assert)5 Ignore (org.junit.Ignore)5 Actor (org.nustaq.kontraktor.Actor)5 Actors (org.nustaq.kontraktor.Actors)5 KxPublisher (org.nustaq.kontraktor.reactivestreams.KxPublisher)5 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)5 HttpConnectable (org.nustaq.kontraktor.remoting.http.HttpConnectable)5 Publisher (org.reactivestreams.Publisher)5 RxReactiveStreams (rx.RxReactiveStreams)5 ActorSystem (akka.actor.ActorSystem)4 ActorMaterializer (akka.stream.ActorMaterializer)4 ActorMaterializerSettings (akka.stream.ActorMaterializerSettings)4