This chapter explains how you can develop your own C application using the libraries and tools supplied by the LIXA project.
The LIXA project ships with some example C programs that you can find in the /opt/lixa/share/doc/lixa-X.Y.Z/examples
folder after software installation (see Chapter 2, Installation).
This chapter is focused on the C programming language for the non-standard extensions that has been added to the TX specification to expose some of the XA interface capabilities. All the information supplied in Chapter 5, Developing C Application Programs using TX (Transaction Demarcation) interface still applies.
The LIXA project provides extensions to the [TXspec], named Transaction Coupling (TC) [39], which can be used in addition to the standard API when developing distributed Application Programs.
The API extensions are easy to use and the following C example briefly explains it:
#include <tx.h> /* your includes */ int main(int argc, char *argv[]) { int rc; if (TX_OK != (rc = tx_open())) /* handle error */ if (TX_OK != (rc = tx_begin())) /* handle error */ /* do local work against Resource Manager here */ /* suspend the transaction so that work can continue elsewhere */ if (TX_OK != (rc = tx_end(TX_TMSUSPEND))) /* handle error */ /* in another thread or another Application Program work can continue on the same transaction */ TXINFO txinfo; if (TX_OK != (rc = tx_info(&txinfo))) /* handle error */ if (TX_OK != (rc = tx_join(&txinfo.xid))) /* handle error */ if (TX_OK != (rc = tx_end(TX_TMSUCCESS))) /* handle error */ /* take up transaction again */ if (TX_OK != (rc = tx_resume(&txinfo.xid))) /* handle error */ /* commit or roll back transaction */ if (TX_OK != (rc = tx_commit())) /* handle errror */ /* shut down */ tx_close(); }
These are the available C functions:
tx_end
: manage the global transaction with flags
:
TX_TMSUSPEND
: suspend the transaction
TX_TMSUCCESS
: mark the portion of work on the global transaction as successful
TX_TMFAIL
: mark the portion of work on the global transaction as failed
tx_join
: join a suspended global transaction and continue work
tx_resume
: resume a suspended global transaction - only from the thread that suspended the original transaction