Search in sources :

Example 1 with TCPPublisher

use of org.nustaq.kontraktor.remoting.tcp.TCPPublisher in project kontraktor by RuedigerMoeller.

the class Java8Streams method remoteJava8EndlessStreams.

// just manual
@Test
// just manual
@org.junit.Ignore
public <T> void remoteJava8EndlessStreams() throws InterruptedException {
    EventSink sink = new EventSink();
    sink.serve(new TCPPublisher().port(8125));
    runTimeClient("c1");
    runTimeClient("c2");
    runTimeClient("c3");
    for (int i = 0; i < 1000; i++) {
        while (!sink.offer(new Date())) {
            Thread.sleep(1);
        }
        Thread.sleep(1000);
    }
}
Also used : TCPPublisher(org.nustaq.kontraktor.remoting.tcp.TCPPublisher) EventSink(org.nustaq.kontraktor.reactivestreams.EventSink) Date(java.util.Date) Test(org.junit.Test)

Example 2 with TCPPublisher

use of org.nustaq.kontraktor.remoting.tcp.TCPPublisher in project kontraktor by RuedigerMoeller.

the class Java8Streams method remoteJava8Streams.

/**
 * stream a java 8 stream via network
 *
 * @throws InterruptedException
 */
public <T> int remoteJava8Streams(Function<MyEvent, T> doStuff, int port) throws InterruptedException {
    AtomicInteger validCount = new AtomicInteger(-1);
    KxReactiveStreams kxReactiveStreams = KxReactiveStreams.get();
    kxReactiveStreams.produce(IntStream.range(0, 5_000_000).mapToObj(i -> new MyEvent(i, Math.random(), "Hello" + i))).serve(new TCPPublisher().port(port));
    CountDownLatch latch = new CountDownLatch(1);
    RateMeasure measure = new RateMeasure("rate");
    KxReactiveStreams.get().connect(MyEvent.class, new TCPConnectable().host("localhost").port(port)).stream(stream -> {
        long count = 0;
        try {
            count = stream.map(event -> {
                measure.count();
                return doStuff.apply(event);
            }).count();
        } finally {
            System.out.println("Count:" + count);
            validCount.set((int) count);
            latch.countDown();
        }
    });
    latch.await();
    return validCount.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) TCPPublisher(org.nustaq.kontraktor.remoting.tcp.TCPPublisher) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with TCPPublisher

use of org.nustaq.kontraktor.remoting.tcp.TCPPublisher in project kontraktor by RuedigerMoeller.

the class Basics method testConnectionCloseOnCompleteTCP.

@Test
public void testConnectionCloseOnCompleteTCP() throws InterruptedException {
    TCPPublisher publisher = new TCPPublisher().port(7855);
    TCPConnectable connectable = new TCPConnectable().host("localhost").port(7855);
    concloseTest(publisher, connectable);
    Thread.sleep(TCPServerConnector.DELAY_MS_TILL_CLOSE + 100);
    Assert.assertTrue(TCPServerConnector.numberOfThreads.get() == 0);
    System.out.println("debug");
}
Also used : TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) TCPPublisher(org.nustaq.kontraktor.remoting.tcp.TCPPublisher) Test(org.junit.Test)

Example 4 with TCPPublisher

use of org.nustaq.kontraktor.remoting.tcp.TCPPublisher in project kontraktor by RuedigerMoeller.

the class Basics method testConnectionCloseOnCompleteWithSink.

@Test
public void testConnectionCloseOnCompleteWithSink() throws InterruptedException {
    EventSink<Integer> sink = new EventSink<>();
    sink.serve(new TCPPublisher().port(7850));
    AtomicInteger cnt = new AtomicInteger(0);
    KxReactiveStreams.get().connect(Integer.class, new TCPConnectable().host("localhost").port(7850)).subscribe((r, e) -> {
        if (Actors.isResult(e)) {
            cnt.incrementAndGet();
        } else {
            System.out.println("not result " + r + " " + e);
        }
    });
    for (int i = 0; i < 100_000; i++) {
        while (!sink.offer(i)) {
            Thread.yield();
        }
    }
    sink.complete();
    System.out.println("received:" + cnt.get());
    Thread.sleep(1000);
    System.out.println("received:" + cnt.get());
    Assert.assertTrue(cnt.get() == 100_000);
    System.out.println("count:" + DispatcherThread.activeDispatchers.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) TCPPublisher(org.nustaq.kontraktor.remoting.tcp.TCPPublisher) EventSink(org.nustaq.kontraktor.reactivestreams.EventSink) Test(org.junit.Test)

Example 5 with TCPPublisher

use of org.nustaq.kontraktor.remoting.tcp.TCPPublisher in project kontraktor by RuedigerMoeller.

the class RemotingTest method test.

@Test
public void test() {
    RemotingTA serv = Actors.AsActor(RemotingTA.class);
    // websocket
    WebSocketPublisher pub = new WebSocketPublisher().facade(serv).hostName("0.0.0.0").urlPath("/websocket").port(7777).serType(SerializerType.FSTSer);
    pub.publish().await();
    WebSocketConnectable con = new WebSocketConnectable().actorClass(RemotingTA.class).url("ws://localhost:7777/websocket");
    fromRemote(con);
    // TCP NIO
    new TCPNIOPublisher(serv, 7778).publish().await();
    fromRemote(new TCPConnectable(RemotingTA.class, "localhost", 7778));
    // TCP Sync
    new TCPPublisher(serv, 7780).publish().await();
    fromRemote(new TCPConnectable(RemotingTA.class, "localhost", 7780));
    // Http-Longpoll
    new HttpPublisher(serv, "0.0.0.0", "/httpapi", 7779).publish().await();
    fromRemote(new HttpConnectable(RemotingTA.class, "http://localhost:7779/httpapi"));
}
Also used : HttpConnectable(org.nustaq.kontraktor.remoting.http.HttpConnectable) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) HttpPublisher(org.nustaq.kontraktor.remoting.http.undertow.HttpPublisher) TCPPublisher(org.nustaq.kontraktor.remoting.tcp.TCPPublisher) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Test(org.junit.Test)

Aggregations

TCPPublisher (org.nustaq.kontraktor.remoting.tcp.TCPPublisher)5 Test (org.junit.Test)4 TCPConnectable (org.nustaq.kontraktor.remoting.tcp.TCPConnectable)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EventSink (org.nustaq.kontraktor.reactivestreams.EventSink)2 Date (java.util.Date)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)1 HttpConnectable (org.nustaq.kontraktor.remoting.http.HttpConnectable)1 HttpPublisher (org.nustaq.kontraktor.remoting.http.undertow.HttpPublisher)1 WebSocketPublisher (org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher)1 TCPNIOPublisher (org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)1 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)1 RateMeasure (org.nustaq.kontraktor.util.RateMeasure)1