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
- MatchingStyle.cs
- SqlUserDefinedTypeAttribute.cs
- DesignerTransaction.cs
- Vector3DAnimationUsingKeyFrames.cs
- Int64Animation.cs
- SqlMetaData.cs
- HMACSHA512.cs
- ComProxy.cs
- WebPartZoneBase.cs
- PlainXmlDeserializer.cs
- SamlSerializer.cs
- EmptyCollection.cs
- FontFamilyConverter.cs
- ListenerSingletonConnectionReader.cs
- QilParameter.cs
- validationstate.cs
- Task.cs
- ZipIOExtraFieldElement.cs
- BooleanAnimationUsingKeyFrames.cs
- AssemblyCollection.cs
- CompiledIdentityConstraint.cs
- ResXResourceWriter.cs
- SizeAnimationBase.cs
- FrameworkElement.cs
- TextEndOfSegment.cs
- HyperLinkColumn.cs
- CalculatedColumn.cs
- SendingRequestEventArgs.cs
- SourceInterpreter.cs
- XmlDocument.cs
- GetLedgerEntryForRecipientRequest.cs
- DrawingImage.cs
- BitmapEffectInput.cs
- RectValueSerializer.cs
- SqlTriggerAttribute.cs
- ExtendedProtectionPolicyTypeConverter.cs
- HMACSHA256.cs
- TransactedReceiveData.cs
- DataGridTableCollection.cs
- QuadraticBezierSegment.cs
- HtmlMobileTextWriter.cs
- CheckBoxStandardAdapter.cs
- TextServicesCompartmentEventSink.cs
- SupportsEventValidationAttribute.cs
- DataGridToolTip.cs
- EventLogPermissionEntry.cs
- StagingAreaInputItem.cs
- DocumentViewerBaseAutomationPeer.cs
- TcpStreams.cs
- ProfessionalColors.cs
- PropertyNames.cs
- CreateUserWizardStep.cs
- AppDomainUnloadedException.cs
- OleDbParameterCollection.cs
- BuildTopDownAttribute.cs
- PointValueSerializer.cs
- TransformConverter.cs
- SpeakCompletedEventArgs.cs
- FileSystemInfo.cs
- TraceRecord.cs
- TextTreeExtractElementUndoUnit.cs
- XmlSchemaValidationException.cs
- ResourceCategoryAttribute.cs
- TypeTypeConverter.cs
- safelink.cs
- DesignTimeTemplateParser.cs
- BrowserDefinitionCollection.cs
- CodeDelegateCreateExpression.cs
- RefreshPropertiesAttribute.cs
- ServiceAuthorizationBehavior.cs
- Utility.cs
- Base64Encoder.cs
- BamlVersionHeader.cs
- BackStopAuthenticationModule.cs
- StateBag.cs
- RelativeSource.cs
- AssertHelper.cs
- Transform3DCollection.cs
- XMLUtil.cs
- __FastResourceComparer.cs
- WebPartHeaderCloseVerb.cs
- SoapExtensionReflector.cs
- ModuleBuilder.cs
- ProtocolsInstallComponent.cs
- PenLineCapValidation.cs
- AnnotationResource.cs
- DataGridViewCellStateChangedEventArgs.cs
- UInt32.cs
- HMACRIPEMD160.cs
- VirtualDirectoryMapping.cs
- RemotingSurrogateSelector.cs
- WSIdentityFaultException.cs
- util.cs
- IPAddressCollection.cs
- HttpHandlerAction.cs
- Misc.cs
- HyperlinkAutomationPeer.cs
- QueryParameter.cs
- BaseParagraph.cs
- InternalsVisibleToAttribute.cs