protected void onInvoke(final HandlerContext ctx, final Invocation invocation) LocalObjects.LocalObjectEntry localObjectEntry = objects.findLocalObjectByReference(invocation.getToReference()); if (localObjectEntry != null) final Invocation forwardedInvocation = new Invocation() .withToReference(invocation.getToReference()) .withMethod(invocation.getMethod()) .withOneWay(invocation.isOneWay()) .withMethodId(invocation.getMethodId()) .withParams(invocation.getParams()) .withHeaders(invocation.getHeaders() != null ? new LinkedHashMap<>(invocation.getHeaders()) : null); if (invocation.getCompletion() != null) InternalUtils.linkFutures(write, invocation.getCompletion());
public Task<?> writeInvocation(final HandlerContext ctx, Invocation invocation) { final Addressable toReference = invocation.getToReference(); final RemoteReference<?> actorReference = (RemoteReference<?>) toReference; final NodeAddress toNode = invocation.getToNode(); Map<String, Object> actualHeaders = null; if (invocation.getHeaders() != null) { actualHeaders = new HashMap<>(); actualHeaders.putAll(invocation.getHeaders()); } final Message message = new Message() .withMessageType(invocation.isOneWay() ? MessageDefinitions.ONE_WAY_MESSAGE : MessageDefinitions.REQUEST_MESSAGE) .withToNode(toNode) .withFromNode(invocation.getFromNode()) .withHeaders(actualHeaders) .withInterfaceId(actorReference._interfaceId()) .withMessageId(invocation.getMessageId()) .withMethodId(invocation.getMethodId()) .withObjectId(RemoteReference.getId(actorReference)) .withPayload(invocation.getParams()) .withReferenceAddress(invocation.getToReference().address); if (logger.isTraceEnabled()) { logger.trace("sending message to " + toReference); } return writeMessage(ctx, message); }
@SuppressWarnings("unchecked") protected void onInvocation(final HandlerContext ctx, final Invocation invocation) final RemoteReference toReference = invocation.getToReference(); final LocalObjects.LocalObjectEntry<Object> entry = objects.findLocalObjectByReference(toReference); if (entry != null) target -> performInvocation(ctx, invocation, entry, target))); if (invocation.getCompletion() != null) InternalUtils.linkFuturesOnError(result, invocation.getCompletion()); invocation.setHops(invocation.getHops() + 1); if (invocation.getCompletion() != null) invocation.getCompletion().completeExceptionally(new ObserverNotFound("Observer Missing. " + invocation.toString()));
protected void beforeInvoke(Invocation invocation, @Nullable Method method) { if (logger.isDebugEnabled()) { logger.debug("Invoking: {}.{}", invocation.getToReference().toString(), method != null ? method.getName() : invocation.getMethodId()); } }
protected Task<Object> performLocalInvocation(final Invocation invocation, final ObjectInvoker invoker, final LocalObjects.LocalObjectEntry target) { Task result = invoker.safeInvoke(target.getObject(), invocation.getMethodId(), invocation.getParams()); try { // must await to hold the execution serializer await(result); } catch (Throwable ex) { // handled bellow; } if (invocation.getCompletion() != null) { InternalUtils.linkFutures(result, invocation.getCompletion()); } return result; }
final RemoteReference toReference = invocation.getToReference(); if (toReference instanceof NodeCapabilities) Method method = invocation.getMethod(); if (method == null) method = DefaultDescriptorFactory.get().getInvoker(RemoteReference.getInterfaceClass(toReference)).getMethod(invocation.getMethodId()); final Object[] params = invocation.getParams(); if (params != null && params.length > 0) if (invocation.getHeaders() != null) strParams += " " + invocation.getHeaders(); if (!invocation.isOneWay())
protected Task<?> writeInvocation(final HandlerContext ctx, Invocation invocation) final Method method = invocation.getMethod(); final RemoteReference<?> toReference = invocation.getToReference(); if (onlyIfActivateCache.isAnnotated(method)) if (invocation.getToNode() == null) invocation.withToNode(address); if (!activeNodes.containsKey(address)) return Task.fromException(new ObserverNotFound("Node no longer active. " + invocation.toString())); task = ctx.write(invocation.withToNode(address));
private Task onInvocation(final HandlerContext ctx, final Invocation invocation) final RemoteReference toReference = invocation.getToReference(); final NodeAddress localAddress = getNodeAddress(); return locateActor(invocation.getToReference(), true) .whenComplete((r, e) -> { if (e != null) if (invocation.getCompletion() != null) invocation.getCompletion().completeExceptionally(e); final NodeInfo info = activeNodes.get(invocation.getFromNode()); if (info != null && info.state == NodeState.RUNNING) invocation.setHops(invocation.getHops() + 1); invocation.setToNode(r); ctx.write(invocation);
final Invocation invocation = new Invocation(reference, null, messageType == MessageDefinitions.ONE_WAY_MESSAGE, methodId, (Object[]) message.getPayload(), null); invocation.setHeaders(message.getHeaders()); invocation.setFromNode(message.getFromNode()); invocation.setMessageId(messageId); if (!invocation.isOneWay()) invocation.setCompletion(completion);
private Task<?> cacheResponseInvoke(HandlerContext ctx, Invocation invocation) { final String parameterHash = generateParameterHash(invocation.getParams()); final Pair<Addressable, String> key = Pair.of(invocation.getToReference(), parameterHash); final Method method = invocation.getMethod(); Task<?> cached = get(method, key); if (cached == null || cached.isCompletedExceptionally() || cached.isCancelled()) { cached = ctx.write(invocation); put(method, key, cached); } return cached.thenApply((object) -> { if (!CloneHelper.needsCloning(object)) { return object; } return objectCloner.clone(object); }); }
for (InvocationHandlerExtension invocationHandlerExtension : invocationHandlerExtensions) beforeInvokeChain = beforeInvokeChain.thenCompose(() -> invocationHandlerExtension.beforeInvoke(startTimeNanos, target.getObject(), method, invocation.getParams(), invocation.getHeaders())); final Task<Object> invokeResult = invoker.safeInvoke(target.getObject(), invocation.getMethodId(), invocation.getParams()); for (InvocationHandlerExtension invocationHandlerExtension : invocationHandlerExtensions) afterInvokeChain = afterInvokeChain.thenCompose(() -> invocationHandlerExtension.afterInvoke(startTimeNanos, target.getObject(), method, invocation.getParams(), invocation.getHeaders())); for (InvocationHandlerExtension invocationHandlerExtension : invocationHandlerExtensions) afterCompleteChain = afterCompleteChain.thenCompose(() -> invocationHandlerExtension.afterInvokeChain(startTimeNanos, target.getObject(), method, invocation.getParams(), invocation.getHeaders()));
final Method method = invoker.getMethod(invocation.getMethodId()); final boolean reentrant = reentrantCache.isAnnotated(method); if (context != null) if (invocation.getHeaders() != null && invocation.getHeaders().size() > 0 && runtime.getStickyHeaders() != null) invocation.getHeaders().forEach((key, value) -> if (invocation.getCompletion() != null) InternalUtils.linkFutures(invokeResult, invocation.getCompletion());
@SuppressWarnings("unchecked") protected Task<Object> doInvoke(final Stage runtime, final Invocation invocation, final LocalObjects.LocalObjectEntry entry, final LocalObjects.LocalObjectEntry target, final Method method, final Boolean reentrant, final ObjectInvoker invoker) { final long startTimeNanos = System.nanoTime(); beforeInvoke(invocation, method); final Task<Object> invokeResult = invoker.safeInvoke(target.getObject(), invocation.getMethodId(), invocation.getParams()); afterInvoke(startTimeNanos, invocation, method); invokeResult.whenComplete((o, throwable) -> taskComplete(startTimeNanos, invocation, method)); return invokeResult; }
@Override public Task write(final HandlerContext ctx, final Object msg) throws Exception { if (msg instanceof Invocation) { // await checks isDone() await(hostingActive); final Invocation invocation = (Invocation) msg; if (invocation.getFromNode() == null) { // used by subsequent filters invocation.setFromNode(stage.getLocalAddress()); } if (invocation.getToNode() == null) { return writeInvocation(ctx, invocation); } } return ctx.write(msg); }
private Task<Void> onActivate(HandlerContext ctx, final Invocation invocation) { // this must run serialized by the remote reference key. LocalObjects.LocalObjectEntry<Object> entry = objects.findLocalObjectByReference(invocation.getToReference()); if (entry == null) { objects.registerLocalObject(invocation.getToReference()); entry = objects.findLocalObjectByReference(invocation.getToReference()); } // queues the invocation final LocalObjects.LocalObjectEntry<Object> theEntry = entry; final Task result = entry.run(target -> performInvocation(ctx, invocation, theEntry, target)); if (invocation.getCompletion() != null) { InternalUtils.linkFuturesOnError(result, invocation.getCompletion()); } // yielding since we blocked the entry before running on activate (serialized execution) return Task.done(); }
public Task writeInvocation(final HandlerContext ctx, final Invocation invocation) throws Exception { LocalObjects.LocalObjectEntry localObjectEntry = objects.findLocalObjectByReference(invocation.getToReference()); if (localObjectEntry != null) { return scheduleLocalInvocation(localObjectEntry, invocation); } return ctx.write(invocation); }
@Override public Task<?> invoke(final RemoteReference toReference, final Method m, final boolean oneWay, final int methodId, final Object[] params) { if (state == NodeCapabilities.NodeState.STOPPED) { throw new IllegalStateException("Stage is stopped. " + this.toString()); } final Invocation invocation = new Invocation(toReference, m, oneWay, methodId, params, null); // copy stick context valued to the message headers headers final ActorTaskContext context = ActorTaskContext.current(); if (context != null) { Map<String, Object> headers = null; for (final String key : stickyHeaders) { final Object value = context.getProperty(key); if (value != null) { if (headers == null) { headers = new HashMap<>(); } headers.put(key, value); } } invocation.setHeaders(headers); } final Task<Void> result = pipeline.write(invocation); return result; }
@Override public Task write(final HandlerContext ctx, final Object msg) throws Exception { if (msg instanceof Invocation) { final Invocation invocation = (Invocation) msg; if (cacheResponseCache.isAnnotated(invocation.getMethod())) { return cacheResponseInvoke(ctx, invocation); } } return super.write(ctx, msg); }
return Task.fromException(new ObserverNotFound("Observer Missing. " + invocation.toString())); if (invocation.getCompletion() != null) invocation.getCompletion().completeExceptionally(exception);
@Override public Task<?> invoke(final RemoteReference toReference, final Method m, final boolean oneWay, final int methodId, final Object[] params) { final Invocation invocation = new Invocation(toReference, m, oneWay, methodId, params, null); return getPipeline().write(invocation); }