Search in sources :

Example 16 with TCPConnectable

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");
}
Also used : TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) TCPPublisher(org.nustaq.kontraktor.remoting.tcp.TCPPublisher) Test(org.junit.Test)

Example 17 with TCPConnectable

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();
}
Also used : TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) IntStream(java.util.stream.IntStream) org.nustaq.reallive.api(org.nustaq.reallive.api) Ignore(org.junit.Ignore) TableSpaceActor(org.nustaq.reallive.impl.tablespace.TableSpaceActor) Assert(junit.framework.Assert) TableSpaceSharding(org.nustaq.reallive.impl.tablespace.TableSpaceSharding) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Actors(org.nustaq.kontraktor.Actors) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher) Test(org.junit.Test) Supplier(java.util.function.Supplier) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) TableSpaceSharding(org.nustaq.reallive.impl.tablespace.TableSpaceSharding) TableSpaceActor(org.nustaq.reallive.impl.tablespace.TableSpaceActor) Test(org.junit.Test)

Example 18 with TCPConnectable

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());
}
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 19 with TCPConnectable

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);
}
Also used : JCommander(com.beust.jcommander.JCommander) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) IOException(java.io.IOException) File(java.io.File) HashSet(java.util.HashSet)

Example 20 with TCPConnectable

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));
}
Also used : TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable)

Aggregations

TCPConnectable (org.nustaq.kontraktor.remoting.tcp.TCPConnectable)25 Test (org.junit.Test)9 TCPNIOPublisher (org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Actors (org.nustaq.kontraktor.Actors)5 Promise (org.nustaq.kontraktor.Promise)4 TCPPublisher (org.nustaq.kontraktor.remoting.tcp.TCPPublisher)4 RateMeasure (org.nustaq.kontraktor.util.RateMeasure)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)3 JCommander (com.beust.jcommander.JCommander)2 UnknownHostException (java.net.UnknownHostException)2 Date (java.util.Date)2 TimeUnit (java.util.concurrent.TimeUnit)2 Actor (org.nustaq.kontraktor.Actor)2 IPromise (org.nustaq.kontraktor.IPromise)2 KxPublisher (org.nustaq.kontraktor.reactivestreams.KxPublisher)2 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)2 HttpConnectable (org.nustaq.kontraktor.remoting.http.HttpConnectable)2 WebSocketPublisher (org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher)2