public <R> Task<R> execute(Supplier<Task<R>> taskSupplier) { final Task<R> completion = new Task<>(); if ((maxQueueSize > 0 && queueSize >= maxQueueSize) || !queue.add(() -> { Task<R> source = InternalUtils.safeInvoke(taskSupplier); InternalUtils.linkFutures(source, completion); return source; })) { throw new IllegalStateException(String.format("Queue full (%d > %d)", queue.size(), maxQueueSize)); } queueSizeUpdater.incrementAndGet(this); tryDrainQueue(); return completion; }
@Override public <R> Task<R> executeSerialized(Supplier<Task<R>> taskSupplier, int maxQueueSize) { final Task<R> completion = new Task<>(); int queueSize = size; if (DEBUG_ENABLED && queueSize >= maxQueueSize / 10) { logger.debug("Queued " + queueSize + " / " + maxQueueSize + " for " + key); } if (queueSize >= maxQueueSize || !queue.add(() -> { Task<R> source = InternalUtils.safeInvoke(taskSupplier); InternalUtils.linkFutures(source, completion); return source; })) { return Task.fromException(new IllegalStateException(String.format("Queue full for %s (%d > %d)", key, queue.size(), maxQueueSize))); } // managing the size like this to avoid using ConcurrentLinkedQueue.size() sizeUpdater.incrementAndGet(this); tryExecute(false); return completion; }
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; }
if (invocation.getCompletion() != null) InternalUtils.linkFutures(write, invocation.getCompletion());
InternalUtils.linkFutures(invokeResult, invocation.getCompletion());