Example #1
0
        public Task <PostMessagesResponse> PostMessagesAsync(string stream, ICollection <Message> messages)
        {
            var          writer = _writers.GetOrAdd(stream, s => new Locked(FileSetup.CreateAndInitWriter(_dir, stream)));
            AppendResult result;

            lock (writer.WriteLock) {
                result = writer.Writer.Append(messages);
            }
            var response = PostMessagesResponse.FromAppendResult(result);

            return(Task.FromResult(response));
        }
Example #2
0
        public Task <PostMessagesResponse> PostMessagesAsync(string stream,
                                                             ICollection <Message> messages)
        {
            var inMem = Get(stream);

            AppendResult value;

            lock (inMem.WriteLock) {
                value = inMem.Writer.Append(messages);
            }
            var response = PostMessagesResponse.FromAppendResult(value);

            return(Task.FromResult(response));
        }
        public async Task <PostMessagesResponse> Append(string id, ICollection <Message> writes)
        {
            var writer = _scheduler;

            if (null != writer)
            {
                using (Metrics.StartTimer("api.append")) {
                    var result = await writer.Append(id, writes);

                    return(PostMessagesResponse.FromAppendResult(result));
                }
            }
            using (Metrics.StartTimer("api.forward")) {
                var endpoint = await _poller.GetLeaderClientAsync();

                var result = await endpoint.PostMessagesAsync(id, writes);

                return(result);
            }
        }