Search in sources :

Example 36 with IPromise

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;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) Remoted(org.nustaq.kontraktor.annotations.Remoted)

Example 37 with IPromise

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;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise)

Example 38 with IPromise

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;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) Remoted(org.nustaq.kontraktor.annotations.Remoted)

Example 39 with IPromise

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);
}
Also used : Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) IPromise(org.nustaq.kontraktor.IPromise) Consumer(java.util.function.Consumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 40 with IPromise

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;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) Consumer(java.util.function.Consumer)

Aggregations

IPromise (org.nustaq.kontraktor.IPromise)58 Promise (org.nustaq.kontraktor.Promise)56 Remoted (org.nustaq.kontraktor.annotations.Remoted)6 Actor (org.nustaq.kontraktor.Actor)5 JsonObject (com.eclipsesource.json.JsonObject)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 ByteBuffer (java.nio.ByteBuffer)3 KeyManagementException (java.security.KeyManagementException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Consumer (java.util.function.Consumer)3 TableSpaceActor (org.nustaq.reallive.impl.tablespace.TableSpaceActor)3 JsonValue (com.eclipsesource.json.JsonValue)2 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ArchiveException (org.apache.commons.compress.archivers.ArchiveException)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2