use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class ReactAppSession method createTokenLink.
@Remoted
public IPromise<String> createTokenLink() {
Promise res = new Promise();
getSessionStorage().createToken(new ISessionStorage.Token(userKey, "hello", 60_000l)).then((s, err) -> {
if (s != null)
res.resolve("direct/" + s);
else
res.reject(err);
});
return res;
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class Greeter method greet.
public IPromise<String> greet(String name, long duration) {
Promise res = new Promise();
delayed(duration, () -> res.resolve("Hello " + name));
return res;
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class ReactApp method register.
@Remoted
public IPromise register(String nick, String pwd, String text) {
Promise p = new Promise();
sessionStorage.putUserIfNotPresent(MapRecord.New(nick).put("pwd", pwd).put("text", text).put("verified", true)).then((r, e) -> {
if (!r) {
p.reject("user " + nick + " already exists");
} else {
p.resolve(true);
}
});
return p;
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class BasicTest method testTimeoutEarlyRegister.
@Test
public void testTimeoutEarlyRegister() throws InterruptedException {
AtomicInteger count = new AtomicInteger(0);
IPromise p = new Promise().timeoutIn(1000);
p.then(new Callback() {
@Override
public void complete(Object result, Object error) {
System.out.println("res:" + result + " err:" + error);
count.incrementAndGet();
}
}).onTimeout(new Consumer() {
@Override
public void accept(Object o) {
count.addAndGet(8);
System.out.println("the EXPECTED timout");
}
});
Thread.sleep(2000);
assertTrue(count.get() == 9);
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class Routing method registerService.
/**
* publish and register a service at a remote Krouter
*
* @param connectable - the krouter to connect
* @param service - the service to publish
* @param disconnectCallback
* @return
*/
public static IPromise<Object> registerService(ConnectableActor connectable, Actor service, Consumer<Actor> disconnectCallback, boolean stateful) {
Promise p = promise();
service.getActor().zzRoutingGCEnabled = true;
service.getActorRef().zzRoutingGCEnabled = true;
if (connectable.getActorClass() == null) {
connectable.actorClass(Krouter.class);
}
service.execute(() -> {
connectable.connect(null, (Consumer<Actor>) disconnectCallback).then((r, e) -> {
if (r != null) {
try {
((AbstractKrouter) r).router$RegisterService(service.getUntypedRef(), stateful).await();
} catch (Exception ex) {
p.complete(null, ex);
return;
}
}
p.complete(r, e);
});
});
return p;
}
Aggregations