This howto is intended for project developers who want to integrate JOTM in their Java projects to provide JTATM support for distributed transactions.
It is not intended for JOTM users. For information, on how to use JOTM, please refer to the installation and examples guides from the documentation page on JOTM web site.
javax.transaction.xa.XAResource).javax.transaction.Transaction object it can access from
the javax.transaction.TransactionManager
object. Some libraries doing so are included in JOTM
distribution (see JDBC and JMS examples).JOTM is an implementation of JTA.
JDBC provides connectivity to databases. JDBC defines XA
objects (javax.sql.XADataSource
and
javax.sql.XAConnection
which can be used to support
distributed transactions across several databases. JDBC driver
implementers should provide these XA objects so that JOTM can
enlist JDBC resources in transactions.
JMS provides a standard API to use MOM in Java. JMS defines a
set of XA objects (such as javax.jms.XAConnection
or javax.jms.XASession)
which can be used to support
distributed transactions across several MOMs. As for JDBC, JMS providers
should implements these XA objects so that JOTM can
enlist JMS resources in transactions.
JOTM can be used by EJB containers to provide both bean-managed
and container-manager transaction demarcation and
javax.transaction.UserTransaction
object to EJB client.
JOTM can be used by Servlet containers to provide
javax.transaction.UserTransaction object to Servlets
and JSPTM (JavaServer Pages).
From the outside, JOTM is a transaction manager implementing JTA
interfaces (as defined in javax.transaction
and
javax.transaction.xa
packages).
Containers start JOTM, access JTA objects and then use them to provide distributed transactions support.
org.objectweb.transaction.jta
packageJTA defines two main interfaces to interact with a transaction manager:
javax.transaction.TransactionManager that
allows an application server to manage transaction
boundaries.javax.transaction.UserTransaction that allows
an application to explicitly manage transaction boundaries.However, JTA does not define how to get those interfaces from a transaction manager.
JOTM defines an interface (
org.objectweb.transaction.jta.TMService)
which can be used to
get those interfaces. It defines three
methods:
public
org.objectweb.transaction.jta.TransactionManager getTransactionManager()
- gets a TransactionManager object. The ObjectWeb
TransactionManager
interface extends the JTA interface
to provide support for late enlistment of resources.public javax.transaction.UserTransaction getUserTransaction()
- gets a JTA UserTransaction object.public void stop() - stops the transaction managerJOTM defines an object, org.objectweb.jotm.Jotm,
implementing org.objectweb.transaction.jta.TMService and can be used to start
JOTM. In addition to the TMService methods, there is
a public constructor:
public Jotm(boolean local, boolean bound) - creates an instance of
JOTM.
local boolean specifies if the
transaction factory used to coordinate
transactions is local to this instance or located on another
instance of JOTM.
If the transaction factory is local, bound boolean
specifies if it is bound to a registry and made
accessible through JNDITM
(Java Naming and Directory Interface).
The rule to remember is, in one "transaction domain", there is one and only one JOTM with a local transaction factory. If there are other instances, they are created with a remote transaction factory and are bound by the JOTM creating them locally.
To integrate JOTM in another product, additional libraries are required.
JOTM requires some libraries and API (they are all in the
lib/ directory of JOTM distribution:
jotm.jar - JOTM jotm_jrmp_stubs.jar - JOTM stubs for RMI/JRMPjotm_iiop_stubs.jar - JOTM stubs for RMI/IIOPcarol-2.0.5.jar - CAROL (RMI
support)jta-spec1_0_1.jar - JTAjts1_0.jar - JTSTM (Java Transaction Service)howl-0.1.8.jarcommons-logging.jarxapool-1.5.0.jarconnector-1.5.jarobjectweb-datasource.jarlog4j.jar - Log4JTMcommons-cli.jar - CLITM
(Command-line interface) library
(used only by standalone JOTM)The classpath requires jotm.jar and the
jar files of the stubs (jotm_jrmp_stubs.jar and/or
jotm_iiop_stubs.jar) only.
Other jar files are
loaded due to the class-path attribute of the jotm.jar manifest file.
(The jar files are required to be in the same
directory as jotm.jar).
JOTM configuration files (RMI support, JNDI properties, trace configurations,...)
need to reside in the conf/ directory at the same
level as the lib/ directory (the class-path
attribute of JOTM jar files looks for them in
../conf/ directory.
If you plan to bind JOTM objects such as
UserTransaction or TransactionManager in
JNDI using RMI registry (rmiregistry), you'll need
to start the registry with
specific permissions required by CAROL. The
java.policy is found in the conf/
directory of the JOTM distribution.
RMI registry needs both jotm.jar and
jotm_jrmp_stubs.jar in its classpath.
From the lib/ directory of JOTM, start the RMI
registry with the following command: (NOTE! UNIX uses a ':' separator. For Windows, use ';')
rmiregistry -J-classpath -Jjotm.jar:jotm_jrmp_stubs.jar:commons-cli-1.0.jar:connector-1_5.jar:howl-0.1.8.jar -J-Djava.security.policy=../conf/java.policy
JOTM can be embedded in a "container" (e.g. an EJB container, a Servlets container, or with a standalone application) and execute in the same JVM.
All you have to do is to create in the container code, a JOTM instance with a local transaction factory which is not bound:
try {
TMService jotm = new Jotm(true, false);
} catch (NamingException e) {
// thrown only if JOTM is started with a remote transaction
// factory or if it has to be bound.
}
Then you can access UserTransaction and
TransactionManager objects:
UserTransaction utx = jotm.getUserTransaction();
TransactionManager tm = jotm.getTransactionManager();
It's also up to the container developer to choose to bind these
objects in a registry or if they will only be used inside the same
JVM. A case example is the JDBC example included in the
JOTM distribution where TransactionManager is
used locally whereas UserTransaction is bound to a registry.
For more information, see Jotm Javadoc.
JOTM can be started as a standalone application. In that case, containers can access JTA objects by looking them up in a registry.
To start JOTM as a standalone application, from a command line interface, type:
java org.objectweb.jotm.Main [args]with
[args] being:
-u USER_TRANSACTION_JNDI_NAME - binds a
UserTransaction to the registry with the name
USER_TRANSACTION_JNDI_NAME-m TRANSACTION_MANAGER_JNDI_NAME - binds a
TransactionManager to the registry with the name
TRANSACTION_MANAGER_JNDI_NAMETo have a complete list of available arguments, type:
java org.objectweb.jotm.Main --help
Containers can then access those objects by looking up them through JNDI.
For more information, see Main Javadoc.
If you have trouble integrating JOTM, questions, or if you want to contribute, do not hesitate to contact us.