Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / TransactionBridge / Microsoft / Transactions / Wsat / InputOutput / TransactionManager.cs / 1 / TransactionManager.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- // This file implements the callbacks and entry-points used by the TM bridge // to call the WS-AT provider using System; using System.Diagnostics; using Microsoft.Transactions.Bridge; using Microsoft.Transactions.Wsat.Messaging; using Microsoft.Transactions.Wsat.Protocol; using Microsoft.Transactions.Wsat.Recovery; using Microsoft.Transactions.Wsat.StateMachines; namespace Microsoft.Transactions.Wsat.InputOutput { class TransactionManagerReceive : IProtocolProviderCoordinatorService, IProtocolProviderPropagationService { ProtocolState state; public TransactionManagerReceive(ProtocolState state) { this.state = state; } // // Coordination // public void Commit(Enlistment enlistment, ProtocolProviderCallback callback, object obj) { ParticipantEnlistment participant = (ParticipantEnlistment)enlistment.ProtocolProviderContext; participant.StateMachine.Enqueue(new TmCommitEvent(participant, callback, obj)); } public void Rollback(Enlistment enlistment, ProtocolProviderCallback callback, object obj) { // // Rollback can be called on any kind of enlistment (completion, coordinator, participant) // ParticipantEnlistment participant = enlistment.ProtocolProviderContext as ParticipantEnlistment; if (participant != null) { participant.StateMachine.Enqueue(new TmRollbackEvent(participant, callback, obj)); } else { TransactionEnlistment txEnlistment = (TransactionEnlistment)enlistment.ProtocolProviderContext; txEnlistment.StateMachine.Enqueue(new TmAsyncRollbackEvent(txEnlistment, callback, obj)); } } // An MSDTC bug (Windows OS 1412893) can cause SPC to be sent to a volatile participant // that has not requested it. Fortunately, we can work around it by declaring Commit. // Other protocols might not be so fortunate. public void SinglePhaseCommit(Enlistment enlistment, ProtocolProviderCallback callback, object obj) { ParticipantEnlistment participant = (ParticipantEnlistment)enlistment.ProtocolProviderContext; participant.StateMachine.Enqueue(new TmSinglePhaseCommitEvent(participant, callback, obj)); } public void Forget(Enlistment enlistment, ProtocolProviderCallback callback, object obj) { ParticipantEnlistment participant = enlistment.ProtocolProviderContext as ParticipantEnlistment; if (participant != null) { participant.StateMachine.Enqueue(new TmParticipantForgetEvent(participant, callback, obj)); } else { CoordinatorEnlistment coordinator = (CoordinatorEnlistment)enlistment.ProtocolProviderContext; coordinator.StateMachine.Enqueue(new TmCoordinatorForgetEvent(coordinator, callback, obj)); } } public void Prepare(Enlistment enlistment, ProtocolProviderCallback callback, object obj) { ParticipantEnlistment participant = (ParticipantEnlistment)enlistment.ProtocolProviderContext; participant.StateMachine.Enqueue(new TmPrepareEvent(participant, callback, obj)); } public void PrePrepare(Enlistment enlistment, ProtocolProviderCallback callback, object obj) { ParticipantEnlistment participant = (ParticipantEnlistment)enlistment.ProtocolProviderContext; participant.StateMachine.Enqueue(new TmPrePrepareEvent(participant, callback, obj)); } // // Propagation // public void Begin(Enlistment enlistment, ProtocolProviderCallback callback, object obj) { // We do not implement this operation, so it should never be called throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); } public void Pull(Enlistment enlistment, byte[] protocolInformation, ProtocolProviderCallback callback, object obj) { // We do not implement this operation, so it should never be called throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); } public void Push(Enlistment enlistment, byte[] protocolInformation, ProtocolProviderCallback callback, object obj) { // We do not implement this operation, so it should never be called throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); } public void MarshalTransaction(Enlistment enlistment, ProtocolProviderCallback callback, object obj) { // We do not implement this operation, so it should never be called throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); } public void EnlistPrePrepare(Enlistment enlistment, ProtocolProviderCallback callback, object obj) { CoordinatorEnlistment coordinator = (CoordinatorEnlistment)enlistment.ProtocolProviderContext; coordinator.StateMachine.Enqueue(new TmEnlistPrePrepareEvent(coordinator, callback, obj)); } public void Rejoin(Enlistment enlistment, ProtocolProviderCallback callback, object obj) { DebugTrace.TraceEnter(this, "Rejoin"); ParticipantEnlistment participant = null; try { participant = state.LogEntrySerialization.DeserializeParticipant(enlistment); } catch (SerializationException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Critical); if (DebugTrace.Error) { DebugTrace.Trace(TraceLevel.Error, "Failed to deserialize log entry for participant: {0}", e); } ParticipantRecoveryLogEntryCorruptRecord.TraceAndLog( enlistment.LocalTransactionId, enlistment.RemoteTransactionId, enlistment.GetRecoveryData(), e ); // If we cannot deserialize a participant log entry, we cannot continue executing. // If that participant were still alive and were to send us a Replay, we would // respond politely and inform it that the transaction aborted. However, // this might not be true - the transaction might have indeed committed. // Since we don't want to corrupt data, we have to failfast. DiagnosticUtility.FailFast("A participant recovery log entry could not " + "be deserialized. This is a fatal condition."); } if (ParticipantRecoveredRecord.ShouldTrace) { ParticipantRecoveredRecord.Trace( participant.EnlistmentId, participant.Enlistment.RemoteTransactionId, participant.ParticipantProxy != null ? participant.ParticipantProxy.To : null, this.state.ProtocolVersion ); } participant.StateMachine.Enqueue(new TmRejoinEvent(participant, callback, obj)); DebugTrace.TraceLeave(this, "Rejoin"); } public void Replay(Enlistment enlistment, ProtocolProviderCallback callback, object obj) { DebugTrace.TraceEnter(this, "Replay"); CoordinatorEnlistment coordinator = null; try { coordinator = state.LogEntrySerialization.DeserializeCoordinator(enlistment); } catch (SerializationException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Critical); if (DebugTrace.Error) { DebugTrace.Trace(TraceLevel.Error, "Failed to deserialize log entry for coordinator: {0}", e); } CoordinatorRecoveryLogEntryCorruptRecord.TraceAndLog( enlistment.LocalTransactionId, enlistment.RemoteTransactionId, enlistment.GetRecoveryData(), e ); // If we cannot deserialize a coordinator log entry, we cannot continue executing. // If that coordinator were still alive and were to send us Commit, we would // respond politely and acknowledge the the outcome with Committed. However, // this would be a lie - we might later recover the log entry and send a Replay. // Since we already acked the coordinator's Commit, he might tell us to Rollback. // Since we don't want to corrupt data, we have to failfast. DiagnosticUtility.FailFast("A coordinator recovery log entry could not " + "be deserialized. This is a fatal condition."); } if (CoordinatorRecoveredRecord.ShouldTrace) { CoordinatorRecoveredRecord.Trace( coordinator.EnlistmentId, coordinator.Enlistment.RemoteTransactionId, coordinator.CoordinatorProxy != null ? coordinator.CoordinatorProxy.To : null, this.state.ProtocolVersion ); } coordinator.StateMachine.Enqueue(new TmReplayEvent(coordinator, callback, obj)); DebugTrace.TraceLeave(this, "Replay"); } public void RecoveryBeginning() { DebugTrace.TraceEnter(this, "RecoveryBeginning"); try { state.RecoveryBeginning(); } catch (Exception e) { DebugTrace.Trace(TraceLevel.Error, "RecoveryBeginning failed: {0}", e); ProtocolRecoveryBeginningFailureRecord.TraceAndLog(PluggableProtocol.Id(this.state.ProtocolVersion), PluggableProtocol.Name(this.state.ProtocolVersion), e); throw; } finally { DebugTrace.TraceLeave(this, "RecoveryBeginning"); } } public void RecoveryComplete() { DebugTrace.TraceEnter(this, "RecoveryComplete"); try { state.RecoveryComplete(); ProtocolRecoveryCompleteRecord.TraceAndLog(PluggableProtocol.Id(this.state.ProtocolVersion), PluggableProtocol.Name(this.state.ProtocolVersion)); } catch (Exception e) { DebugTrace.Trace(TraceLevel.Error, "RecoveryComplete failed: {0}", e); ProtocolRecoveryCompleteFailureRecord.TraceAndLog(PluggableProtocol.Id(this.state.ProtocolVersion), PluggableProtocol.Name(this.state.ProtocolVersion), e); throw; } finally { DebugTrace.TraceLeave(this, "RecoveryComplete"); } } } static class TransactionManagerResponse { // // Activation // public static void CreateTransactionResponse (Enlistment enlistment, Status status, object obj) { MsgCreateTransactionEvent e = (MsgCreateTransactionEvent) obj; CompletionEnlistment completion = (CompletionEnlistment) enlistment.ProtocolProviderContext; completion.StateMachine.Enqueue (new TmCreateTransactionResponseEvent (completion, status, e)); } public static void EnlistTransactionResponse (Enlistment enlistment, Status status, object obj) { MsgEnlistTransactionEvent e = (MsgEnlistTransactionEvent) obj; CoordinatorEnlistment coordinator = (CoordinatorEnlistment) enlistment.ProtocolProviderContext; coordinator.StateMachine.Enqueue (new TmEnlistTransactionResponseEvent (coordinator, status, e)); } // // Registration // public static void RegisterResponse (Enlistment enlistment, Status status, object obj) { MsgRegisterEvent source = (MsgRegisterEvent) obj; ParticipantEnlistment participant = (ParticipantEnlistment) enlistment.ProtocolProviderContext; participant.StateMachine.Enqueue (new TmRegisterResponseEvent(participant, status, source)); } public static void SubordinateRegisterResponse(Enlistment enlistment, Status status, object obj) { InternalEnlistSubordinateTransactionEvent source = (InternalEnlistSubordinateTransactionEvent) obj; ParticipantEnlistment participant = (ParticipantEnlistment) enlistment.ProtocolProviderContext; participant.StateMachine.Enqueue(new TmSubordinateRegisterResponseEvent(participant, status, source)); } // // Completion // public static void CompletionCommitResponse (Enlistment enlistment, Status status, object obj) { CompletionEnlistment completion = (CompletionEnlistment) obj; completion.StateMachine.Enqueue (new TmCompletionCommitResponseEvent (completion, status)); } public static void CompletionRollbackResponse (Enlistment enlistment, Status status, object obj) { CompletionEnlistment completion = (CompletionEnlistment) obj; completion.StateMachine.Enqueue (new TmCompletionRollbackResponseEvent (completion, status)); } // // TwoPhaseCommit // public static void PrePrepareResponse (Enlistment enlistment, Status status, object obj) { VolatileCoordinatorEnlistment coordinator = (VolatileCoordinatorEnlistment) obj; coordinator.StateMachine.Enqueue (new TmPrePrepareResponseEvent (coordinator, status)); } public static void PrepareResponse (Enlistment enlistment, Status status, object obj) { CoordinatorEnlistment coordinator = (CoordinatorEnlistment) obj; coordinator.StateMachine.Enqueue (new TmPrepareResponseEvent (coordinator, status)); } public static void CommitResponse (Enlistment enlistment, Status status, object obj) { CoordinatorEnlistment coordinator = (CoordinatorEnlistment) obj; coordinator.StateMachine.Enqueue (new TmCommitResponseEvent (coordinator, status)); } public static void RollbackResponse (Enlistment enlistment, Status status, object obj) { TransactionEnlistment txEnlistment = (TransactionEnlistment) obj; txEnlistment.StateMachine.Enqueue (new TmRollbackResponseEvent (txEnlistment, status)); } } } // 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
- Invariant.cs
- SystemThemeKey.cs
- Win32NamedPipes.cs
- ActivationServices.cs
- VisualBrush.cs
- GregorianCalendarHelper.cs
- SiteMap.cs
- BackgroundWorker.cs
- LinearGradientBrush.cs
- TypeDependencyAttribute.cs
- XPathChildIterator.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- ParseChildrenAsPropertiesAttribute.cs
- Missing.cs
- StyleTypedPropertyAttribute.cs
- UserControlBuildProvider.cs
- ErrorProvider.cs
- MobileListItemCollection.cs
- SharedConnectionListener.cs
- DispatcherSynchronizationContext.cs
- MessageEventSubscriptionService.cs
- HttpConfigurationSystem.cs
- XmlFormatWriterGenerator.cs
- StringKeyFrameCollection.cs
- ParameterCollectionEditor.cs
- DropDownHolder.cs
- ActiveXHelper.cs
- ListBindingHelper.cs
- UiaCoreProviderApi.cs
- VideoDrawing.cs
- ResolveResponseInfo.cs
- PagedDataSource.cs
- XmlParserContext.cs
- HtmlLiteralTextAdapter.cs
- FormViewRow.cs
- SortedSetDebugView.cs
- XmlResolver.cs
- _HeaderInfoTable.cs
- ListViewDeletedEventArgs.cs
- CompilerLocalReference.cs
- BufferedWebEventProvider.cs
- SessionPageStatePersister.cs
- InkCanvasAutomationPeer.cs
- OrderPreservingPipeliningSpoolingTask.cs
- GeneratedView.cs
- MultipartIdentifier.cs
- BindingCollectionElement.cs
- GeneralTransform3DGroup.cs
- CrossAppDomainChannel.cs
- OptimalTextSource.cs
- DelayedRegex.cs
- ClientUtils.cs
- TemplateNameScope.cs
- UpdateCommand.cs
- EventArgs.cs
- WindowsMenu.cs
- Symbol.cs
- DataSetMappper.cs
- ResourcePropertyMemberCodeDomSerializer.cs
- MdImport.cs
- RuleRefElement.cs
- UnionCodeGroup.cs
- ProfileServiceManager.cs
- BufferedWebEventProvider.cs
- Registration.cs
- Ipv6Element.cs
- XPathNavigatorKeyComparer.cs
- EDesignUtil.cs
- XmlWellformedWriter.cs
- ProcessModuleCollection.cs
- NavigationProperty.cs
- XmlFormatExtensionPointAttribute.cs
- TrustLevelCollection.cs
- PublisherIdentityPermission.cs
- DataSetViewSchema.cs
- ConfigurationValidatorBase.cs
- AdjustableArrowCap.cs
- ProcessModuleDesigner.cs
- HitTestParameters.cs
- CompilerErrorCollection.cs
- CustomTypeDescriptor.cs
- LicFileLicenseProvider.cs
- SectionInformation.cs
- DefaultHttpHandler.cs
- DataTemplate.cs
- SchemaNamespaceManager.cs
- CalendarModeChangedEventArgs.cs
- PropertyRef.cs
- QueryExecutionOption.cs
- DependencyPropertyKind.cs
- SqlProfileProvider.cs
- WebReferencesBuildProvider.cs
- LinqDataSourceDisposeEventArgs.cs
- ClientRoleProvider.cs
- EventBindingService.cs
- LogicalTreeHelper.cs
- AppDomainInfo.cs
- XmlSchemaIdentityConstraint.cs
- TransactionScope.cs
- SolidBrush.cs