Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / tx / System / Transactions / DurableEnlistmentState.cs / 1305376 / DurableEnlistmentState.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Transactions { using System; using System.Diagnostics; using System.Globalization; using System.Security; using System.Threading; using System.Transactions.Diagnostics; // Base class for all durable enlistment states internal abstract class DurableEnlistmentState : EnlistmentState { private static DurableEnlistmentActive _durableEnlistmentActive; private static DurableEnlistmentAborting _durableEnlistmentAborting; private static DurableEnlistmentCommitting _durableEnlistmentCommitting; private static DurableEnlistmentDelegated _durableEnlistmentDelegated; private static DurableEnlistmentEnded _durableEnlistmentEnded; // Object for synchronizing access to the entire class( avoiding lock( typeof( ... )) ) private static object classSyncObject; internal static DurableEnlistmentActive _DurableEnlistmentActive { get { if (_durableEnlistmentActive == null) { lock (ClassSyncObject) { if (_durableEnlistmentActive == null) { DurableEnlistmentActive temp = new DurableEnlistmentActive(); Thread.MemoryBarrier(); _durableEnlistmentActive = temp; } } } return _durableEnlistmentActive; } } protected static DurableEnlistmentAborting _DurableEnlistmentAborting { get { if (_durableEnlistmentAborting == null) { lock (ClassSyncObject) { if (_durableEnlistmentAborting == null) { DurableEnlistmentAborting temp = new DurableEnlistmentAborting(); Thread.MemoryBarrier(); _durableEnlistmentAborting = temp; } } } return _durableEnlistmentAborting; } } protected static DurableEnlistmentCommitting _DurableEnlistmentCommitting { get { if (_durableEnlistmentCommitting == null) { lock (ClassSyncObject) { if (_durableEnlistmentCommitting == null) { DurableEnlistmentCommitting temp = new DurableEnlistmentCommitting(); Thread.MemoryBarrier(); _durableEnlistmentCommitting = temp; } } } return _durableEnlistmentCommitting; } } protected static DurableEnlistmentDelegated _DurableEnlistmentDelegated { get { if (_durableEnlistmentDelegated == null) { lock (ClassSyncObject) { if (_durableEnlistmentDelegated == null) { DurableEnlistmentDelegated temp = new DurableEnlistmentDelegated(); Thread.MemoryBarrier(); _durableEnlistmentDelegated = temp; } } } return _durableEnlistmentDelegated; } } protected static DurableEnlistmentEnded _DurableEnlistmentEnded { get { if (_durableEnlistmentEnded == null) { lock (ClassSyncObject) { if (_durableEnlistmentEnded == null) { DurableEnlistmentEnded temp = new DurableEnlistmentEnded(); Thread.MemoryBarrier(); _durableEnlistmentEnded = temp; } } } return _durableEnlistmentEnded; } } // Helper object for static synchronization private static object ClassSyncObject { get { if( classSyncObject == null ) { object o = new object(); Interlocked.CompareExchange( ref classSyncObject, o, null ); } return classSyncObject; } } } // Active state for a durable enlistment. In this state the transaction can be aborted // asynchronously by calling abort. internal class DurableEnlistmentActive : DurableEnlistmentState { internal override void EnterState( InternalEnlistment enlistment ) { // Set the enlistment state enlistment.State = this; // Yeah it's active } internal override void EnlistmentDone( InternalEnlistment enlistment ) { // Mark the enlistment as done. _DurableEnlistmentEnded.EnterState( enlistment ); } internal override void InternalAborted( InternalEnlistment enlistment ) { // Transition to the aborting state _DurableEnlistmentAborting.EnterState( enlistment ); } internal override void ChangeStateCommitting( InternalEnlistment enlistment ) { // Transition to the committing state _DurableEnlistmentCommitting.EnterState( enlistment ); } internal override void ChangeStatePromoted( InternalEnlistment enlistment, IPromotedEnlistment promotedEnlistment ) { // Save the promoted enlistment because future notifications must be sent here. enlistment.PromotedEnlistment = promotedEnlistment; // The transaction is being promoted promote the enlistment as well _EnlistmentStatePromoted.EnterState( enlistment ); } internal override void ChangeStateDelegated( InternalEnlistment enlistment ) { // This is a valid state transition. _DurableEnlistmentDelegated.EnterState( enlistment ); } } // Aborting state for a durable enlistment. In this state the transaction has been aborted, // by someone other than the enlistment. // internal class DurableEnlistmentAborting : DurableEnlistmentState { internal override void EnterState( InternalEnlistment enlistment ) { // Set the enlistment state enlistment.State = this; Monitor.Exit( enlistment.Transaction ); try { if ( DiagnosticTrace.Verbose ) { EnlistmentNotificationCallTraceRecord.Trace( SR.GetString( SR.TraceSourceLtm ), enlistment.EnlistmentTraceId, NotificationCall.Rollback ); } // Send the Rollback notification to the enlistment if( enlistment.SinglePhaseNotification != null ) { enlistment.SinglePhaseNotification.Rollback( enlistment.SinglePhaseEnlistment ); } else { enlistment.PromotableSinglePhaseNotification.Rollback( enlistment.SinglePhaseEnlistment ); } } finally { #pragma warning disable 0618 //@ Monitor.Enter(enlistment.Transaction); #pragma warning restore 0618 } } internal override void Aborted( InternalEnlistment enlistment, Exception e ) { if( enlistment.Transaction.innerException == null ) { enlistment.Transaction.innerException = e; } // Transition to the ended state _DurableEnlistmentEnded.EnterState( enlistment ); } internal override void EnlistmentDone( InternalEnlistment enlistment ) { // Transition to the ended state _DurableEnlistmentEnded.EnterState( enlistment ); } } // Committing state is when SPC has been sent to an enlistment but no response // has been received. // internal class DurableEnlistmentCommitting : DurableEnlistmentState { internal override void EnterState( InternalEnlistment enlistment ) { bool spcCommitted = false; // Set the enlistment state enlistment.State = this; Monitor.Exit( enlistment.Transaction ); try { if ( DiagnosticTrace.Verbose ) { EnlistmentNotificationCallTraceRecord.Trace( SR.GetString( SR.TraceSourceLtm ), enlistment.EnlistmentTraceId, NotificationCall.SinglePhaseCommit ); } // Send the Commit notification to the enlistment if( enlistment.SinglePhaseNotification != null ) { enlistment.SinglePhaseNotification.SinglePhaseCommit( enlistment.SinglePhaseEnlistment ); } else { enlistment.PromotableSinglePhaseNotification.SinglePhaseCommit( enlistment.SinglePhaseEnlistment ); } spcCommitted = true; } finally { if (!spcCommitted) { enlistment.SinglePhaseEnlistment.InDoubt(); } #pragma warning disable 0618 //@ Monitor.Enter(enlistment.Transaction); #pragma warning restore 0618 } } internal override void EnlistmentDone(InternalEnlistment enlistment) { // EnlistmentDone should be treated the same as Committed from this state. // This eliminates a ---- between the SPC call and the EnlistmentDone call. // Transition to the ended state _DurableEnlistmentEnded.EnterState( enlistment ); // Make the transaction commit enlistment.Transaction.State.ChangeStateTransactionCommitted( enlistment.Transaction ); } internal override void Committed( InternalEnlistment enlistment ) { // Transition to the ended state _DurableEnlistmentEnded.EnterState( enlistment ); // Make the transaction commit enlistment.Transaction.State.ChangeStateTransactionCommitted( enlistment.Transaction ); } internal override void Aborted( InternalEnlistment enlistment, Exception e ) { // Transition to the ended state _DurableEnlistmentEnded.EnterState( enlistment ); // Start the transaction aborting enlistment.Transaction.State.ChangeStateTransactionAborted( enlistment.Transaction, e ); } internal override void InDoubt( InternalEnlistment enlistment, Exception e ) { // Transition to the ended state _DurableEnlistmentEnded.EnterState( enlistment ); if( enlistment.Transaction.innerException == null ) { enlistment.Transaction.innerException = e; } // Make the transaction in dobut enlistment.Transaction.State.InDoubtFromEnlistment( enlistment.Transaction ); } } // Delegated state for a durable enlistment represents an enlistment that was // origionally a PromotableSinglePhaseEnlisment that where promotion has happened. // These enlistments don't need to participate in the commit process anymore. internal class DurableEnlistmentDelegated : DurableEnlistmentState { internal override void EnterState( InternalEnlistment enlistment ) { // Set the enlistment state enlistment.State = this; // At this point the durable enlistment should have someone to forward to. Debug.Assert( enlistment.PromotableSinglePhaseNotification != null ); } internal override void Committed( InternalEnlistment enlistment ) { // Transition to the ended state _DurableEnlistmentEnded.EnterState( enlistment ); // Change the transaction to committed. enlistment.Transaction.State.ChangeStatePromotedCommitted( enlistment.Transaction ); } internal override void Aborted( InternalEnlistment enlistment, Exception e ) { // Transition to the ended state _DurableEnlistmentEnded.EnterState( enlistment ); if( enlistment.Transaction.innerException == null ) { enlistment.Transaction.innerException = e; } // Start the transaction aborting enlistment.Transaction.State.ChangeStatePromotedAborted( enlistment.Transaction ); } internal override void InDoubt( InternalEnlistment enlistment, Exception e ) { // Transition to the ended state _DurableEnlistmentEnded.EnterState( enlistment ); if( enlistment.Transaction.innerException == null ) { enlistment.Transaction.innerException = e; } // Tell the transaction that the enlistment is InDoubt. Note that // for a transaction that has been delegated and then promoted there // are two chances to get a better answer than indoubt. So it may be that // the TM will have a better answer. enlistment.Transaction.State.InDoubtFromEnlistment( enlistment.Transaction ); } } // Ended state is the state that is entered when the durable enlistment has committed, // aborted, or said read only for an enlistment. At this point there are no valid // operations on the enlistment. internal class DurableEnlistmentEnded : DurableEnlistmentState { internal override void EnterState( InternalEnlistment enlistment ) { // Set the enlistment state enlistment.State = this; } internal override void InternalAborted(InternalEnlistment enlistment) { // From the Aborting state the transaction may tell the enlistment to abort. At this point // it already knows. Eat this message. } internal override void InDoubt(InternalEnlistment enlistment, Exception e) { // Ignore this in case the enlistment gets here before // the transaction tells it to do so } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- VariableExpressionConverter.cs
- SettingsPropertyWrongTypeException.cs
- SessionStateSection.cs
- IteratorFilter.cs
- DropTarget.cs
- GridViewAutomationPeer.cs
- AnnotationMap.cs
- QueryMatcher.cs
- WindowsHyperlink.cs
- FontWeightConverter.cs
- SapiRecoInterop.cs
- UnsafeNativeMethods.cs
- Camera.cs
- DebugHandleTracker.cs
- DocumentViewer.cs
- CodeIterationStatement.cs
- TreeView.cs
- FileDialogPermission.cs
- MenuAdapter.cs
- BaseCollection.cs
- DependencyPropertyKey.cs
- Scanner.cs
- BrushProxy.cs
- LoginCancelEventArgs.cs
- _CacheStreams.cs
- VectorCollectionConverter.cs
- ItemChangedEventArgs.cs
- NavigationProperty.cs
- HttpHandler.cs
- COM2FontConverter.cs
- SystemIPv4InterfaceProperties.cs
- LoadedOrUnloadedOperation.cs
- diagnosticsswitches.cs
- StoreAnnotationsMap.cs
- Matrix.cs
- OdbcConnectionHandle.cs
- _NTAuthentication.cs
- CompositeFontFamily.cs
- WebPartVerb.cs
- HttpSessionStateBase.cs
- Image.cs
- Icon.cs
- input.cs
- VirtualizingStackPanel.cs
- DeviceContext2.cs
- Utils.cs
- SessionStateContainer.cs
- SecureStringHasher.cs
- ViewManager.cs
- ThemeDictionaryExtension.cs
- XPathNode.cs
- DataGridViewSelectedCellCollection.cs
- CharStorage.cs
- OutOfMemoryException.cs
- GlobalProxySelection.cs
- VirtualPathProvider.cs
- UpDownBase.cs
- XmlDataLoader.cs
- ResourceDefaultValueAttribute.cs
- CollectionChangeEventArgs.cs
- Converter.cs
- SpellerHighlightLayer.cs
- ColumnWidthChangedEvent.cs
- Function.cs
- WorkflowServiceOperationListItem.cs
- TableLayoutSettings.cs
- BuildProviderAppliesToAttribute.cs
- IsolatedStorageSecurityState.cs
- TypeReference.cs
- SmtpReplyReaderFactory.cs
- Form.cs
- OuterGlowBitmapEffect.cs
- EditCommandColumn.cs
- CryptoConfig.cs
- OverlappedContext.cs
- DoWorkEventArgs.cs
- SafeArrayRankMismatchException.cs
- CodeDOMProvider.cs
- PixelFormatConverter.cs
- TailPinnedEventArgs.cs
- TreeViewEvent.cs
- listitem.cs
- ChannelDispatcherCollection.cs
- FixedBufferAttribute.cs
- AdCreatedEventArgs.cs
- SimpleLine.cs
- PerfProviderCollection.cs
- MetaType.cs
- CompoundFileStreamReference.cs
- VectorCollectionConverter.cs
- Timeline.cs
- RewritingPass.cs
- EdgeProfileValidation.cs
- EventSetter.cs
- AuthenticodeSignatureInformation.cs
- CodeDelegateInvokeExpression.cs
- DataRow.cs
- FastEncoderWindow.cs
- SafeRightsManagementSessionHandle.cs
- HostingPreferredMapPath.cs