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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations