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