Compensator 클래스

정의

모든 CRM(Compensating Resource Manager) Compensator에 대한 기본 클래스를 나타냅니다.

public ref class Compensator : System::EnterpriseServices::ServicedComponent
public class Compensator : System.EnterpriseServices.ServicedComponent
type Compensator = class
    inherit ServicedComponent
Public Class Compensator
Inherits ServicedComponent
상속

예제

다음 코드 예제에서는이 클래스를 사용 하는 방법을 보여 줍니다.

// A CRM Compensator
public ref class AccountCompensator : public Compensator
{
private:
    bool receivedPrepareRecord;

public:
    AccountCompensator()
    {
        receivedPrepareRecord = false;
    } 

public:
    virtual void BeginPrepare() override 
    {
        // nothing to do
    }

public:
    virtual bool PrepareRecord(LogRecord^ log) override 
    {

        // Check the validity of the record.
        if (log == nullptr)
        {
            return false;
        }
        array<Object^>^ record = dynamic_cast<array<Object^>^>(log->Record);
        if (record == nullptr)
        {
            return false;
        }
        if (record->Length != 2)
        {
            return false;
        }

        // The record is valid.
        receivedPrepareRecord = true;
        return true;              
    }

public:
    virtual bool EndPrepare() override
    {
        // Allow the transaction to proceed onlyif we have received a prepare
        // record.
        if (receivedPrepareRecord)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual void BeginCommit(bool commit) override
    {
        // nothing to do
    }

public:
    virtual bool CommitRecord(LogRecord^ log) override
    {
        // nothing to do
        return(false);
    }

public:
    virtual void EndCommit() override
    {
        // nothing to do
    }

public:
    virtual void BeginAbort(bool abort) override
    {
        // nothing to do
    }

public:
    virtual bool AbortRecord(LogRecord^ log) override
    {

        // Check the validity of the record.
        if (log == nullptr)
        {
            return true;
        }
        array<Object^>^ record = dynamic_cast<array<Object^>^>(log->Record);
        if (record == nullptr)
        {
            return true;
        }
        if (record->Length != 2)
        {
            return true;
        }

        // Extract old account data from the record.
        String^ filename = (String^) record[0];
        int balance = (int) record[1];

        // Restore the old state of the account.
        WriteAccountBalance(filename, balance);

        return false;
    }

public:
    virtual void EndAbort() override
    {
        // nothing to do
    }    

};
// A CRM Compensator
public class AccountCompensator : Compensator
{

    private bool receivedPrepareRecord = false;

    public override void BeginPrepare ()
    {
        // nothing to do
    }

    public override bool PrepareRecord (LogRecord log)
    {

        // Check the validity of the record.
        if (log == null) return(true);
        Object[] record = log.Record as Object[];
        if (record == null) return(true);
        if (record.Length != 2) return(true);

        // The record is valid.
        receivedPrepareRecord = true;
        return(false);
    }

    public override bool EndPrepare ()
    {
        // Allow the transaction to proceed onlyif we have received a prepare record.
        if (receivedPrepareRecord)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }

    public override void BeginCommit (bool commit)
    {
        // nothing to do
    }

    public override bool CommitRecord (LogRecord log)
    {
        // nothing to do
        return(false);
    }

    public override void EndCommit ()
    {
        // nothing to do
    }

    public override void BeginAbort (bool abort)
    {
        // nothing to do
    }

    public override bool AbortRecord (LogRecord log)
    {

        // Check the validity of the record.
        if (log == null) return(true);
        Object[] record = log.Record as Object[];
        if (record == null) return(true);
        if (record.Length != 2) return(true);

        // Extract old account data from the record.
        string filename = (string) record[0];
        int balance = (int) record[1];

        // Restore the old state of the account.
        AccountManager.WriteAccountBalance(filename, balance);

        return(false);
    }

    public override void EndAbort ()
    {
        // nothing to do
    }
}
' A CRM Compensator

Public Class AccountCompensator
    Inherits Compensator
    
    Private receivedPrepareRecord As Boolean = False
    
    
    Public Overrides Sub BeginPrepare() 
    
    End Sub
    
    ' nothing to do
    Public Overrides Function PrepareRecord(ByVal log As LogRecord) As Boolean 
        
        ' Check the validity of the record.
        If log Is Nothing Then
            Return True
        End If
        Dim record As [Object]() = log.Record
        
        If record Is Nothing Then
            Return True
        End If
        If record.Length <> 2 Then
            Return True
        End If 
        ' The record is valid.
        receivedPrepareRecord = True
        Return False
    
    End Function 'PrepareRecord
    
    Public Overrides Function EndPrepare() As Boolean 
        ' Allow the transaction to proceed onlyif we have received a prepare record.
        If receivedPrepareRecord Then
            Return True
        Else
            Return False
        End If
    
    End Function 'EndPrepare
    
    Public Overrides Sub BeginCommit(ByVal commit As Boolean) 
    
    End Sub
    
    ' nothing to do
    Public Overrides Function CommitRecord(ByVal log As LogRecord) As Boolean 
        ' nothing to do
        Return False
    
    End Function 'CommitRecord
    
    Public Overrides Sub EndCommit() 
    
    End Sub
    
    ' nothing to do
    Public Overrides Sub BeginAbort(ByVal abort As Boolean) 
    
    End Sub
    
    ' nothing to do
    Public Overrides Function AbortRecord(ByVal log As LogRecord) As Boolean 
        
        ' Check the validity of the record.
        If log Is Nothing Then
            Return True
        End If
        Dim record As [Object]() = log.Record
        
        If record Is Nothing Then
            Return True
        End If
        If record.Length <> 2 Then
            Return True
        End If 
        ' Extract old account data from the record.
        Dim filename As String = CStr(record(0))
        Dim balance As Integer = Fix(record(1))
        
        ' Restore the old state of the account.
        AccountManager.WriteAccountBalance(filename, balance)
        
        Return False
    
    End Function 'AbortRecord
    
    Public Overrides Sub EndAbort() 
    
    End Sub
End Class

이 compensator에이 게 다음 작업자 클래스에 의해 사용 됩니다.

// A CRM Worker
[Transaction]
public ref class Account : public ServicedComponent
{

    // A data member for the account file name.
private:
    String^ filenameValue;

public:
    property String^ Filename
    {
        String^ get()
        {
            return filenameValue;
        }
        void set( String^ value )
        {
            filenameValue = value;
        }
    }

    // A boolean data member that determines whether to commit or abort the 
    // transaction.
private:
    bool allowCommitValue;

public:
    property bool AllowCommit
    {
        bool get()
        {
            return allowCommitValue;
        }
        void set( bool value )
        {
            allowCommitValue = value;
        }
    }

    // Debit the account, 
public:
    void DebitAccount(int amount)
    {

        // Create a new clerk using the AccountCompensator class.
        Clerk^ clerk = gcnew Clerk(AccountCompensator::typeid,
            "An account transaction compensator", CompensatorOptions::AllPhases);

        // Create a record of previous account status, and deliver it to the
        // clerk.
        int balance = ReadAccountBalance(Filename);

        array<Object^>^ record = gcnew array<Object^>(2);
        record[0] = Filename;
        record[1] = balance;

        clerk->WriteLogRecord(record);
        clerk->ForceLog();

        // Perform the transaction
        balance -= amount;

        Console::WriteLine("{0}: {1}", Filename, balance);

        WriteAccountBalance(Filename, balance);

        // Commit or abort the transaction 
        if (AllowCommit)
        {
            ContextUtil::SetComplete();
        }
        else
        {
            ContextUtil::SetAbort();
        }

    }

};
// A CRM Worker
[Transaction]
public class Account : ServicedComponent
{

    // A data member for the account file name.
    private string filename;

    public string Filename
    {
        get
        {
            return(filename);
        }
        set
        {
            filename = value;
        }
    }

    // A boolean data member that determines whether to commit or abort the transaction.
    private bool commit;

    public bool AllowCommit
    {
        get
        {
            return(commit);
        }
        set
        {
            commit = value;
        }
    }

    // Debit the account,
    public void DebitAccount (int ammount)
    {

        // Create a new clerk using the AccountCompensator class.
        Clerk clerk = new Clerk(typeof(AccountCompensator),
          "An account transaction compensator", CompensatorOptions.AllPhases);

        // Create a record of previous account status, and deliver it to the clerk.
        int balance = AccountManager.ReadAccountBalance(filename);

    Object[] record = new Object[2];
    record[0] = filename;
        record[1] = balance;

        clerk.WriteLogRecord(record);
        clerk.ForceLog();

        // Perform the transaction
        balance -= ammount;
        AccountManager.WriteAccountBalance(filename, balance);

        // Commit or abort the transaction
        if (commit)
        {
            ContextUtil.SetComplete();
        }
        else
        {
            ContextUtil.SetAbort();
        }
    }
}
' A CRM Worker
<Transaction()>  _
Public Class Account
    Inherits ServicedComponent
    
    ' A data member for the account file name.
    Private filename As String
    
    
    Public Property Filenam() As String
        Get
            Return Filename
        End Get
        Set(ByVal value As String)
            filename = Value
        End Set
    End Property
    
    
    ' A boolean data member that determines whether to commit or abort the transaction.
    Private commit As Boolean
    
    
    Public Property AllowCommit() As Boolean 
        Get
            Return commit
        End Get
        Set
            commit = value
        End Set
    End Property
    
    
    
    
    ' Debit the account, 
    Public Sub DebitAccount(ByVal ammount As Integer) 
        
        ' Create a new clerk using the AccountCompensator class.
        Dim clerk As New Clerk(GetType(AccountCompensator), "An account transaction compensator", CompensatorOptions.AllPhases)
        ' Create a record of previous account status, and deliver it to the clerk.
        Dim balance As Integer = AccountManager.ReadAccountBalance(Filenam)
        
        Dim record(1) As [Object]
        record(0) = filename
        record(1) = balance
        
        clerk.WriteLogRecord(record)
        clerk.ForceLog()
        ' Perform the transaction
        balance -= ammount
        AccountManager.WriteAccountBalance(filename, balance)
        
        ' Commit or abort the transaction 
        If commit Then
            ContextUtil.SetComplete()
        Else
            ContextUtil.SetAbort()
        End If
    End Sub
    
End Class

다음 코드 예제에서는이 보상 및 작업자를 실행 하는 클라이언트를 보여 줍니다.

#using "System.EnterpriseServices.dll"

using namespace System;

[assembly: System::Reflection::AssemblyKeyFile("CrmServer.key")];

int main ()
{

    // Create a new account object. The object is created in a COM+ server application.
    Account^ account = gcnew Account();

    // Transactionally debit the account.
    try
    {
        account->Filename = System::IO::Path::GetFullPath("JohnDoe");
        account->AllowCommit = true;
        account->DebitAccount(3);
    }
    finally
    {
        delete account;
    }

}
using System;

public class CrmClient
{

    public static void Main ()
    {

        // Create a new account object. The object is created in a COM+ server application.
        Account account = new Account();

        // Transactionally debit the account.
        try
        {
            account.Filename = System.IO.Path.GetFullPath("JohnDoe");
            account.AllowCommit = true;
            account.DebitAccount(3);
        }
        finally
        {
            account.Dispose();
        }
    }
}
Public Class CrmClient
    
    
    Public Shared Sub Main() 
        
        ' Create a new account object. The object is created in a COM+ server application.
        Dim account As New Account()
        
        ' Transactionally debit the account.
        Try
            account.Filenam = System.IO.Path.GetFullPath("JohnDoe")
            account.AllowCommit = True
            account.DebitAccount(3)
        Finally
            account.Dispose()
        End Try
    
    End Sub
End Class

설명

사용자는 사용자 지정 트랜잭션 보상을 작성 하기 위해이 개체에서 확장 해야 합니다.

Compensator에 게는 항상 public 생성자를; 있어야 그렇지 않으면 해당 복구 엔진 만들 수 없습니다.

자세한 내용은 방법:는 Manager CRM (Compensating Resource)을 만들.

생성자

Compensator()

Compensator 클래스의 새 인스턴스를 초기화합니다.

속성

Clerk

CRM(Compensating Resource Manager) Clerk 개체를 나타내는 값을 가져옵니다.

메서드

AbortRecord(LogRecord)

중단 단계에서 CRM(Compensating Resource Manager) Compensator에 로그 레코드를 전달합니다.

Activate()

풀에서 개체를 만들거나 할당할 때 인프라에서 호출합니다. 이 메서드를 재정의하여 사용자 지정 초기화 코드를 개체에 추가합니다.

(다음에서 상속됨 ServicedComponent)
BeginAbort(Boolean)

CRM(Compensating Resource Manager) Compensator에게 트랜잭션 완료의 중단 단계이고 레코드가 전달될 예정임을 알립니다.

BeginCommit(Boolean)

CRM(Compensating Resource Manager) Compensator에게 트랜잭션 완료의 커밋 단계이고 레코드가 전달될 예정임을 알립니다.

BeginPrepare()

CRM(Compensating Resource Manager) Compensator에게 트랜잭션 완료의 준비 단계이고 레코드가 전달될 예정임을 알립니다.

CanBePooled()

개체가 풀에 다시 배치되기 전에 인프라에서 이 메서드를 호출합니다. 이 메서드를 재정의하여 개체를 풀에 다시 배치할지 여부를 결정합니다.

(다음에서 상속됨 ServicedComponent)
CommitRecord(LogRecord)

커밋 단계 중에 전달 순서에 따라 로그 레코드를 전달합니다.

Construct(String)

생성자를 호출하여 생성자 문자열이 전달된 후 바로 인프라에서 호출합니다. 이 메서드를 재정의하여 생성 문자열 값을 사용합니다.

(다음에서 상속됨 ServicedComponent)
CreateObjRef(Type)

원격 개체와 통신하는 데 사용되는 프록시 생성에 필요한 모든 관련 정보가 들어 있는 개체를 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
Deactivate()

개체가 비활성화되기 직전에 인프라에서 호출합니다. JIT(Just-In-Time) 컴파일된 코드나 개체 풀링이 사용될 때 이 메서드를 재정의하여 사용자 지정 종료 코드를 개체에 추가합니다.

(다음에서 상속됨 ServicedComponent)
Dispose()

ServicedComponent에서 사용하는 모든 리소스를 해제합니다.

(다음에서 상속됨 ServicedComponent)
Dispose(Boolean)

ServicedComponent에서 사용하는 관리되지 않는 리소스를 해제하고, 관리되는 리소스를 선택적으로 해제할 수 있습니다.

(다음에서 상속됨 ServicedComponent)
EndAbort()

CRM(Compensating Resource Manager) Compensator에게 중단 단계 중에 사용할 수 있는 모든 로그 레코드를 받았음을 알립니다.

EndCommit()

CRM(Compensating Resource Manager) Compensator에게 커밋 단계 중에 사용할 수 있는 모든 로그 레코드를 전달했음을 알립니다.

EndPrepare()

CRM(Compensating Resource Manager) Compensator에게 준비 단계 중에 사용할 수 있는 모든 로그 레코드가 있음을 알립니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 현재의 수명 서비스 개체를 검색합니다.

(다음에서 상속됨 MarshalByRefObject)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
InitializeLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 수명 서비스 개체를 가져옵니다.

(다음에서 상속됨 MarshalByRefObject)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
MemberwiseClone(Boolean)

현재 MarshalByRefObject 개체의 단순 복사본을 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
PrepareRecord(LogRecord)

준비 단계 중에 전달 순서에 따라 로그 레코드를 전달합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

IRemoteDispatch.RemoteDispatchAutoDone(String)

이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다.

COM+ 컨텍스트에서 원격 메서드 호출 후 ServicedComponent 클래스 개체의 done 비트가 true로 설정되도록 합니다.

(다음에서 상속됨 ServicedComponent)
IRemoteDispatch.RemoteDispatchNotAutoDone(String)

COM+ 컨텍스트에서 원격 메서드 호출 후 ServicedComponent 클래스 개체의 done 비트가 true로 설정되도록 보장하지 않습니다.

(다음에서 상속됨 ServicedComponent)
IServicedComponentInfo.GetComponentInfo(Int32, String[])

ServicedComponent 클래스 인스턴스에 대한 특정 정보를 가져옵니다.

(다음에서 상속됨 ServicedComponent)

적용 대상