Search in sources :

Example 6 with ActorServer

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

the class Basics method concloseTest.

public void concloseTest(ActorPublisher publisher, ConnectableActor connectable) throws InterruptedException {
    ActorServer server = KxReactiveStreams.get().produce(IntStream.range(0, NETWORK_MSG)).serve(publisher);
    AtomicInteger cnt = new AtomicInteger(0);
    KxReactiveStreams.get().connect(Integer.class, connectable).subscribe((r, e) -> {
        if (Actors.isResult(e)) {
            cnt.incrementAndGet();
        } else {
            System.out.println("not result r,e = " + r + "," + e);
        }
    });
    System.out.println("thread:" + DispatcherThread.activeDispatchers.get());
    int count = 0;
    while (count < 10 && cnt.get() != NETWORK_MSG) {
        Thread.sleep(1000);
        System.out.println("received msg:" + cnt.get());
        count++;
    }
    Assert.assertTrue(cnt.get() == NETWORK_MSG);
    System.out.println("thread:" + DispatcherThread.activeDispatchers.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 7 with ActorServer

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

the class TCPServerConnector method Publish.

public static Promise<ActorServer> Publish(Actor facade, int port, Coding coding, Consumer<Actor> disconnectCB) {
    Promise finished = new Promise();
    try {
        ActorServer publisher = new ActorServer(new TCPServerConnector(port), facade, coding);
        facade.execute(() -> {
            try {
                publisher.start(disconnectCB);
                finished.resolve(publisher);
            } catch (Exception e) {
                finished.reject(e);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        return new Promise(null, e);
    }
    return finished;
}
Also used : Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 8 with ActorServer

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

Example 9 with ActorServer

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

the class RemotingTest method runtHttp.

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

Example 10 with ActorServer

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

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