浏览代码

refactor

master
yangxiaodong 7 年前
父节点
当前提交
4fc6a4d195
共有 1 个文件被更改,包括 45 次插入0 次删除
  1. +45
    -0
      src/Cap.Consistency/Internal/MethodMatcherCache.cs

+ 45
- 0
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<string, ConsumerExecutorDescriptor> 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<string, ConsumerExecutorDescriptor> Entries { get; } =
new ConcurrentDictionary<string, ConsumerExecutorDescriptor>();
}
}

正在加载...
取消
保存