use of org.nustaq.kontraktor.annotations.CallerSideMethod in project kontraktor by RuedigerMoeller.
the class Actor method __addStopHandler.
// //////////////////////////// internals ///////////////////////////////////////////////////////////////////
@CallerSideMethod
public void __addStopHandler(Callback<SELF> cb) {
if (__stopHandlers == null) {
getActorRef().__stopHandlers = new ConcurrentLinkedQueue();
getActor().__stopHandlers = getActorRef().__stopHandlers;
}
__stopHandlers.add(cb);
}
use of org.nustaq.kontraktor.annotations.CallerSideMethod in project kontraktor by RuedigerMoeller.
the class KxPublisher method iterator.
@CallerSideMethod
default void iterator(int batchSize, Consumer<Iterator<T>> iteratingCode) {
if (Actor.inside()) {
try {
iteratingCode.accept(getKxStreamsInstance().iterator(KxPublisher.this, batchSize));
} catch (Throwable ce) {
Subscription subscription = KxSubscriber.subsToCancel.get();
subscription.cancel();
throw ce;
}
} else {
new Thread("Iterator Consumer") {
@Override
public void run() {
try {
iteratingCode.accept(getKxStreamsInstance().iterator(KxPublisher.this, batchSize));
} catch (Throwable ce) {
Subscription subscription = KxSubscriber.subsToCancel.get();
subscription.cancel();
throw ce;
}
}
}.start();
}
}
use of org.nustaq.kontraktor.annotations.CallerSideMethod 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.annotations.CallerSideMethod 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;
}
use of org.nustaq.kontraktor.annotations.CallerSideMethod in project kontraktor by RuedigerMoeller.
the class Actor method __getCachedMethod.
@CallerSideMethod
public Method __getCachedMethod(String methodName, Actor actor, BiFunction<Actor, String, Boolean> callInterceptor) {
// assumption: only remote calls can be intercepted, interceptor != null => remote call
if (callInterceptor != null) {
if (interceptedCache == null) {
interceptedCache = new ConcurrentHashMap(7);
}
} else {
if (methodCache == null) {
methodCache = new ConcurrentHashMap(7);
}
}
ConcurrentHashMap mcache = callInterceptor != null ? interceptedCache : methodCache;
Method method = (Method) mcache.get(methodName);
if (method == null) {
Method[] methods = actor.getActor().getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
Method m = methods[i];
if (m.getName().equals(methodName)) {
if (callInterceptor == null || callInterceptor.apply(actor, methodName)) {
mcache.put(methodName, m);
method = m;
break;
}
}
}
}
return method;
}
Aggregations