private void backgroundOperationsLoop() { try { while ( state.get() == CuratorFrameworkState.STARTED ) { OperationAndData<?> operationAndData; try { operationAndData = backgroundOperations.take(); if ( debugListener != null ) { debugListener.listen(operationAndData); } performBackgroundOperation(operationAndData); } catch ( InterruptedException e ) { // swallow the interrupt as it's only possible from either a background // operation and, thus, doesn't apply to this loop or the instance // is being closed in which case the while test will get it } } } finally { log.info("backgroundOperationsLoop exiting"); } }
protected void internalSync(CuratorFrameworkImpl impl, String path, Object context) { BackgroundOperation<String> operation = new BackgroundSyncImpl(impl, context); performBackgroundOperation(new OperationAndData<String>(operation, path, null, null, context, null)); }
<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()) ) { doQueueOperation = checkBackgroundRetry(operationAndData, event); break; } if ( operationAndData.getCallback() != null ) { sendToBackgroundCallback(operationAndData, event); break; } processEvent(event); } while ( false ); if ( doQueueOperation ) { queueOperation(operationAndData); } }
private void backgroundOperationsLoop() { try { while ( state.get() == CuratorFrameworkState.STARTED ) { OperationAndData<?> operationAndData; try { operationAndData = backgroundOperations.take(); if ( debugListener != null ) { debugListener.listen(operationAndData); } performBackgroundOperation(operationAndData); } catch ( InterruptedException e ) { // swallow the interrupt as it's only possible from either a background // operation and, thus, doesn't apply to this loop or the instance // is being closed in which case the while test will get it } } } finally { log.info("backgroundOperationsLoop exiting"); } }
private void backgroundOperationsLoop() { try { while ( state.get() == CuratorFrameworkState.STARTED ) { OperationAndData<?> operationAndData; try { operationAndData = backgroundOperations.take(); if ( debugListener != null ) { debugListener.listen(operationAndData); } performBackgroundOperation(operationAndData); } catch ( InterruptedException e ) { // swallow the interrupt as it's only possible from either a background // operation and, thus, doesn't apply to this loop or the instance // is being closed in which case the while test will get it } } } finally { log.info("backgroundOperationsLoop exiting"); } }
protected void internalSync(CuratorFrameworkImpl impl, String path, Object context) { BackgroundOperation<String> operation = new BackgroundSyncImpl(impl, context); performBackgroundOperation(new OperationAndData<String>(operation, path, null, null, context)); }
protected void internalSync(CuratorFrameworkImpl impl, String path, Object context) { BackgroundOperation<String> operation = new BackgroundSyncImpl(impl, context); performBackgroundOperation(new OperationAndData<String>(operation, path, null, null, context)); }
private void doSyncForSuspendedConnection(final long instanceIndex) { // we appear to have disconnected, force a new ZK event and see if we can connect to another server final BackgroundOperation<String> operation = new BackgroundSyncImpl(this, null); OperationAndData.ErrorCallback<String> errorCallback = new OperationAndData.ErrorCallback<String>() { @Override public void retriesExhausted(OperationAndData<String> operationAndData) { // if instanceIndex != newInstanceIndex, the ZooKeeper instance was reset/reallocated // so the pending background sync is no longer valid. // if instanceIndex is -1, this is the second try to sync - punt and mark the connection lost if ( (instanceIndex < 0) || (instanceIndex == client.getInstanceIndex()) ) { connectionStateManager.addStateChange(ConnectionState.LOST); } else { log.debug("suspendConnection() failure ignored as the ZooKeeper instance was reset. Retrying."); // send -1 to signal that if it happens again, punt and mark the connection lost doSyncForSuspendedConnection(-1); } } }; performBackgroundOperation(new OperationAndData<String>(operation, "/", null, errorCallback, null)); }
private void doSyncForSuspendedConnection(final long instanceIndex) { // we appear to have disconnected, force a new ZK event and see if we can connect to another server final BackgroundOperation<String> operation = new BackgroundSyncImpl(this, null); OperationAndData.ErrorCallback<String> errorCallback = new OperationAndData.ErrorCallback<String>() { @Override public void retriesExhausted(OperationAndData<String> operationAndData) { // if instanceIndex != newInstanceIndex, the ZooKeeper instance was reset/reallocated // so the pending background sync is no longer valid. // if instanceIndex is -1, this is the second try to sync - punt and mark the connection lost if ( (instanceIndex < 0) || (instanceIndex == client.getInstanceIndex()) ) { connectionStateManager.addStateChange(ConnectionState.LOST); } else { log.debug("suspendConnection() failure ignored as the ZooKeeper instance was reset. Retrying."); // send -1 to signal that if it happens again, punt and mark the connection lost doSyncForSuspendedConnection(-1); } } }; performBackgroundOperation(new OperationAndData<String>(operation, "/", null, errorCallback, null)); }
<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()) ) { doQueueOperation = checkBackgroundRetry(operationAndData, event); break; } if ( operationAndData.getCallback() != null ) { sendToBackgroundCallback(operationAndData, event); break; } processEvent(event); } while ( false ); if ( doQueueOperation ) { queueOperation(operationAndData); } }
<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()) ) { doQueueOperation = checkBackgroundRetry(operationAndData, event); break; } if ( operationAndData.getCallback() != null ) { sendToBackgroundCallback(operationAndData, event); break; } processEvent(event); } while ( false ); if ( doQueueOperation ) { queueOperation(operationAndData); } }