Search in sources :

Example 6 with KxPublisher

use of org.nustaq.kontraktor.reactivestreams.KxPublisher in project kontraktor by RuedigerMoeller.

the class AkkaInterop method kontraktorRemoteKontraktor.

@Test
public void kontraktorRemoteKontraktor() throws InterruptedException {
    Log.setLevel(Log.DEBUG);
    final int NUM_MSG = 20_000_000;
    KxReactiveStreams kxStreams = KxReactiveStreams.get();
    RateMeasure rm = new RateMeasure("rate");
    CountDownLatch count = new CountDownLatch(NUM_MSG);
    Iterable it = () -> IntStream.range(0, NUM_MSG).mapToObj(x -> x).iterator();
    Publisher<Integer> pub = kxStreams.produce(it.iterator());
    kxStreams.asKxPublisher(pub).serve(new WebSocketPublisher().hostName("localhost").port(6789).urlPath("not_akka"));
    // subscribe with akka client
    KxPublisher<Integer> remotedPublisher = new KxReactiveStreams(true).connect(Integer.class, new WebSocketConnectable().url("ws://localhost:6789/not_akka"));
    remotedPublisher.subscribe((res, err) -> {
        if (Actors.isResult(err)) {
            rm.count();
            count.countDown();
        }
    });
    int secondsWait = 50;
    while (count.getCount() > 0 && secondsWait-- > 0) {
        System.out.println("count:" + count.getCount());
        Thread.sleep(1000);
    }
    Assert.assertTrue(count.getCount() == 0);
    // give time closing stuff
    Thread.sleep(1000);
}
Also used : IntStream(java.util.stream.IntStream) ActorMaterializerSettings(akka.stream.ActorMaterializerSettings) PublisherSink(akka.stream.impl.PublisherSink) Publisher(org.reactivestreams.Publisher) Source(akka.stream.javadsl.Source) Sink(akka.stream.javadsl.Sink) Materializer(akka.stream.Materializer) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) SubscriberSink(akka.stream.impl.SubscriberSink) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) CountDownLatch(java.util.concurrent.CountDownLatch) ActorMaterializer(akka.stream.ActorMaterializer) RxReactiveStreams(rx.RxReactiveStreams) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActorSystem(akka.actor.ActorSystem) Log(org.nustaq.kontraktor.util.Log) Actors(org.nustaq.kontraktor.Actors) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) CountDownLatch(java.util.concurrent.CountDownLatch) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Test(org.junit.Test)

Example 7 with KxPublisher

use of org.nustaq.kontraktor.reactivestreams.KxPublisher in project kontraktor by RuedigerMoeller.

the class KxStreamProvidingClient method main.

public static void main(String[] args) {
    // FIXME: cancel test. No error on connection close delivered.
    KxStreamServer remoteRef = (KxStreamServer) new TCPConnectable(KxStreamServer.class, "localhost", 7890).connect().await();
    remoteRef.putStream("SomeNumbers", KxReactiveStreams.get().produce(LongStream.range(13, 139)), false);
    // await based variant of subscribing timer (compare with other client):
    KxPublisher timer = remoteRef.listen("TIME").await();
    // could also subscribe with arbitrary RxStreams subscriber.
    // as RxPublisher extends reactivestreams.Publisher
    timer.subscribe((time, err) -> {
        if (Actors.isError(err)) {
            System.out.println("error:" + err);
        } else if (Actors.isComplete(err)) {
            // should not happen as infinite stream
            System.out.println("complete. connection closed ?");
        } else {
            System.out.println("received:" + new Date((Long) time));
        }
    });
}
Also used : TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) Date(java.util.Date)

Example 8 with KxPublisher

use of org.nustaq.kontraktor.reactivestreams.KxPublisher in project kontraktor by RuedigerMoeller.

the class TCPNIOKStreamsTest method testClient3.

// cleanup of async processors
@Test
// cleanup of async processors
@Ignore
public void testClient3() throws InterruptedException {
    AtomicLong received = new AtomicLong(0);
    Callback<ActorClientConnector> discon = (acc, err) -> {
        System.out.println("Client disconnected");
    };
    KxPublisher<String> remote = get().connect(String.class, getRemoteConnector(), discon).await();
    RateMeasure ms = new RateMeasure("event rate");
    remote.map(string -> string.length()).map(number -> number > 10 ? number : number).subscribe((str, err) -> {
        if (isComplete(err)) {
            System.out.println("complete");
        } else if (isError(err)) {
            System.out.println("ERROR " + err);
        } else {
            received.incrementAndGet();
            ms.count();
        }
    });
    while (true) {
        Thread.sleep(100);
    }
}
Also used : ActorPublisher(org.nustaq.kontraktor.remoting.base.ActorPublisher) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) org.nustaq.kontraktor.util(org.nustaq.kontraktor.util) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) EventSink(org.nustaq.kontraktor.reactivestreams.EventSink) Callback(org.nustaq.kontraktor.Callback) LockSupport(java.util.concurrent.locks.LockSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) Ignore(org.junit.Ignore) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) org.nustaq.kontraktor.remoting.tcp(org.nustaq.kontraktor.remoting.tcp) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with KxPublisher

use of org.nustaq.kontraktor.reactivestreams.KxPublisher in project kontraktor by RuedigerMoeller.

the class TCPNIOKStreamsTest method testClient2.

// slowdown
@Test
// slowdown
@Ignore
public void testClient2() throws InterruptedException {
    AtomicLong received = new AtomicLong(0);
    Callback<ActorClientConnector> discon = (acc, err) -> {
        System.out.println("Client disconnected");
    };
    KxPublisher<String> remote = get().connect(String.class, getRemoteConnector(), discon).await();
    RateMeasure ms = new RateMeasure("event rate");
    remote.syncMap(string -> string.length()).syncMap(number -> number > 10 ? number : number).subscribe((str, err) -> {
        if (isErrorOrComplete(err)) {
            System.out.println("complete");
        } else if (isError(err)) {
            System.out.println("ERROR");
        } else {
            received.incrementAndGet();
            ms.count();
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
    while (true) {
        Thread.sleep(100);
    }
}
Also used : ActorPublisher(org.nustaq.kontraktor.remoting.base.ActorPublisher) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) org.nustaq.kontraktor.util(org.nustaq.kontraktor.util) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) EventSink(org.nustaq.kontraktor.reactivestreams.EventSink) Callback(org.nustaq.kontraktor.Callback) LockSupport(java.util.concurrent.locks.LockSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) Ignore(org.junit.Ignore) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) org.nustaq.kontraktor.remoting.tcp(org.nustaq.kontraktor.remoting.tcp) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

KxPublisher (org.nustaq.kontraktor.reactivestreams.KxPublisher)9 Test (org.junit.Test)8 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)8 Ignore (org.junit.Ignore)7 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 LockSupport (java.util.concurrent.locks.LockSupport)4 Assert (org.junit.Assert)4 Actors (org.nustaq.kontraktor.Actors)4 Callback (org.nustaq.kontraktor.Callback)4 EventSink (org.nustaq.kontraktor.reactivestreams.EventSink)4 ActorClientConnector (org.nustaq.kontraktor.remoting.base.ActorClientConnector)4 ActorPublisher (org.nustaq.kontraktor.remoting.base.ActorPublisher)4 ConnectableActor (org.nustaq.kontraktor.remoting.base.ConnectableActor)4 WebSocketPublisher (org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher)4 org.nustaq.kontraktor.remoting.tcp (org.nustaq.kontraktor.remoting.tcp)4 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)4 org.nustaq.kontraktor.util (org.nustaq.kontraktor.util)4 RateMeasure (org.nustaq.kontraktor.util.RateMeasure)4