private void Initialize() { // Basic initialization ChannelHost.Start(); hostStarted = true; channels = new Dictionary <string, TInternal>(); channelQueue = new LimitedQueue <TInternal>(maxAcceptedChannels); acceptQueue = new Queue <AsyncResult <TInternal, object> >(); waitQueue = new Queue <AsyncResult <bool, object> >(); // Register the endpoint with the router. SessionHandlerInfo sessionInfo; sessionInfo = this.GetSessionHandlerInfo(); sessionMode = sessionInfo != null && sessionInfo.SessionType == typeof(DuplexSession); if (sessionMode) { ChannelHost.Router.Dispatcher.AddLogical(new MsgHandlerDelegate(OnReceive), ep, typeof(DuplexSessionMsg), false, sessionInfo); } else { ChannelHost.Router.Dispatcher.AddLogical(new MsgHandlerDelegate(OnReceive), ep, typeof(WcfEnvelopeMsg), false, sessionInfo); } // Start the background task timer arBkTimer = AsyncTimer.BeginTimer(bkTaskInterval, onBkTask, null); }
private int maxReceiveQueueSize; // Maximum size of the queue /// <summary> /// Constructor. /// </summary> /// <param name="channelManager">The responsible channel manager.</param> /// <param name="localAddress">The local <see cref="EndpointAddress" /> this channel will use to receive requests.</param> public InputChannel(ChannelManagerBase channelManager, EndpointAddress localAddress) : base(channelManager) { this.maxReceiveQueueSize = ServiceModelHelper.MaxAcceptedMessages; // $todo(jeff.lill): Hardcoding this this.listener = (InputChannelListener)channelManager; this.localAddress = localAddress; this.msgQueue = new LimitedQueue <Message>(maxReceiveQueueSize); }
private TimeSpan bkTaskInterval; // Channel background task interval /// <summary> /// Constructor. /// </summary> /// <param name="context">The <see cref="BindingContext" /> holding the information necessary to construct the channel stack.</param> internal InputChannelListener(BindingContext context) : base(context) { this.maxReceiveQueueSize = ServiceModelHelper.MaxAcceptedMessages; // $todo(jeff.lill): Hardcoded this.bkTaskInterval = ServiceModelHelper.DefaultBkTaskInterval; // This too this.msgQueue = new LimitedQueue <Message>(maxReceiveQueueSize); this.waitQueue = new QueueArray <AsyncResult <bool, InputChannel> >(); this.receiveQueue = new QueueArray <AsyncResult <Message, InputChannel> >(); }
private TimeSpan bkTaskInterval; // Channel background task interval /// <summary> /// Constructor. /// </summary> /// <param name="context">The <see cref="BindingContext" /> holding the information necessary to construct the channel stack.</param> internal ReplyChannelListener(BindingContext context) : base(context) { this.maxRequestQueueSize = ServiceModelHelper.MaxAcceptedMessages; // $todo(jeff.lill): Hardcoded this.maxRequestQueueTime = ServiceModelHelper.MaxRequestQueueTime; // this.bkTaskInterval = ServiceModelHelper.DefaultBkTaskInterval; // this.requestQueue = new LimitedQueue <RequestInfo>(maxRequestQueueSize); this.waitQueue = new QueueArray <AsyncResult <bool, ReplyChannel> >(); this.receiveQueue = new QueueArray <AsyncResult <RequestInfo, ReplyChannel> >(); }
private PayloadSizeEstimator payloadEstimator; // Used to estimate the buffer required to serialize // the next message sent /// <summary> /// Constructor. /// </summary> /// <param name="channelManager">The responsible channel manager.</param> /// <param name="localAddress">The local <see cref="EndpointAddress" /> this channel will use to receive requests.</param> /// <param name="encoder">The <see cref="MessageEncoder" /> for serializing messages to the wire format.</param> public ReplyChannel(ChannelManagerBase channelManager, EndpointAddress localAddress, MessageEncoder encoder) : base(channelManager) { this.maxReceiveQueueSize = ServiceModelHelper.MaxAcceptedMessages; // $todo(jeff.lill): Hardcoding this this.listener = (ReplyChannelListener)channelManager; this.localAddress = localAddress; this.requestQueue = new LimitedQueue <RequestInfo>(maxReceiveQueueSize); this.pendingRequests = new Dictionary <Guid, MsgRequestContext>(); this.encoder = encoder; this.payloadEstimator = new PayloadSizeEstimator(ServiceModelHelper.PayloadEstimatorSampleCount); }
private void Cleanup(Exception e) { using (TimedLock.Lock(ChannelHost.SyncRoot)) { if (hostStarted) { // Remove the route from the message router. if (ChannelHost.Router != null) { ChannelHost.Router.Dispatcher.RemoveTarget(this); } hostStarted = false; ChannelHost.Stop(); } } List <LillTekChannelBase> abortChannels = null; using (TimedLock.Lock(this)) { // Terminate any pending accepts if (acceptQueue != null) { while (acceptQueue.Count > 0) { acceptQueue.Dequeue().Notify(); } acceptQueue = null; } // Terminate any pending waits if (waitQueue != null) { while (waitQueue.Count > 0) { waitQueue.Dequeue().Notify(); } waitQueue = null; } // Abort any queued accepted channels if (channelQueue != null) { while (channelQueue.Count > 0) { TInternal channel = channelQueue.Dequeue(); if (channel.State != CommunicationState.Closed) { channel.Abort(); } } channelQueue = null; } // $todo(jeff.lill): Delete this ------------------------ // Setup to abort all of the listener's channels. if (channels != null && channels.Count > 0) { abortChannels = new List <LillTekChannelBase>(channels.Count); foreach (LillTekChannelBase channel in channels.Values) { abortChannels.Add(channel); } } //--------------------------------------------------- // Stop the background task timer onBkTask = null; } // Actually abort the channels outside of the lock. if (abortChannels != null) { foreach (LillTekChannelBase channel in abortChannels) { channel.Close(); } } }