The first example

Figure 5.1. Deploy model of an example with two dummy resource managers

Deploy model of an example with two dummy resource managers

Create a working directory in a place you are comfortable with:

[Shell terminal session]
tiian@ubuntu:~$ cd
tiian@ubuntu:~$ mkdir tmp
tiian@ubuntu:~$ cd tmp
tiian@ubuntu:~/tmp$
	

Copy file example1.c in your working dir:

[Shell terminal session]
tiian@ubuntu:~/tmp$ cp /opt/lixa/share/doc/lixa-X.Y.Z/examples/example1.c .
	

Substitute lixa-X.Y.Z with the actual version of the software you installed.

Compile and link the C example program:

[Shell terminal session]
tiian@ubuntu:~/tmp$ gcc example1.c $(/opt/lixa/bin/lixa-config -c -f -l -d) -o example1
	

Check the output of the linker:

[Shell terminal session]
tiian@ubuntu:~/tmp$ ldd example1
        linux-gate.so.1 =>  (0xb773f000)
        liblixac.so.0 => /opt/lixa/lib/liblixac.so.0 (0xb7724000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb75d0000)
        libgmodule-2.0.so.0 => /usr/lib/libgmodule-2.0.so.0 (0xb75cb000)
        libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb75c7000)
        libgthread-2.0.so.0 => /usr/lib/libgthread-2.0.so.0 (0xb75c2000)
        librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb75b9000)
        libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0xb7508000)
        libxml2.so.2 => /usr/lib/libxml2.so.2 (0xb73e8000)
        liblixab.so.0 => /opt/lixa/lib/liblixab.so.0 (0xb73d4000)
        libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb73bc000)
        /lib/ld-linux.so.2 (0xb7740000)
        libpcre.so.3 => /usr/lib/libpcre.so.3 (0xb7395000)
        libz.so.1 => /usr/lib/libz.so.1 (0xb7380000)
        libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb735b000)
        libuuid.so.1 => /lib/libuuid.so.1 (0xb7356000)
	

Now you are ready to start your first application:

[Shell terminal session]
tiian@ubuntu:~/tmp$ ./example1
tx_open(): -7
	

The tx_open() function returned the value -7 (TX_FAIL) because the state server is not running. Start the state server (see the section called “Background (daemon) execution”) and try again:

[Shell terminal session (Ubuntu)]
tiian@ubuntu:~/tmp$ sudo su - lixa
lixa@ubuntu:~$ /opt/lixa/sbin/lixad --daemon
lixa@ubuntu:~$ exit
logout
tiian@ubuntu:~/tmp$ ps -ef|grep lixad|grep -v grep
lixa     12866     1  0 21:35 ?        00:00:00 /opt/lixa/sbin/lixad --daemon
tiian@ubuntu:~/tmp$ ./example1
tx_open(): 0
tx_begin(): 0
tx_info(): 1
xid.formatID: 1279875137
xid.gtrid_length: 16
xid.bqual_length: 16
when_return: 0 (TX_COMMIT_COMPLETED)
transaction_control: 0 (TX_UNCHAINED)
transaction_timeout: 0 s
transaction_state: 0 (TX_ACTIVE)
tx_commit(): 0
tx_info(): 0
xid.formatID: -1
xid.gtrid_length: 0
xid.bqual_length: 0
when_return: 0 (TX_COMMIT_COMPLETED)
transaction_control: 0 (TX_UNCHAINED)
transaction_timeout: 0 s
transaction_state: 0 (TX_ACTIVE)
tx_set_commit_return(): 1
tx_set_transaction_timeout(): 0
tx_set_transaction_control(): 0
tx_info(): 0
xid.formatID: -1
xid.gtrid_length: 0
xid.bqual_length: 0
when_return: 0 (TX_COMMIT_COMPLETED)
transaction_control: 1 (TX_CHAINED)
transaction_timeout: 5 s
transaction_state: 0 (TX_ACTIVE)
tx_set_transaction_control(): 0
tx_info(): 0
xid.formatID: -1
xid.gtrid_length: 0
xid.bqual_length: 0
when_return: 0 (TX_COMMIT_COMPLETED)
transaction_control: 0 (TX_UNCHAINED)
transaction_timeout: 5 s
transaction_state: 0 (TX_ACTIVE)
tx_begin(): 0
tx_rollback(): 0
tx_close(): 0
	

Your first program has connected to the state server and has performed two dummy distributed transactions: commit and rollback.

Some details about the example

You have not specified a specific profile:

[Shell terminal session]
tiian@ubuntu:~/tmp$ echo $LIXA_PROFILE
	  

The LIXA client library used the default one, the first listed in etc/lixac_conf.xml. If you inspected the configuration file /opt/lixa/etc/lixac_conf.xml you would see something like this:

[Shell terminal session]
tiian@ubuntu:~/tmp$ cat /opt/lixa/etc/lixac_conf.xml
<?xml version="1.0" encoding="UTF-8" ?>
<client>
  <sttsrvs>
    <sttsrv name="local_1" domain="AF_INET" address="127.0.0.1" port="2345" />
[...]
    <rsrmgr name="LIXAdummyRM" switch_file="/opt/lixa/lib/switch_lixa_dummyrm.so" xa_open_info="dummy open string" xa_close_info="dummy close string" />
[...]
  <profiles>
    <profile name="CF05">
      <sttsrvs>
        <sttsrv>local_1</sttsrv>
      </sttsrvs>
      <rsrmgrs>
        <rsrmgr>LIXAdummyRM</rsrmgr>
        <rsrmgr>LIXAdummyRM</rsrmgr>
      </rsrmgrs>
    </profile>
    <profile name="GT71">
[...]
  </profiles>
</client>
	  

The default profile is named CF05 and lists two resource managers of the same type: LIXAdummyRM; the related switch file is the file /opt/lixa/lib/switch_lixa_dummyrm.so. The dummy resource managers supplied by the LIXA project is a special trivial resource managers: it ever returns XA_OK. If you are interested in LIXA dummy Resource Manager implementation, take a look to the source file src/client/switch/lixa/lixa_dummyrm.c. To verify that the program is using the dummy resource manager, execute it with LIXA_TRACE_MASK environment variable set to 0x00008000:

[Shell terminal session]
tiian@ubuntu:~/tmp$ export LIXA_TRACE_MASK=0x00008000
tiian@ubuntu:~/tmp$ ./example1
[...]
2011-04-05 22:07:59.953844 [29359/3073444096] client_config_load_switch
2011-04-05 22:07:59.953875 [29359/3073444096] client_config_load_switch: resource manager # 0, name='LIXAdummyRM', switch_file='/opt/lixa/lib/switch_lixa_dummyrm.so'
2011-04-05 22:07:59.954220 [29359/3073444096] client_config_load_switch: module address 0x804e410, function lixa_get_xa_switch found at address 0xb76dd790
2011-04-05 22:07:59.954254 [29359/3073444096] client_config_load_switch: lixa_getxa_switch()->name = 'lixa_dummyrm', lixa_get_xa_switch()->flags = 0
2011-04-05 22:07:59.954279 [29359/3073444096] client_config_load_switch: resource manager dynamically registers: false
2011-04-05 22:07:59.954302 [29359/3073444096] client_config_load_switch: resource manager does not support association migration: false
2011-04-05 22:07:59.954325 [29359/3073444096] client_config_load_switch: resource manager supports asynchronous operations: false
2011-04-05 22:07:59.954348 [29359/3073444096] client_config_load_switch: resource manager # 1, name='LIXAdummyRM', switch_file='/opt/lixa/lib/switch_lixa_dummyrm.so'
2011-04-05 22:07:59.954379 [29359/3073444096] client_config_load_switch: module address 0x804e410, function lixa_get_xa_switch found at address 0xb76dd790
2011-04-05 22:07:59.954405 [29359/3073444096] client_config_load_switch: lixa_getxa_switch()->name = 'lixa_dummyrm', lixa_get_xa_switch()->flags = 0
2011-04-05 22:07:59.954429 [29359/3073444096] client_config_load_switch: resource manager dynamically registers: false
2011-04-05 22:07:59.954451 [29359/3073444096] client_config_load_switch: resource manager does not support association migration: false
2011-04-05 22:07:59.954474 [29359/3073444096] client_config_load_switch: resource manager supports asynchronous operations: false
[...]
tx_open(): 0
tx_begin(): 0
tx_commit(): 0
tx_begin(): 0
tx_rollback(): 0
2011-04-05 22:08:00.128531 [29359/3073444096] client_unconfig
2011-04-05 22:08:00.128883 [29359/3073444096] client_unconfig: acquiring exclusive mutex
2011-04-05 22:08:00.129174 [29359/3073444096] client_config_unload_switch
2011-04-05 22:08:00.129399 [29359/3073444096] client_config_unload_switch: resource manager # 0, defined in config as 'LIXAdummyRM', module address 0x804e410, xa_switch->name='lixa_dummyrm', xa_switch->flags=0
2011-04-05 22:08:00.129594 [29359/3073444096] client_config_unload_switch: resource manager # 1, defined in config as 'LIXAdummyRM', module address 0x804e410, xa_switch->name='lixa_dummyrm', xa_switch->flags=0
2011-04-05 22:08:00.129852 [29359/3073444096] client_config_unload_switch/excp=1/ret_cod=0/errno=0
2011-04-05 22:08:00.130024 [29359/3073444096] client_unconfig/xmlCleanupParser
2011-04-05 22:08:00.130215 [29359/3073444096] client_unconfig: releasing exclusive mutex
2011-04-05 22:08:00.130371 [29359/3073444096] client_unconfig/excp=2/ret_cod=0/errno=0
tx_close(): 0