Transactional File System in Java – commons transaction

2,932 views

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,932
On SlideShare
0
From Embeds
0
Number of Embeds
27
Actions
Shares
0
Downloads
46
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transactional File System in Java – commons transaction

  1. 1. Transactional File System in Java – commons transaction Albert Guo [email_address]
  2. 2. Agenda <ul><li>Use Case </li></ul><ul><li>Commons Transaction </li></ul><ul><li>Commons Transaction Implementation </li></ul><ul><li>Conclusion </li></ul><ul><li>Appendix </li></ul>Commons IO Commons Lang Commons Transaction
  3. 3. Use Case
  4. 4. Use Case Commons IO Commons Lang Commons Transaction
  5. 5. Commons Transaction
  6. 6. Commons Transaction <ul><li>http://commons.apache.org/transaction/ </li></ul>
  7. 7. What is Commons Transaction <ul><li>Whenever you have concurrent access to resources and want to protect them with locks, Commons Transaction can be right for you. </li></ul><ul><li>Providing lightweight, standardized, well tested and efficient implementations of utility classes commonly used in transactional Java programming. </li></ul><ul><li>The 1.x component is compatible to JDK1.2 . </li></ul>
  8. 8. Commons Transaction Features <ul><li>Commons Transaction might be useful for you when you </li></ul><ul><li>need transactional file access (i.e. ACID transactions on a set of files) </li></ul><ul><li>have resources that need locking - lock managers can do that for you: </li></ul><ul><ul><li>be sure you never forget to release a lock again </li></ul></ul><ul><ul><li>let your code have a timer for a whole block of locks </li></ul></ul><ul><ul><li>have an out-of-the-box solution for hierarchical locks </li></ul></ul><ul><ul><li>plug in your own custom or advanced solutions </li></ul></ul>
  9. 9. Commons Transaction Implementation
  10. 10. Implementation Steps
  11. 11. 1. Initialize FileResourceManager <ul><li>storeDir String - JavaDoc says: &quot;directory where main data should go after commit&quot;. </li></ul><ul><li>workDir String - JavaDoc says: directory where transactions store temporary data. </li></ul><ul><li>next parameter is a boolean that indicates if the path should be URL encoded. </li></ul><ul><li>In our example it is false, indicating that we have simple path with no spaces or i18n characters in it. </li></ul><ul><li>sLogger LoggerFacade - JavaDoc says: the logger to be used by this store. </li></ul>1
  12. 12. 2. Start FileResourceManager / 3. Start Transaction 2 3
  13. 13. 4. Modify Resources <ul><li>With the transaction started, you can begin file manipulation. You can perform following operations: </li></ul><ul><ul><li>copyResource </li></ul></ul><ul><ul><li>createResource </li></ul></ul><ul><ul><li>deleteResource </li></ul></ul><ul><ul><li>moveResource </li></ul></ul><ul><ul><li>writeResource </li></ul></ul><ul><li>In our example, we’ll demo createResource and writeResource </li></ul>
  14. 14. 4. Modify Resources
  15. 15. 5. Transaction Management
  16. 16. Conclusion
  17. 17. Conclusion <ul><li>If you have to operate on files and cannot afford to loose data, seriously consider using commons-transactions package. </li></ul><ul><li>It is probably better then any custom mechanism you can come up with. It supports 2 phase commit. </li></ul><ul><li>With a little work, you could probably make it into an XA compliant resource. </li></ul>
  18. 18. Appendix
  19. 19. Appendix <ul><ul><li>Commons Transaction </li></ul></ul><ul><ul><ul><li>Aimed at providing lightweight, standardized, well tested and efficient implementations of utility classes commonly used in transactional Java programming. Initially there were implementations for multi level locks, transactional collections and transactional file access. The 1.x component is compatible to JDK1.2. </li></ul></ul></ul><ul><ul><li>Commons IO </li></ul></ul><ul><ul><ul><li>Commons IO is a library of utilities to assist with developing IO functionality. </li></ul></ul></ul><ul><ul><li>Commons Lang </li></ul></ul><ul><ul><ul><li>The Lang Component provides a host of helper utilities for the java.lang API, notably String manipulation methods, basic numerical methods, object reflection, creation and serialization, and System properties. </li></ul></ul></ul><ul><ul><li>Log4j </li></ul></ul><ul><ul><ul><li>log4j is a Java-based logging utility. It was originally written by Ceki Gülcü and is now a project of the Apache Software Foundation. It is used primarily as a debugging tool. </li></ul></ul></ul>

×