Search in sources :

Example 16 with WebSocketConnectable

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

the class Basics method testConnectionCloseOnCompleteWS.

@Test
public void testConnectionCloseOnCompleteWS() throws InterruptedException {
    WebSocketPublisher publisher = new WebSocketPublisher().hostName("localhost").urlPath("/ws").port(8082);
    ConnectableActor connectable = new WebSocketConnectable().url("ws://localhost:8082/ws");
    concloseTest(publisher, connectable);
}
Also used : WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Test(org.junit.Test)

Example 17 with WebSocketConnectable

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

the class StatelessService method main.

public static void main(String[] args) {
    StatelessServiceArgs conf = new StatelessServiceArgs();
    JCommander.newBuilder().addObject(conf).build().parse(args);
    StatelessService serv = AsActor(StatelessService.class);
    conf.connectUrls.forEach(url -> {
        Routing.registerService(new WebSocketConnectable().url(url).serType(url.endsWith("/bin") ? SerializerType.FSTSer : SerializerType.JsonNoRef), serv, x -> serv.disconnedtedCB(x), false).then((r, e) -> {
            if (e != null) {
                Log.Info(StatelessService.class, "error connecting krouter " + e);
                if (e instanceof Throwable)
                    Log.Info(StatelessService.class, (Throwable) e);
            } else
                Log.Info(StatelessService.class, "SLService connected krouter " + url);
        });
    });
}
Also used : IStatelessService(microservice.pub.IStatelessService) IPromise(org.nustaq.kontraktor.IPromise) SerializerType(org.nustaq.kontraktor.remoting.encoding.SerializerType) Routing(org.nustaq.kontraktor.routers.Routing) JCommander(com.beust.jcommander.JCommander) Actor(org.nustaq.kontraktor.Actor) Log(org.nustaq.kontraktor.util.Log) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Promise(org.nustaq.kontraktor.Promise) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) IStatelessService(microservice.pub.IStatelessService) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 18 with WebSocketConnectable

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

the class KLoadTest method run.

public void run() {
    boolean http = false;
    ConnectableActor connectable;
    if (!http) {
        connectable = new WebSocketConnectable(MyHttpApp.class, "ws://localhost:8080/ws").serType(SerializerType.JsonNoRef);
    } else {
        connectable = new HttpConnectable(MyHttpApp.class, "http://localhost:8080/api").serType(SerializerType.JsonNoRef);
    }
    connectable.connect((connector, error) -> {
        System.out.println("connection lost " + connector);
    }).then((res, err) -> {
        myApp = (MyHttpApp) res;
        myApp.login("dummy", "dummy").then((s, err1) -> {
            session = s;
            System.out.println("session connected " + session);
            session.subscribe((result, e) -> {
                count++;
                lastBcast.set(System.currentTimeMillis());
            });
        });
    });
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) SerializerType(org.nustaq.kontraktor.remoting.encoding.SerializerType) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) MyHttpApp(sample.httpjs.MyHttpApp) HttpClientConnector(org.nustaq.kontraktor.remoting.http.HttpClientConnector) HttpConnectable(org.nustaq.kontraktor.remoting.http.HttpConnectable) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) MyHttpAppSession(sample.httpjs.MyHttpAppSession) ArrayList(java.util.ArrayList) HttpConnectable(org.nustaq.kontraktor.remoting.http.HttpConnectable) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 19 with WebSocketConnectable

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

the class StatelessServiceClient method main.

public static void main(String[] args) {
    if (args == null || args.length == 0) {
        // connect with binary encoding
        StatelessServiceClient cl = AsActor(StatelessServiceClient.class);
        cl.init(new WebSocketConnectable().url("ws://localhost:6667/slservice/v1/bin").serType(SerializerType.FSTSer).actorClass(IStatelessService.class)).then((r, e) -> {
            if (e != null) {
                Log.Error(StatelessServiceClient.class, (Throwable) e);
            }
        });
    } else {
        // connect with json encoding
        StatelessServiceClient cl = AsActor(StatelessServiceClient.class);
        cl.init(new WebSocketConnectable().url("ws://localhost:6667/slservice/v1/json").serType(SerializerType.JsonNoRef).actorClass(IStatelessService.class)).then((r, e) -> {
            if (e != null) {
                Log.Error(StatelessServiceClient.class, (Throwable) e);
            }
        });
    }
}
Also used : WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 20 with WebSocketConnectable

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

the class TestCrashClose method main.

public static void main(String[] args) {
    boolean http = false;
    ConnectableActor connectable;
    if (!http) {
        connectable = new WebSocketConnectable(MyHttpApp.class, "ws://localhost:8080/ws").serType(SerializerType.JsonNoRef);
    } else {
        connectable = new HttpConnectable(MyHttpApp.class, "http://localhost:8080/api").serType(SerializerType.JsonNoRef);
    }
    connectable.connect((connector, error) -> {
        System.out.println("connection lost " + connector);
    }).then((res, err) -> {
        MyHttpApp myApp = (MyHttpApp) res;
        myApp.login("dummy", "dummy").then((s, err1) -> {
            MyHttpAppSession session = s;
            System.out.println("session connected " + session);
            session.subscribe((result, e) -> {
                System.exit(0);
            });
        });
    });
}
Also used : SerializerType(org.nustaq.kontraktor.remoting.encoding.SerializerType) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) MyHttpApp(sample.httpjs.MyHttpApp) HttpConnectable(org.nustaq.kontraktor.remoting.http.HttpConnectable) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) MyHttpAppSession(sample.httpjs.MyHttpAppSession) HttpConnectable(org.nustaq.kontraktor.remoting.http.HttpConnectable) MyHttpApp(sample.httpjs.MyHttpApp) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) MyHttpAppSession(sample.httpjs.MyHttpAppSession) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

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