Search in sources :

Example 1 with DummyService

use of kontraktor.krouter.service.DummyService in project kontraktor by RuedigerMoeller.

the class DummyServiceKrouterClient method main.

public static void main(String[] args) {
    // connect to service via Krouter
    DummyService routerClient = (DummyService) Routing.connectClient(new WebSocketConnectable().url("ws://localhost:8888/binary").actorClass(DummyService.class).serType(SerializerType.FSTSer), x -> System.exit(1)).await();
    try {
        // throws exception if not available
        routerClient.ping().await();
    } catch (AwaitException ae) {
        ae.printStackTrace();
        System.exit(1);
    }
    runTest(routerClient);
}
Also used : DummyService(kontraktor.krouter.service.DummyService) AwaitException(org.nustaq.kontraktor.AwaitException) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 2 with DummyService

use of kontraktor.krouter.service.DummyService in project kontraktor by RuedigerMoeller.

the class DummyServiceKrouterClient method basics.

private static void basics(DummyService routerClient, boolean subservice, boolean cyclic) {
    // if ( 1 != 1 )
    {
        routerClient.roundTrip(System.currentTimeMillis()).then((l, e) -> {
            if (l == null)
                System.out.println(e);
            else
                System.out.println("RT " + (System.currentTimeMillis() - (Long) l));
        });
        routerClient.pingForeign(new ForeignClass(2, 4, 6)).then(r -> {
            System.out.println("pingFor:" + r);
        });
        routerClient.subscribe(new ForeignClass(1, 2, 3), (r, e) -> {
            System.out.println("subs " + r + " " + e);
        });
    }
    if (subservice) {
        // subservices only works for sticky krouters (e.g. hotcold,hothot)
        // as with roundrobin the subservice will be created in one instance only
        routerClient.createSubService().then((subserv, err) -> {
            System.out.println("got subservice " + subserv);
            subserv.subMe("XX", (r, e) -> {
                System.out.println("SUBCB " + r + " " + e);
            }).then((r, e) -> {
                System.out.println("SUBPROM " + r + " " + e);
            });
            if (cyclic) {
                String state = "Hello " + Math.random();
                subserv.setState(state);
                new Thread(() -> {
                    while (true) {
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        subserv.getState().then(r -> {
                            if (state.equals(r)) {
                                System.out.println("state ok");
                            } else {
                                System.out.println("WRONG STATE " + r + " my:" + state);
                            }
                        });
                    }
                }).start();
            }
        });
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) LockSupport(java.util.concurrent.locks.LockSupport) IntStream(java.util.stream.IntStream) AwaitException(org.nustaq.kontraktor.AwaitException) SerializerType(org.nustaq.kontraktor.remoting.encoding.SerializerType) Routing(org.nustaq.kontraktor.routers.Routing) ForeignClass(kontraktor.krouter.service.ForeignClass) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) DummyService(kontraktor.krouter.service.DummyService) ForeignClass(kontraktor.krouter.service.ForeignClass)

Aggregations

DummyService (kontraktor.krouter.service.DummyService)2 AwaitException (org.nustaq.kontraktor.AwaitException)2 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)2 TimeUnit (java.util.concurrent.TimeUnit)1 LockSupport (java.util.concurrent.locks.LockSupport)1 IntStream (java.util.stream.IntStream)1 ForeignClass (kontraktor.krouter.service.ForeignClass)1 SerializerType (org.nustaq.kontraktor.remoting.encoding.SerializerType)1 Routing (org.nustaq.kontraktor.routers.Routing)1