/** * Add operation to the queue. Fire event when operation is successfully added if fireEvent is true. * If the operation determined by equals is already in the queue, do not add it again. * @param operation The {@code VdcOperation} to add. */ private void addOperationImpl(final VdcOperation<?, ?> operation) { // If the operation is not already in the queue || the operation is an action (allows duplicates). // Then add this operation to the queue, and process the queue immediately. final boolean operationCanBeAdded = !operationQueue.contains(operation) || operation.allowDuplicates(); if (operationCanBeAdded && operationQueue.add(operation)) { processor.processOperation(this); if (engineSessionRefreshed(operation)) { EngineSessionRefreshedEvent.fire(eventBus); } } }
@Override public void onFailure(final List<VdcOperation<?, ?>> operationList, final Throwable exception) { // If the failure is recoverable, then add the request back into the queue. removePending(operationList); VdcOperation<?, ?> originalOperation = getOriginalOperation(operationList.get(0)); // If the operation allows duplicates, it means we shouldn't retry the operation. if (!operationList.get(0).allowDuplicates() && operationList.get(0).getCopyCount() < RETRY_THRESHOLD) { manager.addOperationList(operationList); } else { VdcOperationCallbackList<VdcOperation<?, ?>, Object> originalCallback = (VdcOperationCallbackList<VdcOperation<?, ?>, Object>) originalOperation.getCallback(); originalCallback.onFailure(operationList, exception); } // Finished, check for more operations. processOperation(manager); } };
if (!operation.allowDuplicates() && (pending.contains(operation) || operations.contains(operation))) {
@Override public void onFailure(final VdcOperation<?, ?> operation, final Throwable exception) { // Remove pending, so it won't accidentally stop the re-add if possible. removePending(operation); // If the failure is recoverable, then add the request back into the queue. if (!operation.allowDuplicates() && operation.getCopyCount() < RETRY_THRESHOLD) { manager.addOperation(operation); } else { VdcOperation<?, ?> originalOperation = getOriginalOperation(operation); originalOperation.getCallback().onFailure(originalOperation, exception); } // Finished, check for more operations. processOperation(manager); } };