InputQueueChannelAcceptor.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //----------------------------------------------------------------------------
  4. namespace System.ServiceModel.Channels
  5. {
  6. using System.Runtime;
  7. using System.ServiceModel.Diagnostics;
  8. class InputQueueChannelAcceptor<TChannel> : ChannelAcceptor<TChannel>
  9. where TChannel : class, IChannel
  10. {
  11. InputQueue<TChannel> channelQueue;
  12. public InputQueueChannelAcceptor(ChannelManagerBase channelManager)
  13. : base(channelManager)
  14. {
  15. this.channelQueue = TraceUtility.CreateInputQueue<TChannel>();
  16. }
  17. public int PendingCount
  18. {
  19. get { return this.channelQueue.PendingCount; }
  20. }
  21. public override TChannel AcceptChannel(TimeSpan timeout)
  22. {
  23. this.ThrowIfNotOpened();
  24. return this.channelQueue.Dequeue(timeout);
  25. }
  26. public override IAsyncResult BeginAcceptChannel(TimeSpan timeout, AsyncCallback callback, object state)
  27. {
  28. this.ThrowIfNotOpened();
  29. return this.channelQueue.BeginDequeue(timeout, callback, state);
  30. }
  31. public void Dispatch()
  32. {
  33. this.channelQueue.Dispatch();
  34. }
  35. public override TChannel EndAcceptChannel(IAsyncResult result)
  36. {
  37. return this.channelQueue.EndDequeue(result);
  38. }
  39. public void EnqueueAndDispatch(TChannel channel)
  40. {
  41. this.channelQueue.EnqueueAndDispatch(channel);
  42. }
  43. public void EnqueueAndDispatch(TChannel channel, Action dequeuedCallback)
  44. {
  45. this.channelQueue.EnqueueAndDispatch(channel, dequeuedCallback);
  46. }
  47. public bool EnqueueWithoutDispatch(TChannel channel, Action dequeuedCallback)
  48. {
  49. return this.channelQueue.EnqueueWithoutDispatch(channel, dequeuedCallback);
  50. }
  51. public virtual bool EnqueueWithoutDispatch(Exception exception, Action dequeuedCallback)
  52. {
  53. return this.channelQueue.EnqueueWithoutDispatch(exception, dequeuedCallback);
  54. }
  55. public void EnqueueAndDispatch(TChannel channel, Action dequeuedCallback, bool canDispatchOnThisThread)
  56. {
  57. this.channelQueue.EnqueueAndDispatch(channel, dequeuedCallback, canDispatchOnThisThread);
  58. }
  59. public virtual void EnqueueAndDispatch(Exception exception, Action dequeuedCallback, bool canDispatchOnThisThread)
  60. {
  61. this.channelQueue.EnqueueAndDispatch(exception, dequeuedCallback, canDispatchOnThisThread);
  62. }
  63. public void FaultQueue()
  64. {
  65. this.Fault();
  66. }
  67. protected override void OnClosed()
  68. {
  69. base.OnClosed();
  70. this.channelQueue.Dispose();
  71. }
  72. protected override void OnFaulted()
  73. {
  74. this.channelQueue.Shutdown(() => this.ChannelManager.GetPendingException());
  75. base.OnFaulted();
  76. }
  77. public override bool WaitForChannel(TimeSpan timeout)
  78. {
  79. this.ThrowIfNotOpened();
  80. return this.channelQueue.WaitForItem(timeout);
  81. }
  82. public override IAsyncResult BeginWaitForChannel(TimeSpan timeout, AsyncCallback callback, object state)
  83. {
  84. this.ThrowIfNotOpened();
  85. return this.channelQueue.BeginWaitForItem(timeout, callback, state);
  86. }
  87. public override bool EndWaitForChannel(IAsyncResult result)
  88. {
  89. return this.channelQueue.EndWaitForItem(result);
  90. }
  91. }
  92. }