/** * {@inheritDoc} */ @Override public boolean awaitCompletion(long timeout, TimeUnit unit) throws InterruptedException { return super.awaitCompletion(timeout, unit); }
/** * Register an active operation. The operation-id will be generated. * * @param attachment the shared attachment * @return the active operation */ protected <T, A> ActiveOperation<T, A> registerActiveOperation(A attachment) { final ActiveOperation.CompletedCallback<T> callback = getDefaultCallback(); return registerActiveOperation(attachment, callback); }
@Override public boolean done(T result) { try { return ActiveOperationImpl.this.setResult(result); } finally { removeActiveOperation(operationId); } }
/** * Register an active operation. The operation-id will be generated. * * @param attachment the shared attachment * @param callback the completed callback * @return the active operation */ protected <T, A> ActiveOperation<T, A> registerActiveOperation(A attachment, ActiveOperation.CompletedCallback<T> callback) { return registerActiveOperation(null, attachment, callback); }
static <T> ActiveOperation.CompletedCallback<T> getCheckedCallback(final ActiveOperation.CompletedCallback<T> callback) { if(callback == null) { return getDefaultCallback(); } return callback; }
/** * {@inheritDoc} */ @Override public void shutdown() { super.shutdown(); }
/** * Get an active operation. * * @param header the request header * @return the active operation, {@code null} if if there is no registered operation */ protected <T, A> ActiveOperation<T, A> getActiveOperation(final ManagementRequestHeader header) { return getActiveOperation(header.getBatchId()); }
final ActiveOperationImpl<T, A> request = new ActiveOperationImpl<T, A>(operationId, attachment, getCheckedCallback(callback)); final ActiveOperation<?, ?> existing = activeRequests.putIfAbsent(operationId, request); if(existing != null) {
/** * Register an active operation with a specific operation id. * * @param id the operation id * @param attachment the shared attachment * @return the created active operation */ protected <T, A> ActiveOperation<T, A> registerActiveOperation(final Integer id, A attachment) { final ActiveOperation.CompletedCallback<T> callback = getDefaultCallback(); return registerActiveOperation(id, attachment, callback); }
/** * {@inheritDoc} */ @Override protected <T, A> ActiveOperation<T, A> removeActiveOperation(Integer id) { final ActiveOperation<T, A> removed = super.removeActiveOperation(id); if(removed != null) { for(final Map.Entry<Integer, ActiveRequest<?, ?>> requestEntry : requests.entrySet()) { final ActiveRequest<?, ?> request = requestEntry.getValue(); if(request.context == removed) { requests.remove(requestEntry.getKey()); } } } return removed; }
@Override public boolean failed(Exception e) { try { boolean failed = ActiveOperationImpl.this.setFailed(e); if(failed) { ProtocolLogger.ROOT_LOGGER.debugf(e, "active-op (%d) failed %s", operationId, attachment); } return failed; } finally { removeActiveOperation(operationId); } }
@Override public void handleCancelled(AsyncFuture<? extends T> asyncFuture, Object attachment) { removeActiveOperation(operationId); callback.cancelled(); ProtocolLogger.ROOT_LOGGER.debugf("cancelled operation (%d) attachment: (%s) this: %s.", getOperationId(), getAttachment(), ActiveOperationSupport.this); } }, null);