From 4fc6a4d1951dcb9d3620e8da2cd1253ce089b266 Mon Sep 17 00:00:00 2001 From: yangxiaodong Date: Fri, 5 May 2017 16:58:02 +0800 Subject: [PATCH] refactor --- .../Internal/MethodMatcherCache.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/Cap.Consistency/Internal/MethodMatcherCache.cs diff --git a/src/Cap.Consistency/Internal/MethodMatcherCache.cs b/src/Cap.Consistency/Internal/MethodMatcherCache.cs new file mode 100644 index 0000000..dbe327c --- /dev/null +++ b/src/Cap.Consistency/Internal/MethodMatcherCache.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Text; +using Cap.Consistency.Abstractions; +using Cap.Consistency.Infrastructure; +using Cap.Consistency.Routing; + +namespace Cap.Consistency.Internal +{ + public class MethodMatcherCache + { + private readonly IConsumerExcutorSelector _selector; + + public MethodMatcherCache(IConsumerExcutorSelector selector) { + _selector = selector; + } + + public ConcurrentDictionary GetCandidatesMethods(TopicRouteContext routeContext) { + + if (Entries == null) { + + var executorCollection = _selector.SelectCandidates(routeContext); + + foreach (var item in executorCollection) { + + Entries.GetOrAdd(item.Topic.Name, item); + } + } + return Entries; + } + + public ConsumerExecutorDescriptor GetTopicExector(string topicName) { + + if (Entries == null) { + throw new ArgumentNullException(nameof(Entries)); + } + + return Entries[topicName]; + } + + public ConcurrentDictionary Entries { get; } = + new ConcurrentDictionary(); + } +}