Search in sources :

Example 11 with ActorServer

use of org.nustaq.kontraktor.remoting.base.ActorServer in project kontraktor by RuedigerMoeller.

the class HttpPublisher method publish.

@Override
public IPromise<ActorServer> publish(Consumer<Actor> disconnectCallback) {
    ActorServer actorServer;
    try {
        Pair<PathHandler, Undertow> serverPair = Http4K.get().getServer(port, hostName);
        UndertowHttpServerConnector con = new UndertowHttpServerConnector(facade);
        con.setConnectionVerifier(connectionVerifier);
        con.setSessionTimeout(sessionTimeout);
        actorServer = new ActorServer(con, facade, coding == null ? new Coding(SerializerType.FSTSer) : coding);
        con.setActorServer(actorServer);
        actorServer.start(disconnectCallback);
        serverPair.getFirst().addPrefixPath(urlPath, con);
    } catch (Exception e) {
        Log.Warn(null, e);
        return new Promise<>(null, e);
    }
    return new Promise<>(actorServer);
}
Also used : Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer) Coding(org.nustaq.kontraktor.remoting.encoding.Coding) PathHandler(io.undertow.server.handlers.PathHandler) Undertow(io.undertow.Undertow)

Example 12 with ActorServer

use of org.nustaq.kontraktor.remoting.base.ActorServer 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 13 with ActorServer

use of org.nustaq.kontraktor.remoting.base.ActorServer in project kontraktor by RuedigerMoeller.

the class RemotingTest method runNio.

public void runNio(Coding coding) throws Exception {
    checkSequenceErrors = true;
    RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
    ActorServer publisher = NIOServerConnector.Publish(service, 8081, coding).await();
    CountDownLatch latch = new CountDownLatch(1);
    runnitTCP(latch, coding);
    latch.await();
    // wait for outstanding callbacks
    Thread.sleep(2000);
    publisher.close();
}
Also used : ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 14 with ActorServer

use of org.nustaq.kontraktor.remoting.base.ActorServer in project kontraktor by RuedigerMoeller.

the class _JSR356ServerConnector method Publish.

public static IPromise<ActorServer> Publish(Actor facade, String path, Coding coding) {
    _JSR356ServerConnector connector = new _JSR356ServerConnector();
    try {
        ActorServer actorServer = new ActorServer(connector, facade, coding);
        actorServer.start();
        ContainerProvider.getWebSocketContainer().connectToServer(connector, /*new DefaultClientEndpointConfig(),*/
        new URI(path));
        return new Promise<>(actorServer);
    } catch (Exception e) {
        e.printStackTrace();
        return new Promise<>(null, e);
    }
}
Also used : Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer) URI(java.net.URI) IOException(java.io.IOException)

Aggregations

ActorServer (org.nustaq.kontraktor.remoting.base.ActorServer)14 CountDownLatch (java.util.concurrent.CountDownLatch)9 Test (org.junit.Test)6 ExecutorService (java.util.concurrent.ExecutorService)4 IPromise (org.nustaq.kontraktor.IPromise)4 Promise (org.nustaq.kontraktor.Promise)4 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)3 IOException (java.io.IOException)2 Coding (org.nustaq.kontraktor.remoting.encoding.Coding)2 HttpConnectable (org.nustaq.kontraktor.remoting.http.HttpConnectable)2 HttpPublisher (org.nustaq.kontraktor.remoting.http.undertow.HttpPublisher)2 WebSocketPublisher (org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher)2 Undertow (io.undertow.Undertow)1 PathHandler (io.undertow.server.handlers.PathHandler)1 EOFException (java.io.EOFException)1 URI (java.net.URI)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Ignore (org.junit.Ignore)1