Thanks Dasarath's reply.

--- Dasarath Weeratunge <[EMAIL PROTECTED]>写道:
> Quoting Jack Wang <[EMAIL PROTECTED]>:
> 
> Let us assume a money transfer. You invoke the 2 services:
> 
> Bank1.debit(acc1, dollars);
> Bank2.credit(acc2, dollars);
> 
> Now Bank1 and Bank2 services could be running on hosts H1, H2 (H2 could be 
> the 
> same as H1) which we do not care.
> 
> Say you have Kandula running on host H3 (could be the same as H1 or H2). Then 
> you MUST set kandula.context to:
> 
> http://H3:port/axis/services/
>  
> and call your operations like this.
> 
> wstm.begin("http://H3:port/axis/services/activationCoordinator";);

I try to follow it and here is my web application code in H3 running Kandula. 

/* -- wstm begin in H3 ------- */                               
ActivationStub stub = new ActivationStub(new
EndpointReference("http://H3:port/axis/services/activationCoordinator";));
CoordinationContext ctx = 
stub.createCoordinationContext(ATCoordinator.COORDINATION_TYPE_ID);
EndpointReference cps = ctx.register(ATCoordinator.PROTOCOL_ID_COMPLETION,
        new 
EndpointReference("http://H3:port/axis/services/completionInitiator";));
SetCoordCtxHandler.setCtx(ctx);
/* --------------------------- */                               

Question 1:
I wonder if I do not configure "UserTransaction" in H1 and H2's tomcats now 
when I operate the
database in the web services of H1 and H2, which will be called by H3's 
transaction. And Also
wonder if I do not configure "UserTransaction" in H3's tomcat , where there is 
a local db
operation which will also be placed in the H3's same transaction.

In the normal application, I use UserTransaction configured in tomcat's 
sever.xml to operate
database. The code is as follow:

/* -- normal db application ----------------- */                                
Context ctx = new InitialContext();
UserTransaction ut = 
(UserTransaction)ctx.lookup("java:comp/env/UserTransaction");
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myDB");
java.sql.Connection conn = ds.getConnection();
ut.begin();
Statement stmt = conn.createStatement();
PreparedStatement pstmt = conn.prepareStatement("update ...");
...
pstmt.executeUpdate();
if (...) {
    ut.commit();
} else {
    ut.rollback();
}
/* ------------------------------------------ */   

        
> Bank1.debit(acc1, dollars);
> Bank2.credit(acc2, dollars);
> wstm.commit();
> 
> Note that the new o.a.k.coordinator.at.TMimpl expects to be called from 
> within 
> a ws container where kandula is deployed-- if you call it from a standalone 
> your tx will work but the "commit" method will hang expecting a "Committed" 
> message which cannot be received this way.
> 

My application will be a ws container application, so not consider standalone 
application. 

> 
> Say now, that YOU are providing Bank1 (or Bank2 or both)
> 
> Now when you create a DataSource in JDBC it gives you an XAResource 
> interface. 
> You must register this XAResource interface with the local j2ee tx.
> 
> e.g.
> 
> Bank1.creditImpl(acc, dollars) {
> 
> xaRes = createConnection("JDBC:connection string");

I try to follow it and here is my code in H1 or H2 to do the db transaction. 
The database server
is mySQL 5.0 and I will use Connector/J 5.0 jdbc driver, so I can use 
Distributed Transactions.

/* -----db transaction in H1 and H2 --------- */   
MysqlXADataSource xaDs = new MysqlXADataSource();
XAConnection xaConn = xaDs.getXAConnection();
javax.transaction.xa.XAResource xaRes = xaConn.getXAResource();
/* ------------------------------------------ */   

> Transaction tx = tm.getTransaction();
> tx.enlistResource(xaRes);
> 
        
Question 2:
Class javax.transaction.TransactionManager is an interface used by application 
container. I can
get a UserTransaction. Can I get a Transaction instance directly by 
"Transaction tx =
javax.transaction.TransactionManager.getTransaction();" ? If not, how can I get 
the local j2ee tx?

> // SQL statements
> 

/* ----- SQL statements in H1 and H2 --------- */   
Connection conn = xaConn.getConnection();
Xid xid = createXid();
xaRes.start(xid, XAResource.TMNOFLAGS);
conn.createStatement().executeUpdate("INSERT INTO testCoordination VALUES (1)");
xaRes.end(xid, XAResource.TMSUCCESS);
int ret = xaRes.prepare(xid);
if (ret == XAResource.XA_OK) { 
        xaRes.commit(xid, false); 
} else{
        xaRes.rollback(xid); 
}
/* ------------------------------------------ */   

Question 3:
If H3's transaction also contains a local database operation, I should let the 
H3's local j2ee tx
enlist the xaRes in H3's bean, which will be called by a jsp's request. Is it 
right?

> tx.delistResource(xaRes);
> }
> 
> This usually happens transparently if your TM and DB are properly hooked up 
> to 
> your container-- say Tomcat. (However, I've not seen any docs on how to to do 
> this with Geronimo but certainly it is possible.)
> 
> Notice that there are 2 parallel sets of interfaces. 
> o.a.k.coordinator.at.TransactionImpl, 
> o.a.k.coordinator.at.TransactionManagerImpl 
> and 
> javax.transaction.Transaction, javax.transaction.TransactionManager.
> 
> When you use j2ee (or JDBC) for distributed transactions using ws-at/kandula, 
> your application will NOT directly get itself involved in ws-at protocol.
> instead it will as usual work with JTA. However, behind the scene, kandula 
> will 
> tie up your local JTA tx with the corresponding (global) ws-at tx so that 
> your 
> local tx becomes a branch of the global tx.
> 
> --dasarath

Question 4:
The key problem is that I don't know how to get the local JTA(j2ee) tx, and how 
kandula ties the
local tx with the corresponding (global) ws-at tx, please ask in which class 
kandula ties them ?

Thanks again



Wang Jun


        

        
                
___________________________________________________________ 
雅虎1G免费邮箱百分百防垃圾信 
http://cn.mail.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to