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
- SiteMapSection.cs
- CaseInsensitiveComparer.cs
- RecognizerStateChangedEventArgs.cs
- StringConverter.cs
- DbException.cs
- WebPartChrome.cs
- ColorIndependentAnimationStorage.cs
- EventLogWatcher.cs
- CqlLexerHelpers.cs
- WindowsFormsSectionHandler.cs
- ProviderUtil.cs
- TypeInitializationException.cs
- RepeaterItem.cs
- SQLDateTime.cs
- GrabHandleGlyph.cs
- TextElement.cs
- XMLUtil.cs
- DurableInstanceManager.cs
- PersonalizationEntry.cs
- CustomAttribute.cs
- ConfigurationException.cs
- activationcontext.cs
- GenericTypeParameterBuilder.cs
- CounterCreationDataConverter.cs
- TabItemAutomationPeer.cs
- ServiceOperationUIEditor.cs
- XmlFormatReaderGenerator.cs
- WorkflowMarkupSerializerMapping.cs
- GridViewUpdatedEventArgs.cs
- GCHandleCookieTable.cs
- COM2ExtendedBrowsingHandler.cs
- ShaderEffect.cs
- ButtonFieldBase.cs
- PrimitiveCodeDomSerializer.cs
- AudioLevelUpdatedEventArgs.cs
- FormViewActionList.cs
- DataObjectCopyingEventArgs.cs
- BindableAttribute.cs
- MailBnfHelper.cs
- SoapMessage.cs
- arabicshape.cs
- Classification.cs
- UserNameSecurityTokenAuthenticator.cs
- CompModSwitches.cs
- SafeNativeMethods.cs
- DataGridViewButtonCell.cs
- CustomValidator.cs
- CodeSubDirectoriesCollection.cs
- StringKeyFrameCollection.cs
- StrongNameMembershipCondition.cs
- Automation.cs
- HashCryptoHandle.cs
- DivideByZeroException.cs
- ProbeMatchesMessageCD1.cs
- StorageInfo.cs
- ExecutionEngineException.cs
- Directory.cs
- Condition.cs
- Part.cs
- BamlRecordHelper.cs
- HttpFileCollection.cs
- ContactManager.cs
- Typography.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- Rotation3DAnimation.cs
- AuthenticationConfig.cs
- IndexingContentUnit.cs
- SystemGatewayIPAddressInformation.cs
- OptionalMessageQuery.cs
- ImmutableCollection.cs
- Typography.cs
- GenericPrincipal.cs
- TextBoxAutomationPeer.cs
- DecoderBestFitFallback.cs
- SQLGuid.cs
- Int32Converter.cs
- MsmqChannelFactoryBase.cs
- ConfigurationLockCollection.cs
- HtmlFormParameterReader.cs
- FormViewDeletedEventArgs.cs
- AppLevelCompilationSectionCache.cs
- Polygon.cs
- base64Transforms.cs
- SHA512Managed.cs
- ConsoleKeyInfo.cs
- _HeaderInfoTable.cs
- BaseContextMenu.cs
- ObjectCloneHelper.cs
- SystemFonts.cs
- RuntimeHandles.cs
- HttpDigestClientCredential.cs
- SettingsBase.cs
- LineBreakRecord.cs
- CellParagraph.cs
- SourceSwitch.cs
- JsonReaderWriterFactory.cs
- MessageDecoder.cs
- DependencyPropertyKind.cs
- LabelEditEvent.cs
- ScriptResourceAttribute.cs