コード例 #1
0
ファイル: StatsOperation.cs プロジェクト: javithalion/NCache
		protected internal override IOperationResult ReadResponse(PooledSocket socket)
		{
			var response = new BinaryResponse();
			var serverData = new Dictionary<string, string>();
			var retval = false;

			while (response.Read(socket) && response.KeyLength > 0)
			{
				retval = true;

				var data = response.Data;
				var key = BinaryConverter.DecodeKey(data.Array, data.Offset, response.KeyLength);
				var value = BinaryConverter.DecodeKey(data.Array, data.Offset + response.KeyLength, data.Count - response.KeyLength);

				serverData[key] = value;
			}

			this.result = serverData;
			this.StatusCode = response.StatusCode;

			var result = new BinaryOperationResult()
			{
				StatusCode = StatusCode
			};

			result.PassOrFail(retval, "Failed to read response");
			return result;
		}
コード例 #2
0
        protected override IOperationResult ProcessResponse(BinaryResponse response)
        {
            var status = response.StatusCode;
            var result = new BinaryOperationResult();

            this.StatusCode = status;

            if (status == 0)
            {
                int flags = BinaryConverter.DecodeInt32(response.Extra, 0);
                this.result = new CacheItem((ushort)flags, response.Data);
                this.Cas = response.CAS;

            #if EVEN_MORE_LOGGING
                if (log.IsDebugEnabled)
                    log.DebugFormat("Get succeeded for key '{0}'.", this.Key);
            #endif

                return result.Pass();
            }

            this.Cas = 0;

            #if EVEN_MORE_LOGGING
            if (log.IsDebugEnabled)
                log.DebugFormat("Get failed for key '{0}'. Reason: {1}", this.Key, Encoding.ASCII.GetString(response.Data.Array, response.Data.Offset, response.Data.Count));
            #endif

            var message = ResultHelper.ProcessResponseData(response.Data);
            return result.Fail(message);
        }
コード例 #3
0
        protected override IOperationResult ProcessResponse(BinaryResponse response)
        {
            var r = response.StatusCode == 0;
            var result = new BinaryOperationResult();

            if (this.locator != null &&
                !VBucketAwareOperationFactory.GuessResponseState(response, out this.state))
            {
                return result.Fail("Process response failed");
            }

            return result.PassOrFail(r, "Processing response failed");
        }
コード例 #4
0
        protected override IOperationResult ProcessResponse(BinaryResponse response)
        {
            var r = base.ProcessResponse(response);
            var result = new BinaryOperationResult();

            if (this.locator != null &&
                !VBucketAwareOperationFactory.GuessResponseState(response, out this.state))
            {
                return result.Fail("Failed to process response");
            }

            return r;
        }
コード例 #5
0
        public static BinaryOperationResult FromResponse(BinaryResponse response, string failMessage = null)
        {
            var success = response.StatusCode == 0;

            var retval = new BinaryOperationResult
            {
                StatusCode = response.StatusCode,
                Success    = success,
                Message    = success ? null : response.GetStatusMessage() ?? failMessage,
                Cas        = response.CAS
            };

            return(retval);
        }
コード例 #6
0
		public static BinaryOperationResult FromResponse(BinaryResponse response, string failMessage = null)
		{
			var success = response.StatusCode == 0;

			var retval = new BinaryOperationResult
			{
				StatusCode = response.StatusCode,
				Success = success,
				Message = success ? null : response.GetStatusMessage() ?? failMessage,
				Cas = response.CAS
			};

			return retval;
		}
コード例 #7
0
        protected internal override IOperationResult ReadResponse(IPooledSocket socket)
        {
            var response = new BinaryResponse();
            var retval = response.Read(socket);

            this.StatusCode = StatusCode;
            var result = new BinaryOperationResult()
            {
                Success = retval,
                StatusCode = this.StatusCode
            };

            result.PassOrFail(retval, "Failed to read response");
            return result;
        }
コード例 #8
0
ファイル: SaslStep.cs プロジェクト: javithalion/NCache
		protected internal override IOperationResult ReadResponse(PooledSocket socket)
		{
			var response = new BinaryResponse();

			var retval = response.Read(socket);

			this.StatusCode = response.StatusCode;
			this.Data = response.Data.Array;

			var result = new BinaryOperationResult
			{
				StatusCode = this.StatusCode
			};

			result.PassOrFail(retval, "Failed to read response");
			return result;
		}
コード例 #9
0
 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);
     }
 }
コード例 #10
0
        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);
        }
コード例 #11
0
		protected internal override IOperationResult ReadResponse(PooledSocket socket)
		{
			var response = new BinaryResponse();
			var retval = response.Read(socket);
			
			this.Cas = response.CAS;
			this.StatusCode = response.StatusCode;

			var result = new BinaryOperationResult()
			{
				Success = retval,
				Cas = this.Cas,
				StatusCode = this.StatusCode
			};

			IOperationResult responseResult;
			if (! (responseResult = this.ProcessResponse(response)).Success)
			{
				result.InnerResult = responseResult;
				responseResult.Combine(result);
			}
			
			return result;
		}
コード例 #12
0
        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;
        }
コード例 #13
0
            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();
            }
コード例 #14
0
        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;
        }
コード例 #15
0
        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);
        }