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
- GridViewCellAutomationPeer.cs
- AnimationLayer.cs
- PartBasedPackageProperties.cs
- TableLayoutCellPaintEventArgs.cs
- AuthenticateEventArgs.cs
- ResponseBodyWriter.cs
- XmlSchema.cs
- WebColorConverter.cs
- Maps.cs
- EncryptedPackageFilter.cs
- RemotingAttributes.cs
- Stackframe.cs
- MarkupWriter.cs
- LookupNode.cs
- XmlSchemaAnnotated.cs
- ReferentialConstraint.cs
- TemplateComponentConnector.cs
- ScriptHandlerFactory.cs
- MobileControlDesigner.cs
- CheckableControlBaseAdapter.cs
- PenContext.cs
- EntityViewGenerationAttribute.cs
- UnicodeEncoding.cs
- GlyphingCache.cs
- HighContrastHelper.cs
- OneWayBindingElement.cs
- WindowsToolbar.cs
- PeerNameRegistration.cs
- OleDbTransaction.cs
- ReadOnlyDataSourceView.cs
- AdornerLayer.cs
- PropertyEntry.cs
- ResumeStoryboard.cs
- ScrollPatternIdentifiers.cs
- BufferAllocator.cs
- ObjectCache.cs
- TableRow.cs
- RegistryConfigurationProvider.cs
- Compiler.cs
- OdbcReferenceCollection.cs
- TableLayoutPanelBehavior.cs
- TransformProviderWrapper.cs
- ResourcePermissionBaseEntry.cs
- TextRangeEditLists.cs
- EdmProviderManifest.cs
- WrappingXamlSchemaContext.cs
- WebCodeGenerator.cs
- X509Utils.cs
- FilterableAttribute.cs
- TextMetrics.cs
- EntityType.cs
- AssemblyResourceLoader.cs
- PointUtil.cs
- DataGridColumnsPage.cs
- ReachDocumentSequenceSerializer.cs
- UserValidatedEventArgs.cs
- EmptyControlCollection.cs
- DetailsViewUpdateEventArgs.cs
- MenuItemCollectionEditorDialog.cs
- SoapIgnoreAttribute.cs
- TogglePattern.cs
- PassportAuthenticationEventArgs.cs
- EventDescriptor.cs
- MatrixTransform3D.cs
- GlobalProxySelection.cs
- TableRowGroup.cs
- RegistrationServices.cs
- DistributedTransactionPermission.cs
- PropertySourceInfo.cs
- EdmProperty.cs
- EventLogReader.cs
- SimpleHandlerBuildProvider.cs
- MappingSource.cs
- TypeSystem.cs
- XmlSchemaValidator.cs
- XNodeValidator.cs
- UnauthorizedAccessException.cs
- ProgressiveCrcCalculatingStream.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- HandlerBase.cs
- LinkedResource.cs
- SimpleWorkerRequest.cs
- CustomAttributeSerializer.cs
- DiagnosticsElement.cs
- HttpCacheVary.cs
- XmlFormatReaderGenerator.cs
- CodeSpit.cs
- UpdatePanelControlTrigger.cs
- BinaryCommonClasses.cs
- ButtonChrome.cs
- EntityDataSourceWrapper.cs
- InternalPermissions.cs
- XsltContext.cs
- Transactions.cs
- LessThanOrEqual.cs
- AnimationClock.cs
- UniqueConstraint.cs
- ZipIOExtraFieldElement.cs
- CustomErrorsSectionWrapper.cs
- ResXFileRef.cs