Search in sources :

Example 1 with ForeignClass

use of kontraktor.krouter.service.ForeignClass 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

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