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
- CallbackValidator.cs
- TransformPatternIdentifiers.cs
- StreamWithDictionary.cs
- ConstantProjectedSlot.cs
- Currency.cs
- DirectoryNotFoundException.cs
- RectValueSerializer.cs
- As.cs
- Propagator.Evaluator.cs
- XpsSerializationException.cs
- DecodeHelper.cs
- BamlResourceDeserializer.cs
- HttpSessionStateBase.cs
- SizeKeyFrameCollection.cs
- StylusDownEventArgs.cs
- ObjectListCommandEventArgs.cs
- RoleGroupCollection.cs
- Int32AnimationUsingKeyFrames.cs
- BufferedGraphicsManager.cs
- ClientCultureInfo.cs
- DataObjectMethodAttribute.cs
- XmlNodeList.cs
- ISFTagAndGuidCache.cs
- GlyphRun.cs
- COMException.cs
- Deflater.cs
- LogLogRecord.cs
- MappingItemCollection.cs
- FormViewDeleteEventArgs.cs
- ToolBarButtonClickEvent.cs
- XmlSchemaInferenceException.cs
- TextFormatterContext.cs
- PropertyGridCommands.cs
- DataObjectAttribute.cs
- ItemMap.cs
- WebPartConnectVerb.cs
- TrailingSpaceComparer.cs
- FlowDocumentReaderAutomationPeer.cs
- RequestTimeoutManager.cs
- PointAnimationClockResource.cs
- WebPartDescription.cs
- DBConnectionString.cs
- CustomSignedXml.cs
- QuaternionAnimation.cs
- StructuredType.cs
- SiblingIterators.cs
- OracleString.cs
- CheckBoxBaseAdapter.cs
- EdmMember.cs
- WebPartConnectionsEventArgs.cs
- XmlWrappingReader.cs
- SessionState.cs
- DeferrableContent.cs
- SqlClientWrapperSmiStream.cs
- XmlSignificantWhitespace.cs
- CapabilitiesRule.cs
- DebuggerAttributes.cs
- ImageSourceConverter.cs
- OdbcPermission.cs
- SettingsPropertyIsReadOnlyException.cs
- streamingZipPartStream.cs
- Point.cs
- DataPagerField.cs
- DesigntimeLicenseContext.cs
- GPPOINT.cs
- GraphicsPathIterator.cs
- OleDbReferenceCollection.cs
- XPathAxisIterator.cs
- LineBreakRecord.cs
- DoubleAnimationBase.cs
- EditorZoneAutoFormat.cs
- FolderLevelBuildProviderAppliesToAttribute.cs
- StandardCommandToolStripMenuItem.cs
- KeyValueSerializer.cs
- TaskFactory.cs
- FloatUtil.cs
- LocalValueEnumerator.cs
- DataGridPageChangedEventArgs.cs
- DecoderExceptionFallback.cs
- DataRow.cs
- AspProxy.cs
- StatusBarItem.cs
- IndexedString.cs
- RequiredFieldValidator.cs
- SafeRightsManagementHandle.cs
- _NetRes.cs
- XmlWellformedWriter.cs
- ToolBarOverflowPanel.cs
- SortKey.cs
- BaseDataListComponentEditor.cs
- SBCSCodePageEncoding.cs
- DataGridViewButtonColumn.cs
- ChildTable.cs
- DataRowChangeEvent.cs
- DataTableMapping.cs
- CodeDelegateInvokeExpression.cs
- EntryPointNotFoundException.cs
- SignatureToken.cs
- EmptyStringExpandableObjectConverter.cs
- TypeDescriptionProviderAttribute.cs