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
- OlePropertyStructs.cs
- TableRow.cs
- MenuScrollingVisibilityConverter.cs
- FrameworkContentElementAutomationPeer.cs
- BatchParser.cs
- ConstructorBuilder.cs
- XmlParserContext.cs
- SmtpClient.cs
- TemplateControlParser.cs
- XmlCharCheckingReader.cs
- TargetConverter.cs
- ColumnWidthChangedEvent.cs
- EnumBuilder.cs
- TreeNodeCollection.cs
- Point.cs
- SelectionProviderWrapper.cs
- ActivityInterfaces.cs
- Camera.cs
- DeclaredTypeElement.cs
- ControlCachePolicy.cs
- KeyFrames.cs
- DoubleConverter.cs
- LinkedDataMemberFieldEditor.cs
- Message.cs
- _NetworkingPerfCounters.cs
- XmlSchemaInclude.cs
- OLEDB_Util.cs
- AdCreatedEventArgs.cs
- CryptoApi.cs
- PropertyValueChangedEvent.cs
- BufferModesCollection.cs
- ContentFilePart.cs
- HttpCacheVary.cs
- AbstractDataSvcMapFileLoader.cs
- ChannelSinkStacks.cs
- KeyTimeConverter.cs
- DataGridColumnCollection.cs
- ExceptionRoutedEventArgs.cs
- ThreadInterruptedException.cs
- DesignColumn.cs
- AndMessageFilterTable.cs
- DiscreteKeyFrames.cs
- JulianCalendar.cs
- ReadingWritingEntityEventArgs.cs
- TextFormattingConverter.cs
- LookupBindingPropertiesAttribute.cs
- ISSmlParser.cs
- DesignerUtils.cs
- PolicyManager.cs
- KeyPullup.cs
- ErrorInfoXmlDocument.cs
- CommaDelimitedStringAttributeCollectionConverter.cs
- WindowAutomationPeer.cs
- NavigationFailedEventArgs.cs
- StringDictionaryWithComparer.cs
- SqlTransaction.cs
- SmiSettersStream.cs
- PenLineJoinValidation.cs
- ToolStripItemEventArgs.cs
- EncodingConverter.cs
- ListControl.cs
- LinqDataSourceDeleteEventArgs.cs
- QuadraticBezierSegment.cs
- XamlTypeMapper.cs
- UIElementAutomationPeer.cs
- _ChunkParse.cs
- XmlChoiceIdentifierAttribute.cs
- EventMap.cs
- ResourceWriter.cs
- CaseStatement.cs
- HandleCollector.cs
- TransformPattern.cs
- KeyTimeConverter.cs
- CompilationUtil.cs
- RegexGroupCollection.cs
- SelectedDatesCollection.cs
- DataPagerFieldCommandEventArgs.cs
- UrlAuthFailureHandler.cs
- ConfigurationLocationCollection.cs
- X509SecurityTokenProvider.cs
- Stack.cs
- Point3DValueSerializer.cs
- Type.cs
- DataGridViewCellMouseEventArgs.cs
- RightNameExpirationInfoPair.cs
- SafeLibraryHandle.cs
- FormViewModeEventArgs.cs
- CustomAttribute.cs
- FontFamily.cs
- PublisherIdentityPermission.cs
- CodeTypeDeclarationCollection.cs
- WFItemsToSpacerVisibility.cs
- SQLRoleProvider.cs
- DeclarativeConditionsCollection.cs
- XmlSerializer.cs
- BuiltInExpr.cs
- TransformValueSerializer.cs
- XmlRootAttribute.cs
- DomainLiteralReader.cs
- IResourceProvider.cs