Exemple #1
0
        protected void OnOperatonExecuted(KeyValueOperation e)
        {
            var handler = OperatonExecuted;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemple #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 });
        }
Exemple #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);
        }
Exemple #4
0
        public Task<HttpResponseMessage> Del([FromUri] string key)
        {
            var op = new KeyValueOperation
            {
                Key = key,
                Type = KeyValueOperationTypes.Del,
            };

            return Batch(new[] { op });
        }
		protected void OnOperatonExecuted(KeyValueOperation e)
		{
			var handler = OperatonExecuted;
			if (handler != null) handler(this, e);
		}