You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

31 lines
898 B

  1. using JT1078.DotNetty.Core.Enums;
  2. using System;
  3. using System.Collections.Concurrent;
  4. namespace JT1078.DotNetty.Core.Services
  5. {
  6. public class JT1078AtomicCounterServiceFactory
  7. {
  8. private readonly ConcurrentDictionary<JT1078TransportProtocolType, JT1078AtomicCounterService> cache;
  9. public JT1078AtomicCounterServiceFactory()
  10. {
  11. cache = new ConcurrentDictionary<JT1078TransportProtocolType, JT1078AtomicCounterService>();
  12. }
  13. public JT1078AtomicCounterService Create(JT1078TransportProtocolType type)
  14. {
  15. if(cache.TryGetValue(type,out var service))
  16. {
  17. return service;
  18. }
  19. else
  20. {
  21. var serviceNew = new JT1078AtomicCounterService();
  22. cache.TryAdd(type, serviceNew);
  23. return serviceNew;
  24. }
  25. }
  26. }
  27. }