@Override public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception { final TimeTrace trace = client.getZookeeperClient().startTracer("ExistsBuilderImpl-Background"); AsyncCallback.StatCallback callback = new AsyncCallback.StatCallback() { @Override public void processResult(int rc, String path, Object ctx, Stat stat) { trace.commit(); CuratorEvent event = new CuratorEventImpl( CuratorEventType.EXISTS, rc, path, null, ctx, stat, null, null, null, null); client.processBackgroundOperation(operationAndData, event); } }; if (watching.isWatched()) { client .getZooKeeper() .exists(operationAndData.getData(), true, callback, backgrounding.getContext()); } else { client .getZooKeeper() .exists( operationAndData.getData(), watching.getWatcher(), callback, backgrounding.getContext()); } }
private <DATA_TYPE> void handleBackgroundOperationException( OperationAndData<DATA_TYPE> operationAndData, Throwable e) { do { if ((operationAndData != null) && RetryLoop.isRetryException(e)) { if (!Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES)) { log.debug("Retry-able exception received", e); } if (client .getRetryPolicy() .allowRetry( operationAndData.getThenIncrementRetryCount(), operationAndData.getElapsedTimeMs(), operationAndData)) { if (!Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES)) { log.debug("Retrying operation"); } backgroundOperations.offer(operationAndData); break; } else { if (!Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES)) { log.debug("Retry policy did not allow retry"); } if (operationAndData.getErrorCallback() != null) { operationAndData.getErrorCallback().retriesExhausted(operationAndData); } } } logError("Background exception was not retry-able or retry gave up", e); } while (false); }
@SuppressWarnings({"ThrowableResultOfMethodCallIgnored"}) <DATA_TYPE> void processBackgroundOperation( OperationAndData<DATA_TYPE> operationAndData, CuratorEvent event) { boolean isInitialExecution = (event == null); if (isInitialExecution) { performBackgroundOperation(operationAndData); return; } boolean doQueueOperation = false; do { if (RetryLoop.shouldRetry(event.getResultCode())) { if (client .getRetryPolicy() .allowRetry( operationAndData.getThenIncrementRetryCount(), operationAndData.getElapsedTimeMs(), operationAndData)) { doQueueOperation = true; } else { if (operationAndData.getErrorCallback() != null) { operationAndData.getErrorCallback().retriesExhausted(operationAndData); } KeeperException.Code code = KeeperException.Code.get(event.getResultCode()); Exception e = null; try { e = (code != null) ? KeeperException.create(code) : null; } catch (Throwable ignore) { } if (e == null) { e = new Exception("Unknown result code: " + event.getResultCode()); } logError("Background operation retry gave up", e); } break; } if (operationAndData.getCallback() != null) { sendToBackgroundCallback(operationAndData, event); break; } processEvent(event); } while (false); if (doQueueOperation) { queueOperation(operationAndData); } }
private void performBackgroundOperation(OperationAndData<?> operationAndData) { try { operationAndData.callPerformBackgroundOperation(); } catch (Throwable e) { handleBackgroundOperationException(operationAndData, e); } }
private <DATA_TYPE> void sendToBackgroundCallback( OperationAndData<DATA_TYPE> operationAndData, CuratorEvent event) { try { operationAndData.getCallback().processResult(this, event); } catch (Exception e) { handleBackgroundOperationException(operationAndData, e); } }