public void Execute() { eventArgs = cluster.GetEventArgs(); segment = segmentOrig = eventArgs.UserToken as BufferSegment; eventArgs.UserToken = this; if (cluster.HasBufferChanged(segment)) { // Reset buffer in SizeBuffer(). segment.buffer = null; segment.offset = 0; segment.size = 0; } Policy policy = GetPolicy(); timeout = policy.timeout; if (timeout > 0) { watch = Stopwatch.StartNew(); AsyncTimeoutQueue.Instance.Add(this, timeout); } ExecuteCommand(); }
public bool HasBufferChanged(BufferSegment segment) { return(bufferPool.bufferSize != segment.size); }
private void ResizeBuffer(int size) { if (size <= BufferPool.BUFFER_CUTOFF) { // Checkout buffer from cache. cluster.GetNextBuffer(size, segment); } else { // Large buffers should not be cached. // Allocate, but do not put back into pool. segment = new BufferSegment(); segment.buffer = new byte[size]; segment.offset = 0; segment.size = size; } }
private void PutBackArgsOnError() { // 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); } else { // There may be rare error cases where dataBuffer and eventArgs.Buffer // are different. Make sure they are in sync. if (eventArgs.Buffer != segment.buffer) { eventArgs.SetBuffer(segment.buffer, segment.offset, 0); } } eventArgs.UserToken = segment; cluster.PutEventArgs(eventArgs); }
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); } }
public bool HasBufferChanged(BufferSegment segment) { return bufferPool.bufferSize != segment.size; }
public void GetNextBuffer(int size, BufferSegment segment) { lock (this) { if (size > bufferPool.bufferSize) { bufferPool = new BufferPool(maxCommands, size); } bufferPool.GetNextBuffer(segment); } }