@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; }
final Object[] params = invocation.getParams(); if (params != null && params.length > 0)
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; }
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()));
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); }
.withOneWay(invocation.isOneWay()) .withMethodId(invocation.getMethodId()) .withParams(invocation.getParams()) .withHeaders(invocation.getHeaders() != null ? new LinkedHashMap<>(invocation.getHeaders()) : null);
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); }); }