I am working on an application which accepts "plugins". This is accomplished with an interface which the plugins implement. The plugins, which are dynamically loaded, are invoked from a stateful session bean using container managed TXs. The TX demarcation for the calling method is "Required". Some of the client plugins will be EJB based while others will use JDBC.
How do I ensure everything takes place in the same transaction?
To further complicate matters, the plugins manipulate the file system. The application requires the file system to be kept in a consistent state. The plugins need to be notified of the outcome of the TX (commit or rollback) and clean-up accordingly. What's the best way to do this?
Should the calling EJB implement SessionSynchronization and notify the plugins in after afterCompletion? Should my plug-in API extend Synchronization so I can register the plugins with the TX manger some how? What about the non-EJB, JDBC case? (I cannot use setAutoCommit(), commit(), etc.. because the TX context follows the thread).
My current implementation has begin(), comit(), and rollback() methods on the plugins. I have the plugins using new user transactions which I notify. However, this creates locking problems if one of the plugins references an row locked by the outer TX.
Your suggestions are greatly appreciated!