-
1. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
marklittle Feb 25, 2015 6:05 AM (in response to mmusgrov)Is there a clear need for any extensibility at this stage?
-
2. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
tomjenkinson Feb 25, 2015 6:12 AM (in response to mmusgrov)The Jira for the use case is summarized here based on community feedback from the other thread: [JBTM-2342] Add callbacks for thread-to-transaction association changes - JBoss Issue Tracker
The following diagram illustrates the call backs you could expect when executing in a 2 JVM scenario where JVM1 calls JVM2 twice within the scope of the same transaction:
The following diagram explains the proposed call backs if say a reaper in JVM1 times out the TX:
As you can see, it should allow a Synchronization/TXAssociationListener combo to synchronize themselves and ensure they do not tamper with a none-thread safe transactional resource if the only threads are the app thread and the transaction reaper.
-
3. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
tomjenkinson Feb 25, 2015 6:17 AM (in response to marklittle)Mark Little wrote:
Is there a clear need for any extensibility at this stage?
+1 - I am not aware of any need for any further extensibility at this stage. The safest design would be something that tackles the issue we are working to resolve for the user today but does not preclude additions in the future. As such I would propose an interface name that captures the fact that this is an extension to Synchronization with additional callbacks.
How about:
interface ExtendedSynchronization {
public void stateChange(TransactionEvent e);
}
enum TransactionEvent {
ASSOCIATED,
DISASSOCIATED
}
That should be enough to capture the events we know we need. It also means in the future that if we discovered a need to flag to users an event was about to happen you could add beforeStateChange(TransactionEvent) to the interface. And if we found a need for future events we can add them to the enum.
-
4. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
tomjenkinson Feb 25, 2015 6:18 AM (in response to tomjenkinson)In terms of naming, we could even go with:
interface ExtendedSynchronization extends javax.transaction.Synchronization
-
5. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
tomjenkinson Feb 25, 2015 6:20 AM (in response to tomjenkinson)Also, as a note to how to register one of these things. We have two immediate options without changing the JTA API:
1. Use putResource in the TSR
2. Do an "instanceof ExtendedSynchronization" during register*Synchronization methods
-
6. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
tomjenkinson Feb 25, 2015 6:22 AM (in response to tomjenkinson)Of course, my answers 4 and 5 assume a certain level of coupling to JTA, if we wanted to remain neutral to that we don't need the "extends javax.transaction.Synchronization" but the rest can still hold. We could also provide something on BasicAction to pass one of these in if the user is coding directly against that.
-
7. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
marklittle Feb 25, 2015 6:36 AM (in response to tomjenkinson)I'm no longer sure if it makes sense to use ThreadActionData, which is what I was thinking earlier today. However, I do wonder what the overhead implications are on doing these additional calls, especially on transactions that don't have a need. One obvious optimisation is not to do this unless there are Synchronisations registered.
-
8. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
mmusgrov Feb 25, 2015 6:57 AM (in response to marklittle)You could keep the idea of using ThreadActionData if ExtendedSynchronization registrations are stored with the BasicAction. Then when BasicAction#removeChildThread() and BasicAction#addChildThread() are called in response to suspend and resume we would notify the listeners in this list of ExtendedSynchronizations. That sounds like a rather simple change to make to support the new feature.
-
9. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
marklittle Feb 25, 2015 7:20 AM (in response to mmusgrov)Yes, but I'm worried about overhead on additional calls. Plus, BasicAction doesn't know about Synchronizations at all - that concept doesn't come in until TwoPhaseCoordinator. It would break the model to add them to BasicAction.
-
10. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
mmusgrov Feb 25, 2015 8:01 AM (in response to marklittle)But we are talking about thread association listeners (not synchronisations - we don't have to call them ExtendedSynchronizations) and these rightly belong to BasicAction.
The additional calls need to be made somewhere if we want to support the feature
-
11. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
marklittle Feb 25, 2015 8:22 AM (in response to mmusgrov)Wouldn't make sense to add this to BA if it looks and feels like a synchronisation specific thing but is called Fred, for instance.
And yes of course additional calls need to be made somewhere, but no one has yet responded to my concern over any potential overhead. Optimisations and location of these calls play into that discussion.
-
12. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
mmusgrov Feb 25, 2015 8:33 AM (in response to marklittle)Mark Little wrote:
Wouldn't make sense to add this to BA if it looks and feels like a synchronisation specific thing but is called Fred, for instance.
Why are thread association changes synchronisation specific. If you argue that they are then the logical consequence would be that ThreadActionData calls into BasicAction are misplaced.
Mark Little wrote:
And yes of course additional calls need to be made somewhere, but no one has yet responded to my concern over any potential overhead. Optimisations and location of these calls play into that discussion.
Since suspend/resume handling happens in BasicAction and we want to add notifications for when that happens what alternative is there?
-
13. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
mmusgrov Feb 25, 2015 8:36 AM (in response to marklittle)Mark Little wrote:
And yes of course additional calls need to be made somewhere, but no one has yet responded to my concern over any potential overhead. Optimisations and location of these calls play into that discussion.
Lcating the calls in AtomicAction could be made to work too if BA really is too high up in the hierarchy.
-
14. Re: Requirement for an observer SPI for tracking thread-to-transaction association changes
marklittle Feb 25, 2015 8:43 AM (in response to mmusgrov)Michael Musgrove wrote:
Mark Little wrote:
Wouldn't make sense to add this to BA if it looks and feels like a synchronisation specific thing but is called Fred, for instance.
Why are thread association changes synchronisation specific. If you argue that they are then the logical consequence would be that ThreadActionData calls into BasicAction are misplaced.
I didn't say thread association was synchronisation specific. What I meant was really two things: first if the class/interface has a name which implies synchronisations then it shouldn't go into BA; second if the class/interface has extensions that only make sense for, or imply, synchronisations then it shouldn't into BA.
Mark Little wrote:
And yes of course additional calls need to be made somewhere, but no one has yet responded to my concern over any potential overhead. Optimisations and location of these calls play into that discussion.
Since suspend/resume handling happens in BasicAction and we want to add notifications for when that happens what alternative is there?
Well this is part of the problem. If you want to do this generically then ever time a transaction is associated or disassociated there'd be a call on this class to go and do work, just as there is with ThreadActionData. That's potentially an unnecessary overhead that we need to examine first. There would be little scope for optimisations here other than assume most of the time it's a null list of participants that will be trawled (or not). If we make this specific to synchronisations then there are optimisations that may be made, such as only calling if there is at least one synchronisation registered and perhaps only calling if disassociation/association occurs at specific points in a flow.