Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / ServiceThrottle.cs / 1 / ServiceThrottle.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Dispatcher { using System; using System.ServiceModel; using System.Collections.Generic; using System.Globalization; using System.Threading; using System.Runtime.Serialization; interface ISessionThrottleNotification { void ThrottleAcquired(); } public sealed class ServiceThrottle { internal const int DefaultMaxConcurrentCalls = 16; internal const int DefaultMaxConcurrentSessions = 10; FlowThrottle calls; FlowThrottle sessions; QuotaThrottle dynamic; FlowThrottle instanceContexts; ServiceHostBase host; bool isActive; object thisLock = new object(); internal ServiceThrottle(ServiceHostBase host) { if (!((host != null))) { DiagnosticUtility.DebugAssert("ServiceThrottle.ServiceThrottle: (host != null)"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("host"); } this.host = host; this.MaxConcurrentCalls = ServiceThrottle.DefaultMaxConcurrentCalls; this.MaxConcurrentSessions = ServiceThrottle.DefaultMaxConcurrentSessions; this.isActive = true; } FlowThrottle Calls { get { lock (this.ThisLock) { if (this.calls == null) { this.calls = new FlowThrottle(this.GotCall, ServiceThrottle.DefaultMaxConcurrentCalls, ServiceThrottle.MaxConcurrentCallsPropertyName, ServiceThrottle.MaxConcurrentCallsConfigName); } return this.calls; } } } FlowThrottle Sessions { get { lock (this.ThisLock) { if (this.sessions == null) { this.sessions = new FlowThrottle(this.GotSession, ServiceThrottle.DefaultMaxConcurrentSessions, ServiceThrottle.MaxConcurrentSessionsPropertyName, ServiceThrottle.MaxConcurrentSessionsConfigName); } return this.sessions; } } } QuotaThrottle Dynamic { get { lock (this.ThisLock) { if (this.dynamic == null) { this.dynamic = new QuotaThrottle(this.GotDynamic, new object()); this.dynamic.Owner = "ServiceHost"; } this.UpdateIsActive(); return this.dynamic; } } } internal int ManualFlowControlLimit { get { return this.Dynamic.Limit; } set { this.Dynamic.SetLimit(value); } } const string MaxConcurrentCallsPropertyName = "MaxConcurrentCalls"; const string MaxConcurrentCallsConfigName = "maxConcurrentCalls"; public int MaxConcurrentCalls { get { return this.Calls.Capacity; } set { this.ThrowIfClosedOrOpened(MaxConcurrentCallsPropertyName); this.Calls.Capacity = value; this.UpdateIsActive(); } } const string MaxConcurrentSessionsPropertyName = "MaxConcurrentSessions"; const string MaxConcurrentSessionsConfigName = "maxConcurrentSessions"; public int MaxConcurrentSessions { get { return this.Sessions.Capacity; } set { this.ThrowIfClosedOrOpened(MaxConcurrentSessionsPropertyName); this.Sessions.Capacity = value; this.UpdateIsActive(); } } const string MaxConcurrentInstancesPropertyName = "MaxConcurrentInstances"; const string MaxConcurrentInstancesConfigName = "maxConcurrentInstances"; public int MaxConcurrentInstances { get { return this.InstanceContexts.Capacity; } set { this.ThrowIfClosedOrOpened(MaxConcurrentInstancesPropertyName); this.InstanceContexts.Capacity = value; this.UpdateIsActive(); } } FlowThrottle InstanceContexts { get { lock (this.ThisLock) { if (this.instanceContexts == null) { this.instanceContexts = new FlowThrottle(this.GotInstanceContext, Int32.MaxValue, ServiceThrottle.MaxConcurrentInstancesPropertyName, ServiceThrottle.MaxConcurrentInstancesConfigName); } return this.instanceContexts; } } } internal bool IsActive { get { return this.isActive; } } internal object ThisLock { get { return this.thisLock; } } bool PrivateAcquireCall(ChannelHandler channel) { return (this.calls == null) || this.calls.Acquire(channel); } bool PrivateAcquireSessionListenerHandler(ListenerHandler listener) { if ((this.sessions != null) && (listener.Channel != null) && (listener.Channel.Throttle == null)) { listener.Channel.Throttle = this; return this.sessions.Acquire(listener); } else { return true; } } bool PrivateAcquireSession(ISessionThrottleNotification source) { return (this.sessions == null || this.sessions.Acquire(source)); } bool PrivateAcquireDynamic(ChannelHandler channel) { return (this.dynamic == null) || this.dynamic.Acquire(channel); } bool PrivateAcquireInstanceContext(ChannelHandler channel) { if ((this.instanceContexts != null) && (channel.InstanceContext == null)) { channel.InstanceContextServiceThrottle = this; return this.instanceContexts.Acquire(channel); } else { return true; } } internal bool AcquireCall(ChannelHandler channel) { lock (this.ThisLock) { return (this.PrivateAcquireCall(channel)); } } internal bool AcquireInstanceContextAndDynamic(ChannelHandler channel, bool acquireInstanceContextThrottle) { lock(this.ThisLock) { if (!acquireInstanceContextThrottle) { return this.PrivateAcquireDynamic(channel); } else { return (this.PrivateAcquireInstanceContext(channel) && this.PrivateAcquireDynamic(channel)); } } } internal bool AcquireSession(ISessionThrottleNotification source) { lock (this.ThisLock) { return this.PrivateAcquireSession(source); } } internal bool AcquireSession(ListenerHandler listener) { lock (this.ThisLock) { return this.PrivateAcquireSessionListenerHandler(listener); } } void GotCall(object state) { ChannelHandler channel = (ChannelHandler)state; lock (this.ThisLock) { channel.ThrottleAcquiredForCall(); } } void GotDynamic(object state) { ((ChannelHandler)state).ThrottleAcquired(); } void GotInstanceContext(object state) { ChannelHandler channel = (ChannelHandler)state; lock (this.ThisLock) { if (this.PrivateAcquireDynamic(channel)) channel.ThrottleAcquired(); } } void GotSession(object state) { ((ISessionThrottleNotification)state).ThrottleAcquired(); } internal void DeactivateChannel() { if (this.isActive) { if (this.sessions != null) this.sessions.Release(); } } internal void DeactivateCall() { if (this.isActive) { if (this.calls != null) this.calls.Release(); } } internal void DeactivateInstanceContext() { if (this.isActive) { if (this.instanceContexts != null) { this.instanceContexts.Release(); } } } internal int IncrementManualFlowControlLimit(int incrementBy) { return this.Dynamic.IncrementLimit(incrementBy); } void ThrowIfClosedOrOpened(string memberName) { if (this.host.State == CommunicationState.Opened) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxImmutableThrottle1, memberName))); } else { this.host.ThrowIfClosedOrOpened(); } } void UpdateIsActive() { this.isActive = ((this.dynamic != null) || ((this.calls != null) && (this.calls.Capacity != Int32.MaxValue)) || ((this.sessions != null) && (this.sessions.Capacity != Int32.MaxValue)) || ((this.instanceContexts != null) && (this.instanceContexts.Capacity != Int32.MaxValue))); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PageFunction.cs
- GacUtil.cs
- Highlights.cs
- DelegatingChannelListener.cs
- PolicyUnit.cs
- XmlAttributes.cs
- SchemaNames.cs
- HttpWebRequestElement.cs
- RegexCharClass.cs
- MethodCallConverter.cs
- addressfiltermode.cs
- MULTI_QI.cs
- ValidationHelper.cs
- AsyncPostBackErrorEventArgs.cs
- FindCriteriaCD1.cs
- QualificationDataItem.cs
- RegisteredDisposeScript.cs
- BamlTreeNode.cs
- InvalidEnumArgumentException.cs
- SharedRuntimeState.cs
- IPipelineRuntime.cs
- BuildManager.cs
- DayRenderEvent.cs
- HtmlContainerControl.cs
- ImageSourceValueSerializer.cs
- GradientSpreadMethodValidation.cs
- EnvironmentPermission.cs
- ProxyWebPartManager.cs
- SizeChangedEventArgs.cs
- WebHostUnsafeNativeMethods.cs
- EnumerableWrapperWeakToStrong.cs
- WindowsListBox.cs
- EUCJPEncoding.cs
- XmlJsonReader.cs
- SRGSCompiler.cs
- UpdatableWrapper.cs
- ScrollProperties.cs
- WebPartEventArgs.cs
- PageRequestManager.cs
- LogAppendAsyncResult.cs
- AnyReturnReader.cs
- MultiPartWriter.cs
- JsonWriterDelegator.cs
- Descriptor.cs
- ColumnBinding.cs
- DbMetaDataCollectionNames.cs
- RootProjectionNode.cs
- PrivilegedConfigurationManager.cs
- TextProviderWrapper.cs
- PngBitmapEncoder.cs
- ConfigurationSettings.cs
- WebBrowserSiteBase.cs
- PeerObject.cs
- EmptyEnumerator.cs
- ToolStripDropDownItem.cs
- NativeObjectSecurity.cs
- ToolStripOverflow.cs
- Win32SafeHandles.cs
- SqlAggregateChecker.cs
- MouseEvent.cs
- SqlNodeTypeOperators.cs
- DescendantQuery.cs
- ModuleElement.cs
- DBNull.cs
- XmlSerializerFaultFormatter.cs
- SpeakCompletedEventArgs.cs
- SetStoryboardSpeedRatio.cs
- MetadataPropertyvalue.cs
- DataPagerFieldItem.cs
- DelegatedStream.cs
- Rect.cs
- Events.cs
- LogExtent.cs
- IRCollection.cs
- ListViewItemMouseHoverEvent.cs
- LogLogRecordEnumerator.cs
- XsltCompileContext.cs
- Action.cs
- TrackingProfile.cs
- handlecollector.cs
- RoutingChannelExtension.cs
- WebPartRestoreVerb.cs
- FillErrorEventArgs.cs
- DelayLoadType.cs
- XmlSchemaValidator.cs
- ReadOnlyAttribute.cs
- ObjectStateFormatter.cs
- EnumDataContract.cs
- XPathSingletonIterator.cs
- IWorkflowDebuggerService.cs
- TCPClient.cs
- _HTTPDateParse.cs
- InputScopeManager.cs
- PanelContainerDesigner.cs
- DataGridViewRow.cs
- Operand.cs
- ReadOnlyDataSourceView.cs
- WsdlWriter.cs
- InfiniteTimeSpanConverter.cs
- EnumCodeDomSerializer.cs