JTA + JBoss Cache + Distributed Transactions
nanreh May 18, 2007 3:26 AMHi there,
I'm in the process of learning as much as I can about JBoss Transactions. I hope to use it to do distributed transactions across a three or four JBoss Cache nodes which are all stand-alone Java SE applications.
I've run through all of the samples in the trail_map project and they all run just fine for me. The documentation in trail_map says:
"Using JTA to create a distributed transaction need the creation of an ORB instance as done by a JTS application (see JTS versions of the banking application), the difference is in the interface used to demarcate and control transactions."
I would like to use JTA to manage transactions in my code and I've implemented a TransactionManagerLookup for my JBoss Cache that looks like this:
package org.defy.tx; import javax.transaction.TransactionManager; import org.jboss.cache.transaction.TransactionManagerLookup; public class CustomTransactionManagerLookup implements TransactionManagerLookup { public TransactionManager getTransactionManager() throws Exception { javax.transaction.TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager(); return transactionManager; } }
I went ahead and copied the ORB initialization code from the JTS "remotebank" sample and put together a simple program that creates a JBoss Cache and tries to modify it within a transaction.
package org.defy.tx; import javax.transaction.UserTransaction; import org.apache.log4j.PropertyConfigurator; import org.jboss.cache.Cache; import org.jboss.cache.CacheFactory; import org.jboss.cache.DefaultCacheFactory; import org.jboss.cache.Fqn; import org.jboss.cache.Node; import com.arjuna.orbportability.OA; import com.arjuna.orbportability.ORB; import com.arjuna.orbportability.RootOA; public class Main { public static void main (String[] args) { initOrb(args); // Local //System.setProperty("com.arjuna.ats.jta.jtaTMImplementation","com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple"); //System.setProperty("com.arjuna.ats.jta.jtaUTImplementation","com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple"); // Distributed System.setProperty("com.arjuna.ats.jta.jtaTMImplementation","com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple"); System.setProperty("com.arjuna.ats.jta.jtaUTImplementation","com.arjuna.ats.internal.jta.transaction.jts.UserTransactionImple"); CacheFactory factory = DefaultCacheFactory.getInstance(); Cache cache = factory.createCache("cache-configuration.xml"); runTx(cache); } private static void runTx(Cache cache) { UserTransaction tx = com.arjuna.ats.jta.UserTransaction.userTransaction(); System.out.println(tx); try { tx.begin(); Fqn peterGriffinFqn = Fqn.fromString("/griffin/peter"); // let's get a hold of the root node. Node rootNode = cache.getRoot(); // and create a child Node peterGriffin = rootNode.addChild(peterGriffinFqn); // let's store some data in the node peterGriffin.put("isCartoonCharacter", Boolean.TRUE); peterGriffin.put("favouriteDrink", "Beer"); System.out.println("Begin tx."); tx.commit(); System.out.println("Commit tx."); } catch(Exception e) { e.printStackTrace(); try { System.out.println("Rollback tx."); tx.rollback(); } catch(Exception re) { re.printStackTrace(); } } } private static void initOrb(String[] args) { // Define an ORB suitable for use by the JBoss Transactions product ORB portability layer. ORB myORB = null; // Define an object adapter suitable for use by the JBoss Transactions product ORB portability layer. RootOA myOA = null; try { // Initialize the ORB reference using the JBoss Transactions product ORB portability layer. myORB = ORB.getInstance("sample"); // Initialize the object adapter reference using the JBoss Transactions product ORB portability layer. myOA = OA.getRootOA(myORB); // Initialize the ORB using the JBoss Transactions product ORB portability layer. myORB.initORB(args, null); // Initialize the object adapter reference using the JBoss Transactions product ORB portability layer. myOA.initOA(); } catch (Exception e) { // The ORB has not been correctly configured! // Display as much help as possible to the user track down the configuration problem System.err.println("Trailmap Error: ORB Initialisation failed: " + e); e.printStackTrace(); System.exit(0); } }; }
When I set things to run under under a local transaction everything works fine. When I switch to distributed transactions I get the following error.
2007-05-17 23:52:06,593 DEBUG [org.jboss.cache.interceptors.TxInterceptor] - <Running beforeCompletion on gtx GlobalTransaction:<null>:1> 2007-05-17 23:52:06,609 DEBUG [org.jboss.cache.interceptors.TxInterceptor] - <Setting up transactional context.> 2007-05-17 23:52:06,609 DEBUG [org.jboss.cache.interceptors.TxInterceptor] - <Setting tx as TransactionImple < jts, -3f57fefe:ab1:464d4d16:3 > and gtx as GlobalTransaction:<null>:1> [17-05-2007 23:52:06:609] jacorb.orb.giop:INFO: ClientConnectionManager: found conn to target 192.168.1.2:2736 [17-05-2007 23:52:06:625] jacorb.poa:INFO: oid: 04 15 0C 23 4B 15 3C 21 2B 36 ...#K.<!+6 object is activated 2007-05-17 23:52:06,640 WARN [com.arjuna.ats.jts.logging.loggerI18N] - <[com.arjuna.ats.internal.jts.orbspecific.jacorb.recoverycoordinators .JacOrbRCManager_4] [com.arjuna.ats.internal.jts.orbspecific.jacorb.recoverycoordinators.JacOrbRCManager_4] - RCManager could not find file in object store during setup.> 2007-05-17 23:52:06,640 WARN [com.arjuna.ats.jts.logging.loggerI18N] - <[com.arjuna.ats.internal.jts.orbspecific.jacorb.recoverycoordinators .JacOrbRCManager_3] [com.arjuna.ats.internal.jts.orbspecific.jacorb.recoverycoordinators.JacOrbRCManager_3] - RCManager could not find file in object store.> 2007-05-17 23:52:06,656 WARN [com.arjuna.ats.jts.logging.loggerI18N] - <[com.arjuna.ats.internal.jts.orbspecific.coordinator.rccreate] Creat ion of RecoveryCoordinator for -3f57fefe:ab1:464d4d16:3 threw: org.omg.CORBA.BAD_OPERATION: RecoveryCoordinator [com.arjuna.ats.internal.jts .orbspecific.coordinator.rcnotcreated] not created! vmcid: 0x0 minor code: 0 completed: No> [17-05-2007 23:52:06:656] jacorb.poa.controlle:INFO: rid: 6 opname: register_resource invocation: system exception was thrown (org.omg.CORBA .BAD_OPERATION: RecoveryCoordinator [com.arjuna.ats.internal.jts.orbspecific.coordinator.rcnotcreated] not created! vmcid: 0x0 minor code: 0 completed: No) 2007-05-17 23:52:06,671 WARN [com.arjuna.ats.jts.logging.loggerI18N] - <[com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arj una.generror] ServerTopLevelAction.registerResource caught exception: org.omg.CORBA.BAD_OPERATION: Server-side Exception: RecoveryCoordinato r [com.arjuna.ats.internal.jts.orbspecific.coordinator.rcnotcreated] not created! vmcid: 0x0 minor code: 0 completed: No> org.omg.CORBA.BAD_OPERATION: Server-side Exception: RecoveryCoordinator [com.arjuna.ats.internal.jts.orbspecific.coordinator.rcnotcreated] n ot created! vmcid: 0x0 minor code: 0 completed: No at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.jacorb.orb.SystemExceptionHelper.read(SystemExceptionHelper.java:173) at org.jacorb.orb.ReplyReceiver.getReply(ReplyReceiver.java:326) at org.jacorb.orb.Delegate.invoke_internal(Delegate.java:963) at org.jacorb.orb.Delegate.invoke(Delegate.java:857) at org.omg.CORBA.portable.ObjectImpl._invoke(Unknown Source) at org.omg.CosTransactions._CoordinatorStub.register_resource(_CoordinatorStub.java:760) at com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction.registerResource(ServerTopLevelAction .java:673) at com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction.<init>(ServerTopLevelAction.java:130) at com.arjuna.ats.internal.jts.interposition.resources.arjuna.Interposition.createHierarchy(Interposition.java:174) at com.arjuna.ats.internal.jts.interposition.resources.arjuna.Interposition.setupHierarchy(Interposition.java:115) at com.arjuna.ats.internal.jts.interposition.resources.arjuna.Interposition.create(Interposition.java:74) at com.arjuna.ats.internal.jts.interposition.resources.arjuna.InterpositionCreator.recreateLocal(InterpositionCreator.java:48) at com.arjuna.ats.internal.jts.interposition.FactoryElement.recreateLocal(FactoryList.java:72) at com.arjuna.ats.internal.jts.interposition.FactoryList.recreateLocal(FactoryList.java:119) at com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple.recreateLocal(TransactionFactoryImple.java:246) at com.arjuna.ats.internal.jts.context.ContextManager.createHierarchy(ContextManager.java:790) at com.arjuna.ats.internal.jts.context.ContextManager.currentPIContext(ContextManager.java:682) at com.arjuna.ats.internal.jts.context.ContextManager.current(ContextManager.java:212) at com.arjuna.ats.internal.jts.context.ContextManager.associate(ContextManager.java:363) at com.arjuna.ats.internal.jts.OTSImpleManager.current(OTSImpleManager.java:91) at com.arjuna.ats.internal.jta.transaction.jts.TransactionImple.getTransaction(TransactionImple.java:1173) at com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple.getTransaction(TransactionManagerImple.java:74) at org.jboss.cache.interceptors.TxInterceptor.runPreparePhase(TxInterceptor.java:826) at org.jboss.cache.interceptors.TxInterceptor$LocalSynchronizationHandler.beforeCompletion(TxInterceptor.java:1109) at org.jboss.cache.interceptors.OrderedSynchronizationHandler.beforeCompletion(OrderedSynchronizationHandler.java:74) at com.arjuna.ats.internal.jta.resources.jts.orbspecific.SynchronizationImple.before_completion(SynchronizationImple.java:128) at org.omg.CosTransactions.SynchronizationPOA._invoke(SynchronizationPOA.java:42) at org.jacorb.poa.RequestProcessor.invokeOperation(RequestProcessor.java:299) at org.jacorb.poa.RequestProcessor.process(RequestProcessor.java:593) at org.jacorb.poa.RequestProcessor.run(RequestProcessor.java:735) 2007-05-17 23:52:06,671 WARN [com.arjuna.ats.jts.logging.loggerI18N] - <[com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arj una.ipfailed] ServerTopLevelAction - could not register interposed hierarchy!> 2007-05-17 23:52:06,671 WARN [com.arjuna.ats.jts.logging.loggerI18N] - <[com.arjuna.ats.internal.jts.interposition.resources.arjuna.ipfail] Interposition.removeHeirarchy - could not find -3f57fefe:ab1:464d4d16:3 to remove.>
Please let me know if you have any suggestions on how I might get past this issue. I've tried making sense of this stack trace and the WARN log records right before it but I feel I need an expert opinion to help get me moving again.
I'm using:
* JBOSSTS_4_2_3_GA
* jacorb_2_2_1_patch
* JBossCache-2.0.0.CR1
* JDK5
* All of the ext libs that shipped with the above distributions.
Thanks in advance,
Frank