|
Summary: The Jini Distributed Transactions provide a two-phase commit protocol.
OverviewThe Jini Distributed Transactions provide a two-phase commit protocol. The two-phase commit protocol defines the communication patterns that allow distributed objects and resources to wrap a set of operations in such a way that they appear to be a single operation. The protocol requires a manager that will enable consistent resolution of the operations by a guarantee that all participants will eventually know whether they should commit the operations (roll forward) or abort them (roll backward). A participant can be any object that supports the participant contract by implementing the appropriate interface. Participants are not limited to databases or other persistent storage services.
To create the Jini Transaction Manager: /*
* Use the Look-up Service to look-up & get Jini's Txn-Manager
* The Transactions created under THIS Transaction Manager can
* span Multiple Gigaspace instances present in different places...
*/ TransactionManager trManager = (TransactionManager)LookupFinder.find(
null, // service name
new Class[] { net.jini.core.transaction.server.TransactionManager.class },
null, // service attributes
"localhost", // unicast lookup host
null, // lookup groups
10*1000 // timeout 10 seconds
);
To create the transaction: // Now, use trManager as usual to create Transactions ... // But now, you can use the SAME transaction across different Spaces... Transaction.Created tCreated =TransactionFactory.create(trManager, 1000 * 60); Transaction tr = tCreated.transaction; Using the transaction and committing: IJSpace space = SpaceFinder.find(url);
Lease lease = space.write(entry, tr, leaseTime);
// committing the transaction
tr.commit(10000);
You can always extend the transaction's lease time or cancel it via the lease object: tCreated.lease.renew(1000); tCreated.lease.cancel();
Committing or Aborting the Jini TransactionWhen using the Jini transaction Manager, consider using the Transaction.commit(long waitFor) and Transaction.abort(long waitFor) methods – these return acknowledgements to the caller application, only after the transaction commit or abort operation has been fully completed by all transaction participants, or until the timeout period expires. When using the Transaction.abort() and the Transaction.commit() methods, the client gets the acknowledgement immediately after the abort or commit call without waiting for all transaction participants to complete. This may lead to inconsistency. The waitFor parameter timeout allows you to choose the maximum amount of time you would like to wait for the transaction to be completed by all participants. This behavior will not happen when using the Local Transaction Manager, since the client gets an acknowledgement for the commit or abort operation only after the space has completed the commit or abort processing.
TroubleshootingIn general, you can look up any Jini service based on different attributes, name, interface etc. You can have several Jini Transaction Managers running. Once you got a proxy to one of them you should be OK. The default name for the Jini Transaction Manager is Transaction Manager. You can get this information by:
Double click the TransactionManager, and the ServiceItem Editor will be displayed with the Transaction Manager properties:
|
Wiki Content Tree
Your Feedback Needed!
We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.
Add Comment