use of org.nustaq.kontraktor.remoting.tcp.TCPConnectable 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.TCPConnectable in project kontraktor by RuedigerMoeller.
the class TableSpaceTest method simpleShardedNoServer.
@Test
public void simpleShardedNoServer() {
TableSpaceActor[] spaces = { null, null };
spaces[0] = (TableSpaceActor) new TCPConnectable(TableSpaceActor.class, "localhost", 5432).connect((disc, err) -> System.out.println("client disc " + disc + " " + err)).await();
spaces[1] = (TableSpaceActor) new TCPConnectable(TableSpaceActor.class, "localhost", 5433).connect((disc, err) -> System.out.println("client disc " + disc + " " + err)).await();
for (int i = 0; i < spaces.length; i++) {
TableSpaceActor space = spaces[i];
space.init();
}
TableSpaceSharding ts = new TableSpaceSharding(spaces, key -> Math.abs(key.hashCode()) % spaces.length);
Assert.assertTrue(runSimpleTest(ts, () -> createShardedTableDescription()) == EXPECT_SIMPLECOUNT);
ts.shutDown().await();
}
use of org.nustaq.kontraktor.remoting.tcp.TCPConnectable 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.TCPConnectable in project kontraktor by RuedigerMoeller.
the class StarterClient method run.
public void run(String[] args) throws Exception {
if (args.length >= 1 && args[args.length - 1].endsWith(".kson")) {
final StarterClientArgs options = new StarterClientArgs();
final JCommander jCommander = new JCommander(options);
parseStarterConf(args, options, jCommander);
options.underride(ProcessStarter.locateProps(0, new File("./"), "troll.properties"));
// special to process a whole cluster definition from a file (quite a quick hack)
HashSet<String> groups = new HashSet<>();
for (int i = 0; i < options.getParameters().size() - 1; i++) {
String arg = options.getParameters().get(i);
groups.add(arg);
}
KlusterConf klusterConf = new KlusterConf(groups, args[args.length - 1]);
if (klusterConf.getToStart().size() == 0) {
System.out.println("no processes found in " + args[0]);
System.exit(0);
}
klusterConf.getToStart().forEach(proc -> {
System.out.println("will try " + proc.getGroup() + " " + proc.getProcessShortName());
});
try {
ProcessStarter starter = (ProcessStarter) new TCPConnectable(ProcessStarter.class, options.getHost(), options.getPort()).connect((x, y) -> System.out.println("client disc " + x), act -> {
System.out.println("act " + act);
}).await();
klusterConf.getToStart().forEach(opts -> {
try {
runProc(opts, starter);
} catch (IOException e) {
e.printStackTrace();
}
});
starter.ping().await();
} catch (Throwable th) {
System.out.println("could not connect " + th + " host:" + options.getHost() + " " + options.getPort());
System.exit(-1);
}
} else {
final StarterClientArgs options = new StarterClientArgs();
final JCommander jCommander = new JCommander(options);
parseStarterConf(args, options, jCommander);
options.underride(ProcessStarter.locateProps());
if (options.isHelp()) {
jCommander.usage();
System.exit(0);
}
try {
ProcessStarter starter = (ProcessStarter) new TCPConnectable(ProcessStarter.class, options.getHost(), options.getPort()).connect((x, y) -> System.out.println("client disc " + x), act -> {
System.out.println("act " + act);
}).await();
runProc(options, starter);
starter.ping().await();
} catch (Throwable th) {
System.out.println("could not connect " + th + " host:" + options.getHost() + " " + options.getPort());
System.exit(-1);
}
}
System.exit(0);
}
use of org.nustaq.kontraktor.remoting.tcp.TCPConnectable in project kontraktor by RuedigerMoeller.
the class CBSampleClient method main.
public static void main(String[] args) {
CBSampleServer server = (CBSampleServer) new TCPConnectable().actorClass(CBSampleServer.class).serType(SerializerType.FSTSer).host("localhost").port(9090).connect((connector, actor) -> System.out.println("disconnected from server")).await();
server.withCallback("beep", (res, err) -> System.out.println("res:" + res + " err:" + err));
server.timePing(10, (time, err) -> System.out.println("time:" + time + " err:" + err));
}
Aggregations