use of org.nustaq.kontraktor.annotations.CallerSideMethod in project kontraktor by RuedigerMoeller.
the class AbstractKrouter method forwardMultiCallInternal.
// tweak handling such it can deal with double results, runs in caller thread (but single threaded => remoteref registry)
@CallerSideMethod
protected void forwardMultiCallInternal(RemoteCallEntry rceIn, Actor remoteRef, ConnectionRegistry clientRemoteRegistry, boolean[] done, Callback[] selected) {
RemoteCallEntry rce = rceIn.createCopy();
Runnable toRun = () -> {
ConnectionRegistry serviceRemoteReg = remoteRef.__self.__clientConnection;
if (// targets krouter facade
rce.getReceiverKey() == 1)
rce.setReceiverKey(remoteRef.__remoteId);
if (rce.getFutureKey() != 0) {
long prevFuturekey = rce.getFutureKey();
Promise p = new Promise();
long cbid = serviceRemoteReg.registerPublishedCallback(p);
rce.setFutureKey(-cbid);
p.then((r, e) -> {
self().execute(() -> {
serviceRemoteReg.removePublishedObject(cbid);
// websocket close is unreliable
if (serviceRemoteReg.isTerminated()) {
handleServiceDiscon(remoteRef);
return;
}
if (!done[0]) {
done[0] = true;
RemoteCallEntry cbrce = (RemoteCallEntry) r;
cbrce.setReceiverKey(prevFuturekey);
clientRemoteRegistry.forwardRemoteMessage(cbrce);
}
});
});
}
if (rce.getCB() != null) {
Callback cb = rce.getCB();
CallbackWrapper[] wrapperTrick = { null };
CallbackWrapper wrapper = wrapperTrick[0] = new CallbackWrapper(self(), (r, e) -> {
if (selected[0] == null) {
selected[0] = wrapperTrick[0];
}
if (selected[0] == wrapperTrick[0])
cb.complete(r, e);
});
rce.setCB(wrapper);
}
// websocket close is unreliable
if (!serviceRemoteReg.isTerminated())
serviceRemoteReg.forwardRemoteMessage(rce);
else {
handleServiceDiscon(remoteRef);
}
};
if (Thread.currentThread() != getCurrentDispatcher())
self().execute(toRun);
else
toRun.run();
}
use of org.nustaq.kontraktor.annotations.CallerSideMethod in project kontraktor by RuedigerMoeller.
the class AbstractKrouter method __dispatchRemoteCall.
@Override
@CallerSideMethod
public boolean __dispatchRemoteCall(ObjectSocket objSocket, RemoteCallEntry rce, // registry of client connection
ConnectionRegistry clientRemoteRegistry, List<IPromise> createdFutures, Object authContext, BiFunction<Actor, String, Boolean> callInterceptor) {
boolean isCB = rce.getMethod() != null;
if (isCB && rce.getMethod().startsWith("router$")) {
return super.__dispatchRemoteCall(objSocket, rce, clientRemoteRegistry, createdFutures, authContext, callInterceptor);
}
// if ( isCB ) {
// getActor().responseCounter.count();
// } else {
// getActor().requestCounter.count();
// }
// getActor().trafficCounter.count(rce.getSerializedArgs().length);
boolean success = dispatchRemoteCall(rce, clientRemoteRegistry);
if (!success) {
if (rce.getCB() != null) {
rce.getCB().reject(SERVICE_UNAVAILABLE);
}
if (rce.getFutureKey() != 0) {
RemoteCallEntry cbrce = createErrorPromiseResponse(rce, clientRemoteRegistry);
clientRemoteRegistry.inFacadeThread(() -> {
clientRemoteRegistry.forwardRemoteMessage(cbrce);
});
}
}
return false;
}
use of org.nustaq.kontraktor.annotations.CallerSideMethod in project kontraktor by RuedigerMoeller.
the class HotColdFailoverKrouter method setRemoteRef.
@CallerSideMethod
protected void setRemoteRef(Actor remoteRef) {
ArrayList services = new ArrayList();
services.add(remoteRef);
services.addAll(getActor().remoteServices);
getActor().remoteServices = services;
Log.Info(this, "service added. #services " + services.size());
}
use of org.nustaq.kontraktor.annotations.CallerSideMethod in project kontraktor by RuedigerMoeller.
the class ChangeStream method subscribeOn.
@CallerSideMethod
default Subscriber subscribeOn(String query, ChangeReceiver receiver) throws QParseException {
Subscriber subs = new Subscriber(new QueryPredicate(query), receiver);
this.subscribe(subs);
return subs;
}
use of org.nustaq.kontraktor.annotations.CallerSideMethod in project kontraktor by RuedigerMoeller.
the class KxPublisher method stream.
@CallerSideMethod
default void stream(int batchSize, Consumer<Stream<T>> streamingCode) {
if (Actor.inside()) {
try {
Stream<T> stream = getKxStreamsInstance().stream(KxPublisher.this, batchSize);
streamingCode.accept(stream);
} catch (Throwable ce) {
Subscription subscription = KxSubscriber.subsToCancel.get();
if (subscription != null)
subscription.cancel();
throw ce;
}
} else {
new Thread("Stream Consumer") {
@Override
public void run() {
try {
Stream<T> stream = getKxStreamsInstance().stream(KxPublisher.this, batchSize);
streamingCode.accept(stream);
} catch (Throwable ce) {
Subscription subscription = KxSubscriber.subsToCancel.get();
if (subscription != null)
subscription.cancel();
throw ce;
}
}
}.start();
}
}
Aggregations