IEnlistmentNotificationとは? わかりやすく解説

IEnlistmentNotification インターフェイス

メモ : このインターフェイスは、.NET Framework version 2.0新しく追加されたものです。

参加登録時に、トランザクション マネージャに対して 2 フェーズ コミット通知コールバックを行うために、リソース マネージャ実装する必要のあるインターフェイス示します

名前空間: System.Transactions
アセンブリ: System.Transactions (system.transactions.dll 内)
構文構文

Public Interface IEnlistmentNotification
Dim instance As IEnlistmentNotification
public interface IEnlistmentNotification
public interface class IEnlistmentNotification
public interface IEnlistmentNotification
public interface IEnlistmentNotification
解説解説

リソース マネージャトランザクション参加するには、トランザクション マネージャを介してトランザクション参加する必要がありますTransaction クラスは、この機能提供する、名前が Enlist から始まる一連のメソッド定義します異なEnlist メソッドは、リソース マネージャが持つ異な種類参加リストそれぞれ対応してます。

このクラスは、参加登録時トランザクション マネージャに対して 2 フェーズ コミット通知コールバックを行うために、リソース マネージャ実装する必要のあるインターフェイス示しますリソース マネージャIEnlistmentNotification インターフェイスの各実装ごとに、リソース揮発性であるか永続的であるかに応じてTransaction クラスの EnlistVolatile メソッドまたは EnlistDurable メソッド使用してリソース マネージャ参加させる必要があります参加リストと 2PC の詳細については、それぞれトランザクションへの参加要素としてのリソースの登録」および「単一フェーズおよびマルチフェーズでのトランザクションコミット」を参照してください

トランザクション マネージャは、次のメソッド使用して2 フェーズ コミット プロトコル異なフェーズで、参加オブジェクト通知行います

メモメモ

通知は、順番に、つまり特定の順序送信されない可能性があることに注意してください

使用例使用例

次の例では、このインターフェイス実装し、EnlistVolatile メソッド使用してオブジェクト参加要素としてトランザクション参加させます

    Public Shared Sub Main()
        Try
            Using scope As TransactionScope = New
 TransactionScope()

                'Create an enlistment object
                Dim myEnlistmentClass As New
 EnlistmentClass

                'Enlist on the current transaction with the enlistment
 object
                Transaction.Current.EnlistVolatile(myEnlistmentClass, EnlistmentOptions.None)

                'Perform transactional work here.

                'Call complete on the TransactionScope based on console
 input
                Dim c As ConsoleKeyInfo
                While (True)
                    Console.Write("Complete the transaction scope?
 [Y|N] ")
                    c = Console.ReadKey()
                    Console.WriteLine()
                    If (c.KeyChar = "Y")
 Or (c.KeyChar = "y") Then
                        scope.Complete()
                        Exit While
                    ElseIf ((c.KeyChar = "N")
 Or (c.KeyChar = "n")) Then
                        Exit While
                    End If
                End While
            End Using
        Catch ex As TransactionException
            Console.WriteLine(ex)
        Catch
            Console.WriteLine("Cannot complete transaction")
            Throw
        End Try
    End Sub
End Class

Public Class EnlistmentClass
    Implements IEnlistmentNotification

    Public Sub Prepare(ByVal
 myPreparingEnlistment As PreparingEnlistment) Implements
 System.Transactions.IEnlistmentNotification.Prepare
        Console.WriteLine("Prepare notification received")

        'Perform transactional work

        'If work finished correctly, reply with prepared
        myPreparingEnlistment.Prepared()
    End Sub

    Public Sub Commit(ByVal
 myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.Commit
        Console.WriteLine("Commit notification received")

        'Do any work necessary when commit notification is received

        'Declare done on the enlistment
        myEnlistment.Done()
    End Sub

    Public Sub Rollback(ByVal
 myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.Rollback
        Console.WriteLine("Rollback notification received")

        'Do any work necessary when rollback notification is received

        'Declare done on the enlistment
        myEnlistment.Done()
    End Sub

    Public Sub InDoubt(ByVal
 myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.InDoubt
        Console.WriteLine("In doubt notification received")

        'Do any work necessary when indout notification is received

        'Declare done on the enlistment
        myEnlistment.Done()
    End Sub
End Class

static void Main(string[]
 args)
{
    try
    {
        using (TransactionScope scope = new
 TransactionScope())
        {
        
            //Create an enlistment object
            myEnlistmentClass myElistment = new myEnlistmentClass();

            //Enlist on the current transaction with the enlistment
 object
            Transaction.Current.EnlistVolatile(myElistment, EnlistmentOptions.None);

            //Perform transactional work here.

            //Call complete on the TransactionScope based on console
 input
                            ConsoleKeyInfo c;
            while(true)
                            {
                Console.Write("Complete the transaction scope? [Y|N] ");
                c = Console.ReadKey();
                Console.WriteLine();
        
                                    if ((c.KeyChar == 'Y') ||
 (c.KeyChar == 'y'))
                {
                    scope.Complete();
                    break;
                }
                else if ((c.KeyChar == 'N')
 || (c.KeyChar == 'n'))
                {
                    break;
                }
            }
        }
    }
    catch (System.Transactions.TransactionException ex)
    {
        Console.WriteLine(ex);
    }
    catch
    {
        Console.WriteLine("Cannot complete transaction");
        throw;
    }
}

class myEnlistmentClass : IEnlistmentNotification
{
    public void Prepare(PreparingEnlistment
 preparingEnlistment)
    {
        Console.WriteLine("Prepare notification received");

        //Perform transactional work

        //If work finished correctly, reply prepared
        preparingEnlistment.Prepared();

        // otherwise, do a ForceRollback
        preparingEnlistment.ForceRollback();
    }

    public void Commit(Enlistment enlistment)
    {
        Console.WriteLine("Commit notification received");

        //Do any work necessary when commit notification is received

        //Declare done on the enlistment
        enlistment.Done();
    }

    public void Rollback(Enlistment enlistment)
    {
        Console.WriteLine("Rollback notification received");

        //Do any work necessary when rollback notification is received

        //Declare done on the enlistment
        enlistment.Done();
    }

    public void InDoubt(Enlistment enlistment)
    {
        Console.WriteLine("In doubt notification received");

        //Do any work necessary when indout notification is received
        
        //Declare done on the enlistment
        enlistment.Done();
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IEnlistmentNotification メソッド


IEnlistmentNotification メンバ




英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「IEnlistmentNotification」の関連用語

IEnlistmentNotificationのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IEnlistmentNotificationのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS