Search in sources :

Example 6 with RemoteCallEntry

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;
}
Also used : RemoteCallEntry(org.nustaq.kontraktor.remoting.encoding.RemoteCallEntry) CallerSideMethod(org.nustaq.kontraktor.annotations.CallerSideMethod)

Example 7 with RemoteCallEntry

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;
}
Also used : RemoteCallEntry(org.nustaq.kontraktor.remoting.encoding.RemoteCallEntry) CallerSideMethod(org.nustaq.kontraktor.annotations.CallerSideMethod)

Aggregations

RemoteCallEntry (org.nustaq.kontraktor.remoting.encoding.RemoteCallEntry)7 CallerSideMethod (org.nustaq.kontraktor.annotations.CallerSideMethod)5 java.util (java.util)2 BiFunction (java.util.function.BiFunction)2 org.nustaq.kontraktor (org.nustaq.kontraktor)2 Local (org.nustaq.kontraktor.annotations.Local)2 CallbackWrapper (org.nustaq.kontraktor.impl.CallbackWrapper)2 org.nustaq.kontraktor.remoting.base (org.nustaq.kontraktor.remoting.base)2 CallbackRefSerializer (org.nustaq.kontraktor.remoting.encoding.CallbackRefSerializer)2 Log (org.nustaq.kontraktor.util.Log)2