protected override IOperationResult ProcessResponse(BinaryResponse response) { var result = new BinaryOperationResult(); #if EVEN_MORE_LOGGING if (log.IsDebugEnabled) if (response.StatusCode == 0) log.DebugFormat("Delete succeeded for key '{0}'.", this.Key); else log.DebugFormat("Delete failed for key '{0}'. Reason: {1}", this.Key, Encoding.ASCII.GetString(response.Data.Array, response.Data.Offset, response.Data.Count)); #endif if (response.StatusCode == 0) { return result.Pass(); } else { var message = ResultHelper.ProcessResponseData("Delete failed for key " + Key, response.Data); return result.Fail(message); } }
protected override IOperationResult ProcessResponse(BinaryResponse response) { var result = new BinaryOperationResult(); var status = response.StatusCode; this.StatusCode = status; if (status == 0) { var data = response.Data; if (data.Count != 8) return result.Fail("Result must be 8 bytes long, received: " + data.Count, new InvalidOperationException()); this.result = BinaryConverter.DecodeUInt64(data.Array, data.Offset); return result.Pass(); } var message = ResultHelper.ProcessResponseData("Mutate failed for key " + Key, response.Data); return result.Fail(message); }
public IOperationResult Execute(IOperation op) { IOperationResult result = new BinaryOperationResult(); IPooledSocket socket = null; try { socket = _pool.Acquire(); if (Log.IsDebugEnabled) { Log.DebugFormat("Start execute {0} with {1}", op.Key, socket.InstanceId); } var buffers = op.GetBuffer(); socket.Write(buffers); result = op.ReadResponse(socket); if (result.Success) { result.Pass(); } } catch (NodeShutdownException e) { string msg = String.Format("Node Shutdown - {0}.", EndPoint); Log.DebugFormat("m:{0} i:{1}\n{2}", msg, op.Key, e); result.Fail(msg, e); result.StatusCode = StatusCode.NodeShutdown.ToInt(); } catch (QueueTimeoutException e) { string msg = String.Format("Queue Timeout - {0}.", EndPoint); Log.ErrorFormat("m:{0} i:{1}\n{2}", msg, op.Key, e); result.Fail(msg, e); result.StatusCode = StatusCode.SocketPoolTimeout.ToInt(); } catch (IOException e) { string msg = String.Format("Exception reading response - {0}", EndPoint); Log.ErrorFormat("m:{0} s:{1} i:{2}\n{3}", msg, op.Key, socket == null ? Guid.Empty : socket.InstanceId, e); result.Fail(msg, e); if (result.StatusCode == null || result.StatusCode == StatusCode.Success.ToInt()) { result.StatusCode = StatusCode.InternalError.ToInt(); } } catch (Exception e) { string msg = String.Format("Operation failed - {0}", EndPoint); Log.ErrorFormat("m:{0} s:{1} i:{2}\n{3}", msg, op.Key, socket == null ? Guid.Empty : socket.InstanceId, e); result.Fail(msg, e); if (result.StatusCode == null || result.StatusCode == StatusCode.Success.ToInt()) { result.StatusCode = StatusCode.InternalError.ToInt(); } } finally { if (socket != null) { if (Log.IsDebugEnabled) { Log.DebugFormat("End execute {0} with {1}", op.Key, socket.InstanceId); } _pool.Release(socket); } } if (Log.IsDebugEnabled) { const string msg = "Operation {0} :i {1} n: {2} t: {3} m: {4} sc: {5} r: {6}"; Log.DebugFormat(msg, result.Success ? op.RetryAttempts > 0 ? "succeeded*" : "succeeded" : op.RetryAttempts > 0 ? "failed*" : "failed", op.Key, _endpoint, Thread.CurrentThread.Name, result.Message, Enum.GetName(typeof (StatusCode), result.StatusCode ?? 0), op.RetryAttempts); } return result; }
protected override IOperationResult ProcessResponse(BinaryResponse response) { base.ProcessResponse(response); var result = new BinaryOperationResult(); if (!GuessResponseState(response, out this.state)) { var message = ResultHelper.ProcessResponseData(response.Data, "Failed to process response"); return result.Fail(message); } return result.Pass(); }
protected override IOperationResult ReadResponse(IPooledSocket socket) { var response = new BinaryResponse(); var result = new BinaryOperationResult(); if (response.Read(socket)) { this.Result = DecodeResult(response.Data); result.Pass(); return result; } result.Fail("Processing of response failed"); return result; }
protected override IOperationResult ProcessResponse(BinaryResponse response) { var status = response.StatusCode; var result = new BinaryOperationResult(); this.StatusCode = status; if (status == 0) { this.Cas = response.CAS; return result.Pass(); } this.Cas = 0; var message = ResultHelper.ProcessResponseData(response.Data); return result.Fail(message); }