@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 validateConnection(CuratorEvent curatorEvent) { if (curatorEvent.getType() == CuratorEventType.WATCHED) { if (curatorEvent.getWatchedEvent().getState() == Watcher.Event.KeeperState.Disconnected) { connectionStateManager.addStateChange(ConnectionState.SUSPENDED); internalSync( this, "/", null); // we appear to have disconnected, force a new ZK event and see if we can connect // to another server } else if (curatorEvent.getWatchedEvent().getState() == Watcher.Event.KeeperState.Expired) { connectionStateManager.addStateChange(ConnectionState.LOST); } else if (curatorEvent.getWatchedEvent().getState() == Watcher.Event.KeeperState.SyncConnected) { connectionStateManager.addStateChange(ConnectionState.RECONNECTED); } else if (curatorEvent.getWatchedEvent().getState() == Watcher.Event.KeeperState.ConnectedReadOnly) { connectionStateManager.addStateChange(ConnectionState.READ_ONLY); } } }