Search in sources :

Example 1 with IPromise

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

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

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

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

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