use of org.nustaq.kontraktor.remoting.encoding.RemoteCallEntry in project kontraktor by RuedigerMoeller.
the class AbstractKrouter method createErrorPromiseResponse.
@CallerSideMethod
protected RemoteCallEntry createErrorPromiseResponse(RemoteCallEntry rce, ConnectionRegistry clientRemoteRegistry) {
RemoteCallEntry cbrce = new RemoteCallEntry();
cbrce.setReceiverKey(rce.getFutureKey());
cbrce.setSerializedArgs(clientRemoteRegistry.getConf().asByteArray(new Object[] { null, SERVICE_UNAVAILABLE }));
cbrce.setQueue(1);
return cbrce;
}
use of org.nustaq.kontraktor.remoting.encoding.RemoteCallEntry in project kontraktor by RuedigerMoeller.
the class Actor method __dispatchRemoteCall.
/**
* called if a message invokation from remote is received
* @return true if a new promise has been created
*/
@CallerSideMethod
public boolean __dispatchRemoteCall(ObjectSocket objSocket, RemoteCallEntry rce, ConnectionRegistry registry, List<IPromise> createdFutures, Object authContext, BiFunction<Actor, String, Boolean> callInterceptor) {
rce.unpackArgs(registry.getConf());
try {
Object future = getScheduler().enqueueCallFromRemote(registry, null, self(), rce.getMethod(), rce.getArgs(), false, null, callInterceptor);
if (future instanceof IPromise) {
Promise p = null;
if (createdFutures != null) {
p = new Promise();
createdFutures.add(p);
}
final Promise finalP = p;
final RemoteCallEntry finalRce = rce;
((IPromise) future).then((r, e) -> {
Runnable runnable = () -> {
try {
registry.receiveCBResult(objSocket, finalRce.getFutureKey(), r, e);
if (finalP != null)
finalP.resolve();
} catch (Exception ex) {
Log.Warn(this, ex, "--");
}
};
if (Thread.currentThread() != __currentDispatcher)
self().execute(runnable);
else
runnable.run();
});
}
} catch (Throwable th) {
Log.Warn(this, th);
if (rce.getFutureKey() != 0) {
self().execute(() -> {
try {
registry.receiveCBResult(objSocket, rce.getFutureKey(), null, FSTUtil.toString(th));
} catch (Exception e) {
Log.Error(this, e);
}
});
} else {
FSTUtil.<RuntimeException>rethrow(th);
}
}
return createdFutures != null && createdFutures.size() > 0;
}
Aggregations