private Task cleanupObservers() { localObjects.stream() .filter(e -> e.getValue() instanceof ObserverEntry && e.getValue().getObject() == null) .forEach(e -> localObjects.remove(e.getKey(), e.getValue())); return Task.done(); }
if (previous != null && localObject != previous) if (!Objects.equals(reference, previous.getRemoteReference())) }).getRemoteReference();
if (target == null || target.isDeactivated()) return Task.fromValue(null); if (target.getObject() == null) final ObjectInvoker invoker = DefaultDescriptorFactory.get().getInvoker(target.getObject().getClass()); return invocationHandler.invoke(runtime, invocation, entry, target, invoker);
target.updateLastAccessTime(); context.setDefaultExecutor(r -> entry.run(o ->
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()));
if (entry != null) final Task<Object> result = InternalUtils.safeInvoke(() -> entry.run( target -> performInvocation(ctx, invocation, entry, target)));
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(); }
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; }
/** * @return the result of the method called */ @SuppressWarnings("unchecked") public Task scheduleLocalInvocation(final LocalObjects.LocalObjectEntry<Object> localObjectEntry, final Invocation invocation) { ObjectInvoker invoker = runtime.getInvoker(RemoteReference.getInterfaceId(invocation.getToReference())); return localObjectEntry.run(target -> performLocalInvocation(invocation, invoker, target) ); }
@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; }
private void onRemoval(final Object key, final LocalObjectEntry value, final RemovalCause removalCause) { if (removalCause == RemovalCause.COLLECTED) { if (value != null && value.getRemoteReference() != null) { localObjects.remove(value.getRemoteReference()); } } }