1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
use crate::rm::{RmRc, RmResult};
use crate::tm::XaTransactionId;

/// Interface of a resource manager, as required by a transaction manager.
///
pub trait ResourceManager: std::fmt::Debug {
    /// Tells the server to start work on behalf of the given transaction branch.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn start(&mut self, id: &XaTransactionId) -> RmResult<RmRc>;

    /// Tells the server to join working on behalf of the given transaction branch.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn start_by_joining(&mut self, id: &XaTransactionId) -> RmResult<RmRc>;

    /// Tells the server to resume working on behalf of the given transaction branch.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn start_by_resuming(&mut self, id: &XaTransactionId) -> RmResult<RmRc>;

    /// Tells the server to end working on behalf of the given transaction branch.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn end_success(&mut self, id: &XaTransactionId) -> RmResult<RmRc>;

    /// Tells the server to stop working on behalf of the given transaction branch, transaction
    /// will not be committed.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn end_failure(&mut self, id: &XaTransactionId) -> RmResult<RmRc>;

    /// Tells the server to suspend working on behalf of the given transaction branch.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn end_suspend(&mut self, id: &XaTransactionId) -> RmResult<RmRc>;

    /// Tells the server to prepare to commit the work done in the given transaction branch.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn prepare(&mut self, id: &XaTransactionId) -> RmResult<RmRc>;

    /// Tells the server to commit the work done in the given prepared transaction branch.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn commit(&mut self, id: &XaTransactionId) -> RmResult<RmRc>;

    /// Tells the server to commit the work done in the given not-prepared transaction branch.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn commit_one_phase(&mut self, id: &XaTransactionId) -> RmResult<RmRc>;

    /// Tells the server to rollback the work done in the given transaction branch.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn rollback(&mut self, id: &XaTransactionId) -> RmResult<RmRc>;

    /// Tells the server to forget about the given heuristically completed transaction.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn forget(&mut self, id: &XaTransactionId) -> RmResult<RmRc>;

    /// Returns the list of transactions that have been prepared or heuristically
    /// completed.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn recover(&mut self) -> RmResult<Vec<XaTransactionId>>;

    /// Returns the list of transactions that have been prepared or heuristically
    /// completed.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn begin_recover(&mut self) -> RmResult<Vec<XaTransactionId>>;

    /// Returns the list of transactions that have been prepared or heuristically
    /// completed.
    ///
    /// # Errors
    ///
    /// `RmError` if the request cannot be handled regularily.
    fn end_recover(&mut self) -> RmResult<Vec<XaTransactionId>>;
}