Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / TransactionBridge / Microsoft / Transactions / Wsat / StateMachines / Completion.cs / 1 / Completion.cs
//------------------------------------------------------------------------------ // Copyright(c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- // This file contains the the implementations of the various states used by // the Completion participant state machine using System; using System.Diagnostics; using System.ServiceModel; using Microsoft.Transactions.Bridge; using Microsoft.Transactions.Wsat.InputOutput; using Microsoft.Transactions.Wsat.Messaging; using Microsoft.Transactions.Wsat.Protocol; using DiagnosticUtility = Microsoft.Transactions.Bridge.DiagnosticUtility; namespace Microsoft.Transactions.Wsat.StateMachines { //============================================================================= // CompletionInitializing // // A CreateTransaction message was received, and a new transaction // object was created to process it. //============================================================================= class CompletionInitializing : InactiveState { public CompletionInitializing(ProtocolState state) : base(state) { } public override void OnEvent(MsgCreateTransactionEvent e) { CompletionEnlistment completion = e.Completion; EnlistmentOptions options = completion.CreateEnlistmentOptions(e.Body.Expires, e.Body.ExpiresPresent, e.Body.IsolationLevel, 0, null); state.TransactionManagerSend.CreateTransaction (completion, options, e); e.StateMachine.ChangeState(state.States.CompletionCreating); } } //============================================================================== // CompletionCreating // // The TM has been asked to create a new transaction //============================================================================= class CompletionCreating : InactiveState { public CompletionCreating(ProtocolState state) : base (state) { } public override void OnEvent(TmCreateTransactionResponseEvent e) { MsgCreateTransactionEvent source = e.SourceEvent; CompletionEnlistment completion = e.Completion; if (e.Status != Status.Success) { // Send a fault to the caller Microsoft.Transactions.Wsat.Messaging.Fault fault = this.state.Faults.CannotCreateContext; state.ActivationCoordinator.SendFault(source.Result, fault); if (CreateTransactionFailureRecord.ShouldTrace) { CreateTransactionFailureRecord.Trace ( completion.EnlistmentId, SR.GetString (SR.PplCreateTransactionFailed, e.Status.ToString()) ); } completion.StateMachine.ChangeState(state.States.CompletionInitializationFailed); } else { completion.OnRootTransactionCreated(); TransactionContext context = completion.ContextManager.TransactionContext; state.ActivationCoordinator.SendCreateCoordinationContextResponse(context, source.Result); completion.StateMachine.ChangeState(state.States.CompletionCreated); } } } //============================================================================== // CompletionCreated // // The TM successfully created a new transaction, but no one has registered // for completion. //============================================================================== class CompletionCreated : ActiveState { public CompletionCreated(ProtocolState state) : base (state) {} public override void OnEvent(MsgRegisterCompletionEvent e) { CompletionEnlistment completion = e.Completion; completion.SetCompletionProxy(e.Proxy); state.RegistrationCoordinator.SendRegisterResponse(completion, e.Result, ControlProtocol.Completion, completion.CoordinatorService); e.StateMachine.ChangeState(state.States.CompletionActive); } // The most likely cause of this is a transaction timeout public override void OnEvent(TmAsyncRollbackEvent e) { CompletionEnlistment completion = (CompletionEnlistment) e.Enlistment; completion.SetCallback(e.Callback, e.CallbackState); state.TransactionManagerSend.Aborted(completion); e.StateMachine.ChangeState(state.States.CompletionAborted); } } //============================================================================= // CompletionActive // // A transaction was successfully created, and a completion participant // was successfully added. We can now be asked to commit or rollback. //============================================================================== class CompletionActive : ActiveState { public CompletionActive(ProtocolState state) : base (state) {} public override void Enter (StateMachine stateMachine) { base.Enter (stateMachine); if (RegisterParticipantRecord.ShouldTrace) { CompletionEnlistment completion = (CompletionEnlistment) stateMachine.Enlistment; RegisterParticipantRecord.Trace ( completion.EnlistmentId, completion.Enlistment.RemoteTransactionId, ControlProtocol.Completion, completion.ParticipantProxy.To, this.state.ProtocolVersion ); } } public override void OnEvent(MsgRegisterCompletionEvent e) { // Sorry, someone already registered if (RegisterParticipantFailureRecord.ShouldTrace) { RegisterParticipantFailureRecord.Trace( e.Completion.EnlistmentId, e.Completion.Enlistment.RemoteTransactionId, ControlProtocol.Completion, e.ParticipantService, SR.GetString(SR.RegisterCompletionFailureDuplicate), this.state.ProtocolVersion ); } state.RegistrationCoordinator.SendFault(e.Result, this.state.Faults.CompletionAlreadyRegistered); } public override void OnEvent(MsgCompletionCommitEvent e) { state.TransactionManagerSend.Commit(e.Completion); e.StateMachine.ChangeState(state.States.CompletionCommitting); } public override void OnEvent(MsgCompletionRollbackEvent e) { state.TransactionManagerSend.Rollback(e.Completion); e.StateMachine.ChangeState(state.States.CompletionAborting); } public override void OnEvent(TmAsyncRollbackEvent e) { CompletionEnlistment completion = (CompletionEnlistment) e.Enlistment; state.CompletionCoordinator.SendAborted(completion); completion.SetCallback(e.Callback, e.CallbackState); state.TransactionManagerSend.Aborted(completion); e.StateMachine.ChangeState(state.States.CompletionAborted); } } //============================================================================= // CompletionCommitting // // The completion participant called Commit on an active transaction. //============================================================================= class CompletionCommitting : DecidedState { public CompletionCommitting(ProtocolState state) : base (state) { } // Tolerate duplicate commit message // Note that the state machine in the spec recommends a rollback if we're in the // preparing state, but to ignore if we're prepared. Since we can't tell the // difference over here, we'll just let the transaction continue (not that we // have much of a choice...) public override void OnEvent(MsgCompletionCommitEvent e) { return; } public override void OnEvent(TmCompletionCommitResponseEvent e) { CompletionEnlistment completion = e.Completion; State newState; switch (e.Status) { case Status.Committed: state.CompletionCoordinator.SendCommitted(completion); newState = state.States.CompletionCommitted; break; case Status.Aborted: state.CompletionCoordinator.SendAborted(completion); newState = state.States.CompletionAborted; break; // We do not worry about Status.InDoubt because we always disable SPC // when we're the root of the transaction default: // An invalid Enum value on this internal code path indicates // a product bug and violates assumptions about // valid values in MSDTC. DiagnosticUtility.FailFast("Invalid status code"); newState = null; // Keep the compiler happy break; } e.StateMachine.ChangeState(newState); } // Trains crossed in the night... // This means aborted, and the completion participant is waiting for a response public override void OnEvent(TmAsyncRollbackEvent e) { CompletionEnlistment completion = (CompletionEnlistment)e.Enlistment; state.CompletionCoordinator.SendAborted(completion); completion.SetCallback(e.Callback, e.CallbackState); state.TransactionManagerSend.Aborted(completion); e.StateMachine.ChangeState(state.States.CompletionAborted); } } //============================================================================= // CompletionAborting // // The completion participant called Rollback on an active transaction. //============================================================================== class CompletionAborting : DecidedState { public CompletionAborting(ProtocolState state) : base (state) { } public override void OnEvent(MsgCompletionCommitEvent e) { state.CompletionCoordinator.SendAborted(e.Completion); } // Tolerate duplicate rollback message public override void OnEvent(MsgCompletionRollbackEvent e) { state.CompletionCoordinator.SendAborted(e.Completion); } public override void OnEvent(TmCompletionRollbackResponseEvent e) { if (e.Status != Status.Aborted) { // The only legal response from the TM to us trying to abort a // transaction is Status.Aborted. DiagnosticUtility.FailFast("Transaction manager should respond Aborted to Rollback"); } state.CompletionCoordinator.SendAborted(e.Completion); e.StateMachine.ChangeState(state.States.CompletionAborted); } // Trains crossed in the night... // This means aborted, and the completion participant is waiting for a response public override void OnEvent(TmAsyncRollbackEvent e) { CompletionEnlistment completion = (CompletionEnlistment) e.Enlistment; state.CompletionCoordinator.SendAborted(completion); // Be polite completion.SetCallback(e.Callback, e.CallbackState); state.TransactionManagerSend.Aborted(completion); e.StateMachine.ChangeState(state.States.CompletionAborted); } } //============================================================================= // CompletionCommitted // // We think we're done, and the transaction committed //============================================================================== class CompletionCommitted : TerminalState { public CompletionCommitted(ProtocolState state) : base (state) { } public override void Enter(StateMachine stateMachine) { base.Enter(stateMachine); if (ParticipantStateMachineFinishedRecord.ShouldTrace) { ParticipantStateMachineFinishedRecord.Trace( stateMachine.Enlistment.EnlistmentId, stateMachine.Enlistment.Enlistment.RemoteTransactionId, TransactionOutcome.Committed); } } public override void OnEvent(MsgCompletionCommitEvent e) { state.CompletionCoordinator.SendCommitted(e.ReplyTo); } } //============================================================================== // CompletionAborted // // We think we're done, and the transaction aborted //============================================================================= class CompletionAborted : TerminalState { public CompletionAborted(ProtocolState state) : base (state) { } public override void Enter(StateMachine stateMachine) { base.Enter(stateMachine); if (ParticipantStateMachineFinishedRecord.ShouldTrace) { ParticipantStateMachineFinishedRecord.Trace( stateMachine.Enlistment.EnlistmentId, stateMachine.Enlistment.Enlistment.RemoteTransactionId, TransactionOutcome.Aborted); } } public override void OnEvent(MsgCompletionCommitEvent e) { state.CompletionCoordinator.SendAborted(e.ReplyTo); } public override void OnEvent(MsgCompletionRollbackEvent e) { state.CompletionCoordinator.SendAborted(e.ReplyTo); } public override void OnEvent(TmCompletionRollbackResponseEvent e) { if (e.Status != Status.Aborted) { // The only valid state for the state machine to be in is Aborted. // Anything else indicates that we executed an 'impossible' path // and should do the safe thing and not corrupt user data. DiagnosticUtility.FailFast("Transaction manager should respond Aborted to Rollback"); } return; } } //============================================================================== // CompletionInitializationFailed // // We think we're done because we couldn't create a new transaction //============================================================================= class CompletionInitializationFailed : TerminalState { public CompletionInitializationFailed(ProtocolState state) : base(state) { } } } // 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
- TrackingServices.cs
- HostingEnvironment.cs
- TextShapeableCharacters.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- GridEntry.cs
- ListViewGroupConverter.cs
- ExpressionDumper.cs
- rsa.cs
- MonthChangedEventArgs.cs
- Int32Collection.cs
- ScrollBarAutomationPeer.cs
- DatatypeImplementation.cs
- BitmapFrameDecode.cs
- UICuesEvent.cs
- DataGridViewTextBoxColumn.cs
- XPathBuilder.cs
- PersistenceException.cs
- BuilderPropertyEntry.cs
- DataBindingCollection.cs
- MimeWriter.cs
- Drawing.cs
- XmlDataContract.cs
- VectorCollectionValueSerializer.cs
- LinkArea.cs
- BinaryObjectReader.cs
- DiffuseMaterial.cs
- StylusCaptureWithinProperty.cs
- WebServiceEnumData.cs
- ValueQuery.cs
- TransformerInfoCollection.cs
- DataControlField.cs
- ListViewCommandEventArgs.cs
- Rectangle.cs
- ThreadAttributes.cs
- XmlEnumAttribute.cs
- MenuTracker.cs
- Predicate.cs
- DecimalConstantAttribute.cs
- PTUtility.cs
- SByteConverter.cs
- X509Extension.cs
- DirectoryObjectSecurity.cs
- MetadataPropertyCollection.cs
- Tuple.cs
- XPathNodePointer.cs
- MetabaseServerConfig.cs
- FileDialog.cs
- SqlVersion.cs
- ObjectDataSourceMethodEventArgs.cs
- XmlSchemaAttribute.cs
- InfoCardArgumentException.cs
- StructuredTypeEmitter.cs
- NativeMethods.cs
- EventlogProvider.cs
- ObservableCollection.cs
- ApplicationGesture.cs
- SystemUnicastIPAddressInformation.cs
- IRCollection.cs
- DataTable.cs
- SystemNetHelpers.cs
- XPathItem.cs
- SemanticTag.cs
- QuaternionAnimation.cs
- SmtpNtlmAuthenticationModule.cs
- BaseResourcesBuildProvider.cs
- ReadWriteObjectLock.cs
- WindowsScrollBarBits.cs
- SqlProcedureAttribute.cs
- PartialCachingAttribute.cs
- DeviceContext.cs
- QuaternionAnimationBase.cs
- IndentedTextWriter.cs
- NumberAction.cs
- DefaultMemberAttribute.cs
- SubMenuStyleCollection.cs
- PanelDesigner.cs
- _BufferOffsetSize.cs
- Message.cs
- SendingRequestEventArgs.cs
- LocationSectionRecord.cs
- AssociationEndMember.cs
- WrappedKeySecurityToken.cs
- EndpointPerformanceCounters.cs
- StatusBarPanelClickEvent.cs
- ArglessEventHandlerProxy.cs
- StringFunctions.cs
- RotateTransform.cs
- SystemIcmpV4Statistics.cs
- PermissionListSet.cs
- MulticastNotSupportedException.cs
- OdbcInfoMessageEvent.cs
- UnionCodeGroup.cs
- XsltLibrary.cs
- WpfKnownTypeInvoker.cs
- DispatchChannelSink.cs
- PopupRoot.cs
- DesignObjectWrapper.cs
- SafeViewOfFileHandle.cs
- GridViewDeleteEventArgs.cs
- RuntimeUtils.cs