public interface DpTransCallback
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 ...
Modifier and Type | Field and Description |
---|---|
static int |
M_ABORT
Bit flag for the
abort(DpTrans) method. |
static int |
M_ALL |
static int |
M_COMMIT
Bit flag for the
commit(DpTrans) method. |
static int |
M_FINISH
Bit flag for the
finish(DpTrans) method. |
static int |
M_INIT
Bit flag for the
init(DpTrans) method. |
static int |
M_PREPARE
Bit flag for the
prepare(DpTrans) method. |
static int |
M_TRANS_LOCK
Bit flag for the
transLock(DpTrans) method. |
static int |
M_TRANS_UNLOCK
Bit flag for the
transUnlock(DpTrans) method. |
static int |
M_WRITE_START
Bit flag for the
writeStart(DpTrans) method. |
Modifier and Type | Method and Description |
---|---|
void |
abort(DpTrans trans)
This callback is responsible for
undoing whatever was done in the prepare() phase.
|
void |
commit(DpTrans trans)
This callback is responsible for
undoing whatever was done in the prepare() phase.
|
void |
finish(DpTrans trans)
This callback is responsible for
releasing resources allocated in the init() phase.
|
void |
init(DpTrans trans)
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 |
prepare(DpTrans trans)
If we have multiple sources of data it is highly recommended
that the callback is implemented.
|
void |
transLock(DpTrans trans)
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.
|
static final int M_ABORT
abort(DpTrans)
method.static final int M_ALL
static final int M_COMMIT
commit(DpTrans)
method.static final int M_FINISH
finish(DpTrans)
method.static final int M_INIT
init(DpTrans)
method.static final int M_PREPARE
prepare(DpTrans)
method.static final int M_TRANS_LOCK
transLock(DpTrans)
method.static final int M_TRANS_UNLOCK
transUnlock(DpTrans)
method.static final int M_WRITE_START
writeStart(DpTrans)
method.void abort(DpTrans trans) throws DpCallbackException
trans
- TransactionDpCallbackException
- Callback method failed.void commit(DpTrans trans) throws DpCallbackException
trans
- TransactionDpCallbackException
- Callback method failed.void finish(DpTrans trans) throws DpCallbackException
trans
- TransactionDpCallbackException
- Callback method failed.void init(DpTrans trans) throws DpCallbackException
trans
- TransactionDpCallbackException
- Callback method failed.int mask()
void prepare(DpTrans trans) throws DpCallbackException
trans
- TransactionDpCallbackException
- Callback method failed.void transLock(DpTrans trans) throws DpCallbackException
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.
trans
- TransactionDpCallbackException
- Callback method failed.void transUnlock(DpTrans trans) throws DpCallbackException
The transaction re-enters READ state.
trans
- TransactionDpCallbackException
- Callback method failed.void writeStart(DpTrans trans) throws DpCallbackException
The transaction enters the WRITE state. No more read() operations will be performed by the system.
trans
- TransactionDpCallbackException
- Callback method failed.