Search in sources :

Example 41 with Promise

use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.

the class PromiseSampleService method getDataSimple.

// //////////////////////////////////////////////////
// these methods are identical ...
public IPromise<String> getDataSimple() {
    Promise result = new Promise();
    result.complete("Data", null);
    return result;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise)

Example 42 with Promise

use of org.nustaq.kontraktor.Promise 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 43 with Promise

use of org.nustaq.kontraktor.Promise 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 44 with Promise

use of org.nustaq.kontraktor.Promise 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 45 with Promise

use of org.nustaq.kontraktor.Promise 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)

Aggregations

Promise (org.nustaq.kontraktor.Promise)67 IPromise (org.nustaq.kontraktor.IPromise)62 Test (org.junit.Test)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Actor (org.nustaq.kontraktor.Actor)6 Remoted (org.nustaq.kontraktor.annotations.Remoted)6 IOException (java.io.IOException)4 Actors (org.nustaq.kontraktor.Actors)4 RateMeasure (org.nustaq.kontraktor.util.RateMeasure)4 JsonObject (com.eclipsesource.json.JsonObject)3 ByteBuffer (java.nio.ByteBuffer)3 KeyManagementException (java.security.KeyManagementException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Consumer (java.util.function.Consumer)3 ActorServer (org.nustaq.kontraktor.remoting.base.ActorServer)3 TCPConnectable (org.nustaq.kontraktor.remoting.tcp.TCPConnectable)3 TableSpaceActor (org.nustaq.reallive.impl.tablespace.TableSpaceActor)3 EOFException (java.io.EOFException)2