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