| public void init()
| {
| try
| {
| initialContext = new InitialContext();
| cf = (ConnectionFactory)
initialContext.lookup("ConnectionFactory");
| jbossCf = (JBossConnectionFactory)
initialContext.lookup("ConnectionFactory");
|
| topicDestn = (Destination)
initialContext.lookup("/topic/testTopic");
| ut = (UserTransaction) initialContext.lookup("UserTransaction");
| } catch (Exception e) {
| e.printStackTrace();
| }
|
| }
| public void testXA() throws Exception
| {
| XAConnection conn = null;
| javax.jms.Connection conn2 = null;
|
| init();
| conn = jbossCf.createXAConnection();
|
| try
| {
|
| UserTransaction userTx =
com.arjuna.ats.jta.UserTransaction.userTransaction();
|
| userTx.begin();
|
| // javax.transaction.TransactionManager txMgr =
TransactionManager.transactionManager();
| // txMgr.begin();
|
| XASession sess1 = conn.createXASession();
|
| // messaging resource
| org.jboss.jms.tx.MessagingXAResource msgRes =
(org.jboss.jms.tx.MessagingXAResource) sess1.getXAResource();
| msgRes.setPreventJoining(true);
|
| // dummy resource
| XAResource dummyRes = new DummyXAResource(true);
|
| // sybase res
| SybaseXAResource sybaseRes = new SybaseXAResource();
| XAResource sybRes = sybaseRes.getXAResource();
|
| // Transaction tx = txMgr.getTransaction();
|
| // static transaction
| Transaction tx=
TransactionManager.transactionManager().getTransaction();
|
| // enlististing the resoruces
| tx.enlistResource(msgRes);
| tx.enlistResource(dummyRes);
| tx.enlistResource(sybRes);
|
| // ===================== Sybase works start
===============================
| System.out.println("=========== Sybase XA Work START
=========");
| javax.sql.XAConnection sybaseXaConn =
sybaseRes.getXAConnection();
| java.sql.Connection sybaseConn = sybaseXaConn.getConnection();
| java.sql.Statement stmt = sybaseConn.createStatement();
|
| int i = stmt.executeUpdate("INSERT INTO GRINDER_MESSAGES
VALUES('"
| + System.currentTimeMillis() + "-XXXX','"
| + new java.util.Random().nextInt() + "','"
| + new java.util.Random().nextInt() + "')");
|
| System.out.println("Rows affected: " + i);
| System.out.println("=========== Sybase XA Work END =========");
|
| // ===================== Sybase works end
==============================
|
| // ===================== Messaging works start
==============================
|
| MessageProducer sender = sess1.createProducer(topicDestn);
| // sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
|
| javax.jms.Message tm = sess1.createTextMessage("test-"+new
java.util.Random().nextInt());
|
| System.out.println("Sending the message");
| sender.send(tm);
|
| try {
| System.out.println("Toplevel commit");
| tx.commit();
| } catch (Exception e) {
| // don't bother
| }
|
| System.out.println("Exiting..");
| System.exit(0);
|
| } finally {
| if (conn != null) {
| conn.close();
| }
| if (conn2 != null) {
| conn2.close();
| }
| }
|
|
| }
| static class DummyXAResource implements XAResource
| {
| boolean failOnPrepare;
|
| DummyXAResource()
| {
| }
|
| DummyXAResource(boolean failOnPrepare)
| {
| this.failOnPrepare = failOnPrepare;
| }
|
| public void commit(Xid arg0, boolean arg1) throws XAException
| {
| System.out.println("Dummyresoruce: commit ");
| System.out.println("I am about to commit..check the logs");
|
| try {
| Thread.sleep(30000);
| } catch (InterruptedException e) {
| e.printStackTrace();
| }
| System.out.println("I am awake now.");
| }
|
| public void end(Xid arg0, int arg1) throws XAException{ }
|
| public void forget(Xid arg0) throws XAException { }
|
| public int getTransactionTimeout() throws XAException
| {
| return 0;
| }
|
| public boolean isSameRM(XAResource arg0) throws XAException
| {
| return false;
| }
| public int prepare(Xid arg0) throws XAException
| {
| System.out.println("Dummyresoruce: prepare");
| if (failOnPrepare)
| {
| throw new XAException(XAException.XAER_RMERR);
| }
| return XAResource.XA_OK;
| }
|
| public Xid[] recover(int arg0) throws XAException
| {
| return null;
| }
|
| public void rollback(Xid arg0) throws XAException
| {
| }
|
| public boolean setTransactionTimeout(int arg0) throws XAException
| {
| return false;
| }
|
| public void start(Xid arg0, int arg1) throws XAException
| {
|
| }
|
| }
|
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3947991#3947991
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3947991
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user