Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / ChannelFactoryRefCache.cs / 1 / ChannelFactoryRefCache.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- using System.ServiceModel.Channels; using System.Collections.Generic; namespace System.ServiceModel { sealed class EndpointTraitwhere TChannel : class { string endpointConfigurationName; EndpointAddress remoteAddress; InstanceContext callbackInstance; public EndpointTrait(string endpointConfigurationName, EndpointAddress remoteAddress, InstanceContext callbackInstance) { this.endpointConfigurationName = endpointConfigurationName; this.remoteAddress = remoteAddress; this.callbackInstance = callbackInstance; } public override bool Equals(object obj) { EndpointTrait trait1 = obj as EndpointTrait ; if (trait1 == null) return false; if (!object.ReferenceEquals(this.callbackInstance, trait1.callbackInstance)) return false; if (string.CompareOrdinal(this.endpointConfigurationName, trait1.endpointConfigurationName) != 0) { return false; } // EndpointAddress.Equals is used. if (this.remoteAddress != trait1.remoteAddress) return false; return true; } public override int GetHashCode() { int hashCode = 0; if (this.callbackInstance != null) { hashCode ^= this.callbackInstance.GetHashCode(); } hashCode ^= this.endpointConfigurationName.GetHashCode(); if (this.remoteAddress != null) hashCode ^= this.remoteAddress.GetHashCode(); return hashCode; } public ChannelFactory CreateChannelFactory() { if (this.callbackInstance != null) return CreateDuplexFactory(); return CreateSimplexFactory(); } DuplexChannelFactory CreateDuplexFactory() { if (this.remoteAddress != null) { return new DuplexChannelFactory (this.callbackInstance, this.endpointConfigurationName, this.remoteAddress); } return new DuplexChannelFactory (this.callbackInstance, this.endpointConfigurationName); } ChannelFactory CreateSimplexFactory() { if (this.remoteAddress != null) { return new ChannelFactory (this.endpointConfigurationName, this.remoteAddress); } return new ChannelFactory (this.endpointConfigurationName); } } sealed class ChannelFactoryRef where TChannel : class { ChannelFactory channelFactory; int refCount = 1; public ChannelFactoryRef(ChannelFactory channelFactory) { this.channelFactory = channelFactory; } public void AddRef() { this.refCount++; } // The caller should call Close/Abort when the return value is true. public bool Release() { --this.refCount; DiagnosticUtility.DebugAssert(this.refCount >= 0, "RefCount should not be less than zero."); if (this.refCount == 0) { return true; } return false; } public void Close(TimeSpan timeout) { this.channelFactory.Close(timeout); } public void Abort() { this.channelFactory.Abort(); } public ChannelFactory ChannelFactory { get { return this.channelFactory; } } } class ChannelFactoryRefCache : MruCache , ChannelFactoryRef > where TChannel : class { static EndpointTraitComparer DefaultEndpointTraitComparer = new EndpointTraitComparer(); class EndpointTraitComparer : IEqualityComparer > { public bool Equals(EndpointTrait x, EndpointTrait y) { if (x != null) { if (y != null) return x.Equals(y); return false; } if (y != null) return false; return true; } public int GetHashCode(EndpointTrait obj) { if (obj == null) return 0; return obj.GetHashCode(); } } public ChannelFactoryRefCache(int watermark) : base(watermark * 4 / 5, watermark, DefaultEndpointTraitComparer) { } protected override void OnSingleItemRemoved(ChannelFactoryRef item) { // Remove from cache. if (item.Release()) { item.Abort(); } } } } // 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
- ButtonBase.cs
- CallbackException.cs
- SecurityElement.cs
- WindowsFormsHostPropertyMap.cs
- TaskCanceledException.cs
- AuthorizationRuleCollection.cs
- DropDownList.cs
- SettingsBase.cs
- BinaryQueryOperator.cs
- NonPrimarySelectionGlyph.cs
- UnsafeNativeMethods.cs
- EventBuilder.cs
- XmlWrappingReader.cs
- StringUtil.cs
- SQLMoney.cs
- ExtensionDataReader.cs
- QilVisitor.cs
- FixedHighlight.cs
- DtdParser.cs
- BaseDataList.cs
- QilStrConcatenator.cs
- Certificate.cs
- XmlRootAttribute.cs
- StreamGeometry.cs
- SQLBinaryStorage.cs
- PersonalizableAttribute.cs
- ISAPIApplicationHost.cs
- EdmType.cs
- NavigateEvent.cs
- Config.cs
- ResourcePart.cs
- XmlBoundElement.cs
- Transform.cs
- SecurityTokenProvider.cs
- XmlCharCheckingReader.cs
- TypeKeyValue.cs
- PointAnimationUsingKeyFrames.cs
- BrowsableAttribute.cs
- CommandDevice.cs
- DataServiceRequestOfT.cs
- CryptoHelper.cs
- HttpWebRequest.cs
- FixUpCollection.cs
- FocusWithinProperty.cs
- Cursors.cs
- PackageDocument.cs
- ListViewItemCollectionEditor.cs
- ParameterRetriever.cs
- DataServiceBuildProvider.cs
- TriggerAction.cs
- CubicEase.cs
- XmlNamespaceMappingCollection.cs
- GradientSpreadMethodValidation.cs
- CompressionTransform.cs
- Wildcard.cs
- KeyPullup.cs
- SoapExtensionReflector.cs
- SiteMapDataSource.cs
- securestring.cs
- XmlUTF8TextReader.cs
- DiscoveryEndpoint.cs
- SelectorAutomationPeer.cs
- MimePart.cs
- ProxyManager.cs
- ObjectNotFoundException.cs
- BufferBuilder.cs
- UnmanagedHandle.cs
- Function.cs
- IndexOutOfRangeException.cs
- ListBoxItemWrapperAutomationPeer.cs
- SharedConnectionInfo.cs
- Win32PrintDialog.cs
- GeneralTransform3D.cs
- ImageList.cs
- controlskin.cs
- ImportedPolicyConversionContext.cs
- DispatcherFrame.cs
- LambdaCompiler.Unary.cs
- WindowsTab.cs
- InstrumentationTracker.cs
- SimpleTypesSurrogate.cs
- PropertyFilterAttribute.cs
- DrawingContext.cs
- Tuple.cs
- MultilineStringConverter.cs
- IDReferencePropertyAttribute.cs
- EndpointIdentityConverter.cs
- AbstractSvcMapFileLoader.cs
- SignedXml.cs
- ITextView.cs
- ItemsPresenter.cs
- PostBackOptions.cs
- SpellerHighlightLayer.cs
- ResXDataNode.cs
- MimeParameterWriter.cs
- WebEventCodes.cs
- Tablet.cs
- FontInfo.cs
- BuildManagerHost.cs
- ProcessManager.cs