Make room for JavaSpaces, Part 4
Explore Jini transactions with JavaSpaces
By Eric Freeman and Susanne Hupfer, JavaWorld.com, 04/21/00
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
The Jini transaction model is one of the lesser known and least used aspects of Jini, yet it provides a powerful tool for
writing distributed applications that operate correctly in the presence of partial failure. In this article, we take a look
at the Jini transaction model and show how you can use it with the JavaSpaces service -- one of the first Jini services to
fully support Jini transactions.
TEXTBOX: TEXTBOX_HEAD: Make room for JavaSpaces: Read the whole series!
:END_TEXTBOX
In general, transactional systems let you group together a set of operations so that they are performed atomically -- that
is, either all of the operations complete, or none of them do. Without this transactional ability, the states of systems can
easily become inconsistent -- especially distributed systems in which participants can crash the network or leave the network
before an operation has completed. By using transactions, you can ensure that the operations do complete, or if they don't,
that the state of the entire distributed system remains unchanged.
Systems that support transactions, such as a database management system, typically build transactions into the system's core.
Jini takes a more lightweight and flexible approach: It provides a transaction service that manages a set of participants
through a transaction process. The transaction service leads the participants through a "two-phase commit protocol," a fairly
simple and standard protocol that ensures that either all participants complete their respective operations in the transaction,
or none of them do. If you're interested, you can find out more about this protocol in the Jini Transaction Specification
(see Resources below).
The participants in a Jini transaction are typically Jini services and devices. If you are developing a Jini service, you
can enable it to participate in Jini transactions by implementing the TransactionParticipant interface. You can find out more about this interface in the Jini Transaction Specification.
Now we'll give you a better idea of how you can use transactions with JavaSpaces.
Transactions and JavaSpaces
The JavaSpaces application programming interface integrates Jini transactions in a clean and well-thought-out manner. As a
result, introducing transactional security into your JavaSpaces applications is usually fairly painless. To use transactions
with space-based operations, typically you first ask a transaction manager to create a transaction and manage it for a specified
lease time. Then, you pass the transaction to each space operation you'd like to occur under the transaction (which may include
operations over more than one space). Assuming there are no problems along the way, you then explicitly commit the transaction,
which results in all operations completing. If any problems occur, you can abort the transaction, which will leave the space
unchanged. The transaction might also be aborted by the transaction manager if, for instance, the transaction's lease expires.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- The complete source code for this example can be downloaded from
http://www.javaworld.com/jw-04-2000/jiniology/spacerelay.zip
- For a more in-depth exploration of space-based programming concepts and code examples, as well as a detailed look at the JavaSpaces
technology APIs, refer to Sun's official Jini Technology Series book, JavaSpaces Principles, Patterns, and Practice, Eric Freeman, Susanne Hupfer, and Ken Arnold (Addison-Wesley, 1999)
http://www.amazon.com/exec/obidos/ASIN/0201309556
- You may wish to experiment with the code from JavaSpaces Principles, Patterns, and Practice, which is downloadable from the book's Website
http://java.sun.com/docs/books/jini
- For information about getting your JavaSpaces (or Jini) programs up and running, refer to "The Nuts and Bolts of Compiling
and Running JavaSpaces Programs," Susanne Hupfer, (Java Developer Connection, January 2000)
http://developer.java.sun.com/developer/technicalArticles/Programming/javaspaces
- For specifics on Jini Transactions, see The Jini Specification, another Jini Technology Series book, by Ken Arnold, Bryan O'Sullivan, Robert W. Scheifler, Jim Waldo, and Ann Wollrath (Addison-Wesley,
1999)
http://www.amazon.com/exec/obidos/ASIN/0201616343
- You'll also find more information on Jini transactions in Core Jini, W. Keith Edwards (Prentice-Hall, 1999). It provides in-depth treatment of Jini, including information about lookup and discovery
http://www.amazon.com/exec/obidos/ASIN/013014469X
- For more on using Jini's lookup service, read the books mentioned above, along with "Locate Services With the Jini Lookup
Service," Bill Venners (JavaWorld, February 2000)
http://www.javaworld.com/javaworld/jw-02-2000/jw-02-jiniology.html
- Whether you wish to share information with other developers (including the Sun engineers that developed the Jini and JavaSpaces
technologies) or you seek troubleshooting advice, the official JavaSpaces-users mailing list is the place to go
http://archives.java.sun.com/archives/javaspaces-users.html
- The Jini-users mailing list also has a considerable amount of JavaSpaces-related discussion
http://archives.java.sun.com/archives/jini-users.html
- For pointers to the JavaSpaces FAQ and other documentation, refer to the Sun Microsystems JavaSpaces page
http://java.sun.com/products/javaspaces
- TechDispatch sends out a weekly Jini Advisor newsletter, written by Eric Freeman, that covers many of the nuances of Jini
and JavaSpaces technology (past topics have included codebase, leasing, and transactions). To subscribe, visit
http://www.techdispatch.com