Search in sources :

Example 1 with HttpConnectable

use of org.nustaq.kontraktor.remoting.http.HttpConnectable in project kontraktor by RuedigerMoeller.

the class HelloClient method main.

public static void main(String[] args) {
    org.nustaq.kontraktor.remoting.base.ConnectableActor[] connectables = { new WebSocketConnectable(HelloActor.class, "http://localhost:8080/hello").serType(SerializerType.FSTSer), new HttpConnectable(HelloActor.class, "http://localhost:8080/hellohttp").serType(SerializerType.JsonNoRefPretty), new TCPConnectable(HelloActor.class, "localhost", 6789) };
    stream(connectables).forEach(connectable -> {
        HelloActor remote = (HelloActor) connectable.connect((res, err) -> System.out.println(connectable + " disconnected !")).await();
        remote.getMyName().then(name -> {
            System.out.println(connectable.getClass().getSimpleName() + " " + name);
        });
    });
}
Also used : HttpConnectable(org.nustaq.kontraktor.remoting.http.HttpConnectable) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 2 with HttpConnectable

use of org.nustaq.kontraktor.remoting.http.HttpConnectable in project kontraktor by RuedigerMoeller.

the class MyJavaClient method main.

public static void main(String[] args) {
    boolean http = false;
    MyHttpApp remoteApp;
    if (http) {
        HttpClientConnector.DumpProtocol = true;
        remoteApp = (MyHttpApp) new HttpConnectable(MyHttpApp.class, "http://localhost:8080/api").serType(SerializerType.JsonNoRefPretty).connect().await();
    } else {
        // dev only
        JSR356ClientConnector.DumpProtocol = true;
        remoteApp = (MyHttpApp) new WebSocketConnectable(MyHttpApp.class, "ws://localhost:8080/ws").serType(SerializerType.JsonNoRefPretty).connect().await();
    }
    MyHttpAppSession session = remoteApp.login("someuser", "apwd").await();
    session.getToDo().then(list -> {
        list.forEach(System.out::println);
    });
    session.streamToDo("p", (r, e) -> System.out.println(r + " " + e));
}
Also used : HttpConnectable(org.nustaq.kontraktor.remoting.http.HttpConnectable) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 3 with HttpConnectable

use of org.nustaq.kontraktor.remoting.http.HttpConnectable 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 4 with HttpConnectable

use of org.nustaq.kontraktor.remoting.http.HttpConnectable 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)

Example 5 with HttpConnectable

use of org.nustaq.kontraktor.remoting.http.HttpConnectable in project kontraktor by RuedigerMoeller.

the class RemotingTest method testHttpMany.

@Test
public void testHttpMany() throws Exception {
    checkSequenceErrors = false;
    RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
    ActorServer publisher = new HttpPublisher(service, "localhost", "/lp", 8082).publish().await();
    RemotingTestService client = (RemotingTestService) new HttpConnectable(RemotingTestService.class, "http://localhost:8082/lp").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 : HttpConnectable(org.nustaq.kontraktor.remoting.http.HttpConnectable) ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer) HttpPublisher(org.nustaq.kontraktor.remoting.http.undertow.HttpPublisher) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

HttpConnectable (org.nustaq.kontraktor.remoting.http.HttpConnectable)7 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)5 HttpPublisher (org.nustaq.kontraktor.remoting.http.undertow.HttpPublisher)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 ActorServer (org.nustaq.kontraktor.remoting.base.ActorServer)2 ConnectableActor (org.nustaq.kontraktor.remoting.base.ConnectableActor)2 SerializerType (org.nustaq.kontraktor.remoting.encoding.SerializerType)2 TCPConnectable (org.nustaq.kontraktor.remoting.tcp.TCPConnectable)2 MyHttpApp (sample.httpjs.MyHttpApp)2 MyHttpAppSession (sample.httpjs.MyHttpAppSession)2 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 HttpClientConnector (org.nustaq.kontraktor.remoting.http.HttpClientConnector)1 WebSocketPublisher (org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher)1 TCPNIOPublisher (org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)1 TCPPublisher (org.nustaq.kontraktor.remoting.tcp.TCPPublisher)1