next up previous contents
Next: 3 JDBC Example Up: JOTM Examples guide Previous: 1 Available Examples   Contents

Subsections


2 Basic Example

All Ant commands are to be executed from the examples/basic/ directory of a JOTM distribution (examples won't work from JOTM source directory).


2.1 Scenario

The basic example is a very simple example showing how to use a Transaction Manager. The client application (BasicExample class) looks up the UserTransaction. Then it makes two transactions:


2.2 Setup and compilation

To set up this example, you'll need:

To compile the example, in the examples/basic/ directory, type

$ ant compile

2.3 Run the example

First, you've to set JOTM_HOME to the directory of your JOTM distribution (e.g., .../jotm/output/dist from CVS).
$ export JOTM_HOME=<JOTM_distribution_directory>
To run the example, you have to be in the examples/basic/ directory.
You can run the example with three different configurations for protocol communication:

There are two commands to run the example:

$ ant run.rmi.jrmp
$ ant run.rmi.iiop

The first one assumes that JOTM is accessible through RMI/JRMP and that a RMI registry is running on its default port (i.e. 1099).
The second one assumes that JOTM is accessible through RMI/IIOP and that a CORBA name server is running on port 19751.
Both also assume that the UserTransaction object is accessible on JNDI with the name UserTransaction.

It has to be noted that these two targets are using the same class, BasicExample. They just differ in their settings: one is for RMI/JRMP communication whereas the other is a pure RMI/IIOP client.

2.3.1 On RMI/JRMP

To run the example on RMI/JRMP, type in $JOTM_HOME/lib/,
$ rmiregistry -J-classpath -Jjotm.jar:jotm_jrmp_stubs.jar \
  -J-Djava.security.policy=../config/java.policy &
Then in $JOTM_HOME/lib/, type
$ java -classpath jotm.jar:jotm_jrmp_stubs.jar:../config/ \
  org.objectweb.jotm.Main -u UserTransaction &
(on one line)

And in the basic/ directory, type

$ ant run.rmi.jrmp
(by default JOTM is configured to run on RMI/JRMP so you don't have to modify $JOTM_HOME/config/carol.properties file to run example on it).

2.3.2 On RMI/IIOP

To run the example on RMI/IIOP, first change the settings of JOTM to activate RMI/IIOP support : in $JOTM_HOME/config/carol.properties (Now only RMI/IIOP is activated and is the default protocol)

Then type

$ tnameserv -ORBInitialPort 19751 &
Then in $JOTM_HOME/lib/, type
$ java -classpath jotm.jar:jotm_iiop_stubs.jar:../config/ \
  org.objectweb.jotm.Main -u UserTransaction &
(on one line)

And in the basic/ directory, type

$ ant run.rmi.iiop

2.3.3 On both RMI/JRMP and RMI/IIOP

To run the example on both RMI/JRMP and RMI/IIOP, first change the settings of JOTM to activate both of them.
In $JOTM_HOME/config/carol.properties (Now both RMI/IIOP and RMI/JRMP are activated and RMI/JRMP is the default protocol)

Then type in $JOTM_HOME/lib/,

$ tnameserver -ORBInitialPort 19751 &
$ rmiregistry -J-classpath -Jjotm.jar:jotm_jrmp_stubs.jar \
  -J-Djava.security.policy=../config/java.policy &
Then in $JOTM_HOME/lib/, type
$ java -classpath \
  jotm.jar:jotm_jrmp_stubs.jar:jotm_iiop_stubs.jar:../config/ \
  org.objectweb.jotm.Main -u UserTransaction &
(on one line)

Finally you can acces JOTM on both RMI/JRMP or RMI/IIOP. in the basic/ directory, type

$ ant run.rmi.jrmp
$ ant run.rmi.iiop
$ ant run.rmi.jrmp
$ ...


2.4 Output

Whatever configuration, you have chosen, the output of the example is still the same : something like
$ ...
$
$ [java] create initial context
$ [java] lookup UserTransaction at : UserTransaction
$
$ [java] a simple transaction wich is committed:
$ [java]        - initial status : STATUS_NO_TRANSACTION
$ [java]        - after begin status : STATUS_ACTIVE
$ [java]        - after commit status : STATUS_NO_TRANSACTION
$
$ [java] a simple transaction which is rolled back.
$ [java] we set a transaction timeout to 1 second, begin the
$ [java] transaction, and wait 5 seconds before commiting it:
$ [java]        - initial status : STATUS_NO_TRANSACTION
$ [java]        - after begin status : STATUS_ACTIVE
$ [java]        - wait for 5 seconds
$ [java]        - after rollback status : STATUS_NO_TRANSACTION
$
$ [java] Basic example is OK.
$
$ ...

If you have the message Basic example is OK., the example is working. If it's not the case, double check your JOTM settings. Most of the time, troubles come from incorrect settings (clients try to access JOTM through RMI/JRMP whereas there is no RMI registry but a CORBA name server,...).


next up previous contents
Next: 3 JDBC Example Up: JOTM Examples guide Previous: 1 Available Examples   Contents
Jeff Mesnil 2003-07-30