Interface DpTransCallback
- All Known Implementing Classes:
TransCallbackProxy
In order to orchestrate transactions with multiple sources of data, ConfD/NCS implements a two-phase commit protocol towards all data sources that participate in a transaction.
Each NETCONF operation will be an individual transaction. These transactions are typically very short lived. Transactions originating from the CLI or the Web UI have longer life. The transaction can be viewed as a conceptual state machine where the different phases of the transaction are different states and the invocations of the callback functions are state transitions. The following ASCII art depicts the state machine.
+-------+
| START |
+-------+
| init()
|
v
read() +------+ finish()
------> | READ | --------------------> START
+------+
^ |
trans_unlock() | | trans_lock()
| v
read() +----------+ finish()
------> | VALIDATE | -----------------> START
+----------+
| write_start()
|
v
write() +-------+ finish()
-------> | WRITE | -------------------> START
+-------+
| prepare()
|
v
+----------+ commit() +-----------+
| PREPARED | -----------> | COMMITTED |
+----------+ +-----------+
| abort() |
| | finish()
v |
+---------+ v
| ABORTED | START
+---------+
| finish()
|
v
START
Example: Callback class MyTransCb
* public class MyTransCb { @TransCallback(callType=TransCBType.INIT) public void init(DpTrans trans) throws DpCallbackException { trace("init(): userinfo= " + trans.getUserInfo()); } @TransCallback(callType=TransCBType.FINISH) public void finish(DpTrans trans) throws DpCallbackException { trace("finish()"); } } // And so on ...
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Bit flag for theabort(DpTrans)
method.static final int
static final int
Bit flag for thecommit(DpTrans)
method.static final int
Bit flag for thefinish(DpTrans)
method.static final int
Bit flag for theinit(DpTrans)
method.static final int
Bit flag for theprepare(DpTrans)
method.static final int
Bit flag for thetransLock(DpTrans)
method.static final int
Bit flag for thetransUnlock(DpTrans)
method.static final int
Bit flag for thewriteStart(DpTrans)
method. -
Method Summary
Modifier and TypeMethodDescriptionvoid
This callback is responsible for undoing whatever was done in the prepare() phase.void
This callback is responsible for undoing whatever was done in the prepare() phase.void
This callback is responsible for releasing resources allocated in the init() phase.void
The callback must indicate which WORKER_SOCKET should be used for future communications in this transaction.int
mask()
Mask of flags for each method that is supported by this callback:M_INIT
M_TRANS_LOCK
M_TRANS_UNLOCK
M_WRITE_START
M_PREPARE
M_ABORT
M_COMMIT
M_FINISH
void
If we have multiple sources of data it is highly recommended that the callback is implemented.void
This callback is invoked when the validation phase of the transaction starts.void
transUnlock
(DpTrans trans) This callback is called when the validation of the transaction failed, or the validation is triggered explicitly (i.e.void
writeStart
(DpTrans trans) This callback is invoked when the validation succeeded and the write phase of the transaction starts.
-
Field Details
-
M_INIT
static final int M_INITBit flag for theinit(DpTrans)
method.- See Also:
-
M_TRANS_LOCK
static final int M_TRANS_LOCKBit flag for thetransLock(DpTrans)
method.- See Also:
-
M_TRANS_UNLOCK
static final int M_TRANS_UNLOCKBit flag for thetransUnlock(DpTrans)
method.- See Also:
-
M_WRITE_START
static final int M_WRITE_STARTBit flag for thewriteStart(DpTrans)
method.- See Also:
-
M_PREPARE
static final int M_PREPAREBit flag for theprepare(DpTrans)
method.- See Also:
-
M_ABORT
static final int M_ABORTBit flag for theabort(DpTrans)
method.- See Also:
-
M_COMMIT
static final int M_COMMITBit flag for thecommit(DpTrans)
method.- See Also:
-
M_FINISH
static final int M_FINISHBit flag for thefinish(DpTrans)
method.- See Also:
-
M_ALL
static final int M_ALL- See Also:
-
-
Method Details
-
mask
int mask()Mask of flags for each method that is supported by this callback: -
init
The callback must indicate which WORKER_SOCKET should be used for future communications in this transaction. This is the mechanism which is used by Conf to distribute work among multiple worker threads in the database application.- Parameters:
trans
- Transaction- Throws:
DpCallbackException
- Callback method failed.
-
transLock
This callback is invoked when the validation phase of the transaction starts. If the underlying database supports real transactions, it is usually appropriate to start such a native transaction here.The transaction enters VALIDATE state, where the system will perform a series of read() operations.
The trans lock is set until either transUnlock() or finish() is called. the system ensures that a transLock is set on a single transaction only.
- Parameters:
trans
- Transaction- Throws:
DpCallbackException
- Callback method failed.
-
transUnlock
This callback is called when the validation of the transaction failed, or the validation is triggered explicitly (i.e. not part of a user can enter invalid data. Transactions that originate from NETCONF will never trigger this callback. If the underlying database supports real transactions and they are used, the transaction should be aborted here.The transaction re-enters READ state.
- Parameters:
trans
- Transaction- Throws:
DpCallbackException
- Callback method failed.
-
writeStart
This callback is invoked when the validation succeeded and the write phase of the transaction starts. If the underlying database supports real transactions, it is usually appropriate to start such a native transaction here.The transaction enters the WRITE state. No more read() operations will be performed by the system.
- Parameters:
trans
- Transaction- Throws:
DpCallbackException
- Callback method failed.
-
prepare
If we have multiple sources of data it is highly recommended that the callback is implemented. The callback is called at the end of the transaction, when all read and write operations for the transaction have been performed and the transaction should prepare to commit.- Parameters:
trans
- Transaction- Throws:
DpCallbackException
- Callback method failed.
-
abort
This callback is responsible for undoing whatever was done in the prepare() phase.- Parameters:
trans
- Transaction- Throws:
DpCallbackException
- Callback method failed.
-
commit
This callback is responsible for undoing whatever was done in the prepare() phase.- Parameters:
trans
- Transaction- Throws:
DpCallbackException
- Callback method failed.
-
finish
This callback is responsible for releasing resources allocated in the init() phase.- Parameters:
trans
- Transaction- Throws:
DpCallbackException
- Callback method failed.
-