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);
}
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));
}
});
}
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);
}
}
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);
}
}
Aggregations