Пример #1
0
        protected void OnOperatonExecuted(KeyValueOperation e)
        {
            var handler = OperatonExecuted;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Пример #2
0
        public Task<HttpResponseMessage> Set([FromUri] string key, [FromUri] string val)
        {
            JToken jVal;
            try
            {
                jVal = JToken.Parse(val);
            }
            catch (JsonReaderException)
            {
                jVal = val;
            }

            var op = new KeyValueOperation
            {
                Key = key,
                Type = KeyValueOperationTypes.Add,
                Value = jVal
            };

            return Batch(new[] { op });
        }
Пример #3
0
        private async Task<HttpResponseMessage> Batch(KeyValueOperation[] operations)
        {
            var taskCompletionSource = new TaskCompletionSource<object>();
            try
            {
                RaftEngine.AppendCommand(new OperationBatchCommand
                {
                    Batch = operations,
                    Completion = taskCompletionSource
                });
            }
            catch (NotLeadingException e)
            {
                return this.RedirectToLeader(e.CurrentLeader, Request.RequestUri);
            }
            await taskCompletionSource.Task;

            return Request.CreateResponse(HttpStatusCode.Accepted);
        }
Пример #4
0
        public Task<HttpResponseMessage> Del([FromUri] string key)
        {
            var op = new KeyValueOperation
            {
                Key = key,
                Type = KeyValueOperationTypes.Del,
            };

            return Batch(new[] { op });
        }
Пример #5
0
		protected void OnOperatonExecuted(KeyValueOperation e)
		{
			var handler = OperatonExecuted;
			if (handler != null) handler(this, e);
		}