private void DeviceOverload(AerospikeException ae) { node.IncrErrorCount(); if (iteration <= maxRetries && (totalWatch == null || totalWatch.ElapsedMilliseconds < totalTimeout)) { int status = Interlocked.CompareExchange(ref state, RETRY, IN_PROGRESS); if (status == IN_PROGRESS) { node.PutAsyncConnection(conn); Retry(ae); } else { AlreadyCompleted(status); } } else { int status = Interlocked.CompareExchange(ref state, FAIL_APPLICATION_ERROR, IN_PROGRESS); if (status == IN_PROGRESS) { node.PutAsyncConnection(conn); FailCommand(ae); } else { AlreadyCompleted(status); } } }
protected internal void Finish() { // Ensure that command succeeds or fails, but not both. int status = Interlocked.CompareExchange(ref state, SUCCESS, IN_PROGRESS); if (status == IN_PROGRESS) { // Command finished successfully. // Put connection back into pool. conn.UpdateLastUsed(); node.PutAsyncConnection(conn); // Do not put large buffers back into pool. if (segment.size > BufferPool.BUFFER_CUTOFF) { // Put back original buffer instead. segment = segmentOrig; eventArgs.SetBuffer(segment.buffer, segment.offset, 0); } eventArgs.UserToken = segment; cluster.PutEventArgs(eventArgs); } else if (status == FAIL_TOTAL_TIMEOUT || status == FAIL_SOCKET_TIMEOUT) { // Timeout thread closed connection, but transaction still completed. // Do not connection put back into pool. PutBackArgsOnError(); } else { // Should never get here. if (Log.WarnEnabled()) { Log.Warn("AsyncCommand finished with unexpected return status: " + status); } } try { OnSuccess(); } catch (Exception e) { if (Log.WarnEnabled()) { Log.Warn("OnSuccess() error: " + Util.GetErrorMessage(e)); } } }
protected internal void Finish() { // Ensure that command succeeds or fails, but not both. int status = Interlocked.CompareExchange(ref complete, SUCCESS, 0); if (status == 0) { conn.UpdateLastUsed(); node.PutAsyncConnection(conn); // Do not put large buffers back into pool. if (segment.size > BufferPool.BUFFER_CUTOFF) { // Put back original buffer instead. segment = segmentOrig; eventArgs.SetBuffer(segment.buffer, segment.offset, 0); } eventArgs.UserToken = segment; cluster.PutEventArgs(eventArgs); try { OnSuccess(); } catch (AerospikeException ae) { // The user's OnSuccess() may have already been called which in turn generates this // exception. It's important to call OnFailure() anyhow because the user's code // may be waiting for completion notification which wasn't yet called in // OnSuccess(). This is the only case where both OnSuccess() and OnFailure() // gets called for the same command. OnFailure(ae); } catch (Exception e) { OnFailure(new AerospikeException(e)); } } else { AlreadyCompleted(status); } }
private void ConnectionReady() { if (Interlocked.CompareExchange(ref state, 1, 0) == 0) { conn.UpdateLastUsed(); node.PutAsyncConnection(conn); try { listener.OnSuccess(eventArgs, dataBuffer); } catch (Exception e) { if (Log.WarnEnabled()) { Log.Warn("OnSuccess() error: " + Util.GetErrorMessage(e)); } } } }