Search in sources :

Example 1 with ActorServer

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

the class WebSocketPublisher method publish.

@Override
public IPromise<ActorServer> publish(Consumer<Actor> disconnectCallback) {
    Promise finished = new Promise();
    try {
        ActorServer publisher = new ActorServer(new UndertowWebsocketServerConnector(urlPath, port, hostName).sendStrings(sendStringMessages).sendSid(sendSid), facade, coding);
        facade.execute(() -> {
            try {
                publisher.start(disconnectCallback);
                finished.resolve(publisher);
            } catch (Exception e) {
                finished.reject(e);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        return new Promise(null, e);
    }
    return finished;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer)

Example 2 with ActorServer

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

the class RemotingTest method testBlockingMany.

@Test
public void testBlockingMany() throws Exception {
    checkSequenceErrors = false;
    RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
    ActorServer publisher = TCPServerConnector.Publish(service, 8081, null).await();
    ExecutorService exec = Executors.newCachedThreadPool();
    CountDownLatch latch = new CountDownLatch(10);
    for (int i = 0; i < 10; i++) {
        exec.execute(() -> {
            try {
                runnitTCP(latch, null);
            } 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) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with ActorServer

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

the class RemotingTest method testWSJSR.

// fixme: add connect-from-actor tests
// fixme: add minbin tests
// fixme: increase basic test coverage
@Test
@Ignore
public void testWSJSR() throws Exception {
    checkSequenceErrors = true;
    RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
    ActorServer publisher = _JSR356ServerConnector.Publish(service, "ws://localhost:8081/ws", null).await();
    RemotingTestService client = (RemotingTestService) new WebSocketConnectable(RemotingTestService.class, "ws://localhost:8081/ws").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) CountDownLatch(java.util.concurrent.CountDownLatch) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with ActorServer

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

the class RemotingTest method testNIOMany.

@Test
public void testNIOMany() throws Exception {
    checkSequenceErrors = false;
    RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
    ActorServer publisher = NIOServerConnector.Publish(service, 8081, null).await();
    ExecutorService exec = Executors.newCachedThreadPool();
    CountDownLatch latch = new CountDownLatch(10);
    for (int i = 0; i < 10; i++) {
        exec.execute(() -> {
            try {
                runnitTCP(latch, null);
            } 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) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with ActorServer

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

the class RemotingTest method testBlocking.

@Test
public void testBlocking() throws Exception {
    checkSequenceErrors = true;
    RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
    Coding coding = new Coding(SerializerType.FSTSer);
    ActorServer publisher = TCPServerConnector.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) Coding(org.nustaq.kontraktor.remoting.encoding.Coding) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

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