Add beginDispatch/endDispatch to VertxContext#572
Conversation
Expose context dispatch lifecycle methods so that consumers can manage thread-local context without depending on the Vert.x internal API (ContextInternal). This covers split-dispatch use cases like JCA message endpoint delivery where begin and end happen in separate method calls.
Is it? In my eyes, the whole point of There's nothing wrong with using |
|
I agree with @Ladicek, I don't think this is bringing much, except exposing low-level APIs which I would not recommend using, except if you know what you are doing. |
|
Well, it's explicitly said in the class' Javadoc:
About @cescoffier's comment, I agree, but I don't see how I can use the recommended |
Summary
VertxContext.beginDispatch(Context)andVertxContext.endDispatch(Context, Context)static methods to bothvertx4-contextandvertx5-contextmodulesContextInternal.beginDispatch()/endDispatch()so that consumers can manage the thread-local context dispatch lifecycle without depending on the Vert.x internal APIMotivation
The whole point of
VertxContextis to shield consumers fromContextInternal— but until now it only covered context creation (duplicate, nested, etc.), not context dispatch. This forced projects like quarkus-ironjacamar to importContextInternaldirectly forbeginDispatch()/endDispatch()calls (seeDuplicatedContextMessageEndpoint).The JCA message endpoint delivery lifecycle splits begin/end across separate method calls (
beforeDelivery→ message delivery →afterDelivery), so the higher-levelContext.dispatch(Runnable)API cannot be used. These new methods fill that gap.Test plan
testBeginAndEndDispatchto bothvertx4-contextandvertx5-contexttest suitesbeginDispatchsets the thread-local context and returns the previous one, andendDispatchrestores itmvn test -pl vertx4-context,vertx5-contextpasses