Search in sources :

Example 1 with Promise

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

the class WebSocketPublisher method publish.

@Override
public IPromise<ActorServer> publish(Consumer<Actor> disconnectCallback) {
    Promise finished = new Promise();
    try {
        ActorServer publisher = new ActorServer(new UndertowWebsocketServerConnector(urlPath, port, hostName).sendStrings(sendStringMessages).sendSid(sendSid), facade, coding);
        facade.execute(() -> {
            try {
                publisher.start(disconnectCallback);
                finished.resolve(publisher);
            } catch (Exception e) {
                finished.reject(e);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        return new Promise(null, e);
    }
    return finished;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer)

Example 2 with Promise

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

the class JSR356ClientConnector method connect.

@Override
public IPromise connect(Function<ObjectSocket, ObjectSink> factory) throws Exception {
    endpoint = new WSClientEndpoint(uri, null);
    ObjectSink sink = factory.apply(endpoint);
    endpoint.setSink(sink);
    return new Promise<>(null);
}
Also used : Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) ObjectSink(org.nustaq.kontraktor.remoting.base.ObjectSink)

Example 3 with Promise

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

the class WebSocketConnectable method connect.

@Override
public <T extends Actor> IPromise<T> connect(Callback<ActorClientConnector> disconnectCallback, Consumer<Actor> actorDisconnecCB) {
    if (actorClass == null) {
        throw new RuntimeException("pls specify actor clazz to connect to");
    }
    Promise result = new Promise();
    Runnable connect = () -> {
        JSR356ClientConnector client = null;
        try {
            client = new JSR356ClientConnector(url);
            ActorClient connector = new ActorClient(client, actorClass, coding);
            connector.connect(inboundQueueSize, actorDisconnecCB).then(result);
        } catch (URISyntaxException e) {
            e.printStackTrace();
            result.reject(e);
        }
    };
    if (!Actor.inside()) {
        JSR356ClientConnector.get().execute(() -> Thread.currentThread().setName("JSR356WS singleton remote client actor polling"));
        JSR356ClientConnector.get().execute(connect);
    } else
        connect.run();
    return result;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) ActorClient(org.nustaq.kontraktor.remoting.base.ActorClient) URISyntaxException(java.net.URISyntaxException)

Example 4 with Promise

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

the class ReactAppSession method loadSessionData.

@Override
protected IPromise loadSessionData(String sessionId, ISessionStorage storage) {
    Promise res = new Promise();
    Log.Info(this, "loadSessionData " + sessionId);
    // let's cache the record of current user (take care => stale state in case of multiple clients from same user)
    storage.getUser(getUserKey()).then((user, err) -> {
        if (user != null) {
            userRecord = user;
            res.resolve(userRecord);
        } else {
            res.reject(err);
        }
    });
    return res;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise)

Example 5 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)

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