NetTokenPoolProvider.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections.Generic;
  2. namespace IFramework.Net
  3. {
  4. internal class NetTokenPoolProvider:INetTokenPoolProvider
  5. {
  6. TokenConnectionManager tokenManager = null;
  7. public int ConnectionTimeout
  8. {
  9. get { return tokenManager.ConnectionTimeout; }
  10. set { tokenManager.ConnectionTimeout = value; }
  11. }
  12. public int Count { get { return tokenManager.Count; } }
  13. public static NetTokenPoolProvider CreateProvider(int taskExecutePeriod)
  14. {
  15. return new NetTokenPoolProvider(taskExecutePeriod);
  16. }
  17. public NetTokenPoolProvider(int taskExecutePeriod)
  18. {
  19. tokenManager = new TokenConnectionManager(taskExecutePeriod);
  20. }
  21. public void TimerEnable(bool isContinue)
  22. {
  23. tokenManager.TimerEnable(isContinue);
  24. }
  25. public NetConnectionToken GetTopToken()
  26. {
  27. return tokenManager.GetTopToken();
  28. }
  29. public void InsertToken(NetConnectionToken ncToken)
  30. {
  31. tokenManager.InsertToken(ncToken);
  32. }
  33. public IEnumerable<NetConnectionToken> Reader()
  34. {
  35. foreach (var item in tokenManager.ReadNext())
  36. {
  37. yield return item;
  38. }
  39. }
  40. public bool RemoveToken(NetConnectionToken ncToken,bool isClose=true)
  41. {
  42. return tokenManager.RemoveToken(ncToken,isClose);
  43. }
  44. public NetConnectionToken GetTokenById(int Id)
  45. {
  46. return tokenManager.GetTokenById(Id);
  47. }
  48. public NetConnectionToken GetTokenBySocketToken(SocketToken sToken)
  49. {
  50. return tokenManager.GetTokenBySocketToken(sToken);
  51. }
  52. public bool RefreshExpireToken(SocketToken sToken)
  53. {
  54. return tokenManager.RefreshConnectionToken(sToken);
  55. }
  56. public void Clear(bool isClose=true)
  57. {
  58. tokenManager.Clear(isClose);
  59. }
  60. }
  61. }