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 ...
Dp.registerAnnotatedCallbacks(Object)
Modifier and Type | Field and Description |
---|---|
static int |
M_ABORT
Bit flag for the
DpTransCallback.abort(DpTrans) method. |
static int |
M_ALL |
static int |
M_COMMIT
Bit flag for the
DpTransCallback.commit(DpTrans) method. |
static int |
M_FINISH
Bit flag for the
DpTransCallback.finish(DpTrans) method. |
static int |
M_INIT
Bit flag for the
DpTransCallback.init(DpTrans) method. |
static int |
M_PREPARE
Bit flag for the
DpTransCallback.prepare(DpTrans) method. |
static int |
M_TRANS_LOCK
Bit flag for the
DpTransCallback.transLock(DpTrans) method. |
static int |
M_TRANS_UNLOCK
Bit flag for the
DpTransCallback.transUnlock(DpTrans) method. |
static int |
M_WRITE_START
Bit flag for the
DpTransCallback.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:
DpTransCallback.M_INIT
DpTransCallback.M_TRANS_LOCK
DpTransCallback.M_TRANS_UNLOCK
DpTransCallback.M_WRITE_START
DpTransCallback.M_PREPARE
DpTransCallback.M_ABORT
DpTransCallback.M_COMMIT
DpTransCallback.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_INIT
DpTransCallback.init(DpTrans)
method.static final int M_TRANS_LOCK
DpTransCallback.transLock(DpTrans)
method.static final int M_TRANS_UNLOCK
DpTransCallback.transUnlock(DpTrans)
method.static final int M_WRITE_START
DpTransCallback.writeStart(DpTrans)
method.static final int M_PREPARE
DpTransCallback.prepare(DpTrans)
method.static final int M_ABORT
DpTransCallback.abort(DpTrans)
method.static final int M_COMMIT
DpTransCallback.commit(DpTrans)
method.static final int M_FINISH
DpTransCallback.finish(DpTrans)
method.static final int M_ALL
int mask()
void init(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.void prepare(DpTrans trans) throws DpCallbackException
trans
- TransactionDpCallbackException
- Callback method failed.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.