transactional file system in java - commons transaction

19
Transactional File System in Java – commons transaction Albert Guo [email protected]

Upload: guo-albert

Post on 13-Dec-2014

2.882 views

Category:

Business


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Transactional File System In Java - Commons Transaction

Transactional File System in Java – commons transactionAlbert Guo

[email protected]

Page 2: Transactional File System In Java - Commons Transaction

Agenda

CMCS Scenario

Commons Transaction

Commons Transaction Implementation

Conclusion

2

Page 3: Transactional File System In Java - Commons Transaction

CMCS Scenario

Page 4: Transactional File System In Java - Commons Transaction

System Architecture

CIS

Green

Windchill

Project Management

Document Management

Change Management

Pro/EWildfire

Pro/E

Wo

rk Sp

ace

Pro/E

PDMLink

Supplier Management

GSM

Product Management

(Part /BOM)

Interface

Ta

ble

SAPERP

ProjectLinkO

DB

C

xmls, files

4

Page 5: Transactional File System In Java - Commons Transaction

Scenario

5

Page 6: Transactional File System In Java - Commons Transaction

Commons Transaction

6

Page 7: Transactional File System In Java - Commons Transaction

Commons Transaction

• http://commons.apache.org/transaction/

7

Page 8: Transactional File System In Java - Commons Transaction

What is Commons Transaction

① Whenever you have concurrent access to resources and want to protect them with locks, Commons Transaction can be right for you.

② Providing lightweight, standardized, well tested and efficient implementations of utility classes commonly used in transactional Java programming.

③ The 1.x component is compatible to JDK1.2.

8

Page 9: Transactional File System In Java - Commons Transaction

Commons Transaction Features

Commons Transaction might be useful for you when you

①need transactional file access (i.e. ACID transactions on a set of files)

②have resources that need locking - lock managers can do that for you:

be sure you never forget to release a lock again

let your code have a timer for a whole block of locks

have an out-of-the-box solution for hierarchical locks

plug in your own custom or advanced solutions

9

Page 10: Transactional File System In Java - Commons Transaction

Commons Transaction Implementation

10

Page 11: Transactional File System In Java - Commons Transaction

Implementation Steps

11

Page 12: Transactional File System In Java - Commons Transaction

1. Initialize FileResourceManager

12

Page 13: Transactional File System In Java - Commons Transaction

2. Initialize FileResourceManager

storeDir String - JavaDoc says: "directory where main data should go after commit".

workDir String - JavaDoc says: directory where transactions store temporary data.

next parameter is a boolean that indicates if the path should be URL encoded. In our example it is false, indicating that we have simple path with no spaces or i18n characters in it.

sLogger LoggerFacade - JavaDoc says: the logger to be used by this store.

13

Page 14: Transactional File System In Java - Commons Transaction

3. Start FileResourceManager & Start Transaction

14

Page 15: Transactional File System In Java - Commons Transaction

4. Modify Resources

With the transaction started, you can begin file manipulation. You can perform following operations:

copyResource

createResource

deleteResource

moveResource

writeResource

In our example, we’ll demo createResource and writeResource

15

Page 16: Transactional File System In Java - Commons Transaction

4. Modify Resources

16

Page 17: Transactional File System In Java - Commons Transaction

5. Transaction Management

17

Page 18: Transactional File System In Java - Commons Transaction

Conclusion

18

Page 19: Transactional File System In Java - Commons Transaction

Conclusion

If you have to operate on files and cannot afford to loose data, seriously consider using commons-transactions package.

It is probably better then any custom mechanism you can come up with. It supports 2 phase commit.

With a little work, you could probably make it into an XA compliant resource.

Src.rar

19