-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ThreadContext.REQUEST #134
Comments
You are talking about CDI req scope., but CDI has multiple scopes you need to consider. There is session and conversation as well. These are all incorporated in So what exactly would happen if you tried to propagate |
I assume that if the (narrower) request scope is propagated, then the (wider) conversation and session scopes are going to also be propagated. Is there some reason to think this wouldn't work? (Note, you need to consider how this works in the context of a reactive stream processing a single request.) |
Well, the spec doesn't (yet) define what exactly propagates but it should state that with |
Actually, if you propagate all contexts then both those (request) contexts will be propagated. |
Sure, but as I understand it, "all contexts" is not the default behavior. |
Sure, I agree. Sorry I left that implicit. Certainly the spec should make it explicit. |
There is no default anymore. When there was a default, it was "all contexts except transaction" so it would have worked. Using |
@aguibert is currently working on the pull that explicitly defines in the spec what is propagated by CDI context. There was another issue already open for it and it is being done under that issue. |
@FroMage well, OK, fine, if that's indeed the resolution of #124.
Nevertheless, I it seems to me that there's still a need to be able to easily control request context propagation individually from other contexts. (For essentially the same reasons that we have a need to control |
I wouldn't say so, introducing
|
@manovotn I don't understand.
I could make the exact same criticism of
These are both perfectly valid interpretations of
Nope.
On the contrary, you're in a completely well-defined state, with fresh CDI contexts, but the JAX-RS request and response objects propagated from the thread that was processing the JAX-RS request. |
Am I correct in assuming that JAX-RS request context refers to the javax.ws.rs.core.Context annotation being used at class level to inject an instance that might be used across different request, that information possibly being lost when accessed from a completion stage action? I checked with one of our JAX-RS experts @andymc12 on this who informed me this pattern is non-strategic and being replaced by CDI |
I think so. But @FroMage can clarify this.
That's not clear to me. The fact that you're using |
I mean, look, if there's a need for I mean, you can write So what then is the difference between the two cases? |
But they wouldn't be accessible from anything the completion stage method calls. So the CDI |
Then I misunderstood your initial comments which seemed to me that Now the question is how many contexts we want to place into the spec for its 1.0. Just note that the model we have is extensible and we can experiment with additional contexts in impls and pull them into specs later on. |
Well it's my understanding that the other context identifiers on So no, that's not what I meant.
Well I guess at least naively that seems like a very easy question to answer: there should be an appropriate context identifier whenever any of the Microprofile specs require that information be propagated with the current thread. I understand that the model is extensible, but the set of Microprofile specs is finite. In fact, it's rather small. |
I went back to the JAX-RS expert group member and asked the direct question about whether they foresee creating a scope/scopes of their own or whether they expect to reuse existing CDI scopes for the injectable JAX-RS objects. His reply, while qualified that this hasn't been sufficiently discussed in the JAX-RS community, is that he foresees the use of existing CDI scopes, which would vary by type, with most being request scoped, and a few being application scoped or possibly session scoped. Given that the probable direction for JAX-RS is that |
Despite the name, The difference with JAX-RS usage of CDI context is in the details of the yet-to-be-officially-defined proposal. We can only speculate on it, albeit with the guidance and help of the JAX-RS community hinting at the future direction. And I'm told that we should prepare for injectable instances with life cycle that is tied to built-in CDI scopes. If that's how it is defined, then it is natural that by switching CDI scopes, the JAX-RS context that is tied to it must change as well. Ultimately, we need to wait and see. We should at least not do anything contradictory to this in the meantime. |
I agree that if the JAX-RS implementations refrain from storing any state in its own threadlocals, and stores everything in CDI contexts instead, then this feature is unnecessary. However, this behavior would have to be mandated by the JAX-RS spec. Because I'm pretty sure that currently all JAX-RS implementations associate some state with the thread via their own threadlocals, and if the spec doesn't explicitly prohibit this, then they will most likely continue to do that, even after introducing support for |
With this being the last issue remaining open against the MP Concurrency initial release, and it being unlikely to see an answer with 100% certainty from JAX-RS in the near term, I would like to propose that we keep this issue open and defer it to vNext of MP Concurrency. This will ensure that we don't put anything into the spec that ends up being incompatible/inconsistent with where JAX-RS is headed. Is this approach acceptable to everyone else? |
OK. |
Currently it's possible to control propagation of contexts via passing of Stringly-typed identifiers. There are some standard identifiers defined by
ThreadContext
. For example,ThreadContext.TRANSACTION
is useful to control exactly when transaction contexts are propagated to long-running asynchronous jobs.However, there is no standard identifier for the very important request context. As I understand it, the current behavior is that if a JAX-RS client calls a
ManagedExecutor
to start a job, then:(If my understanding here is wrong, please could someone correct me.)
Assuming that my understanding is correct, well, it's broken.
ManagedExecutor
.And we don't even give the user a very good way to control request context propagation, since there is no standard way to identify the JAX-RS contexts.
I therefore propose that:
ThreadContext.REQUEST
, and specifyManagedExecutor
, andREQUEST
context is propagated.We don't need to limit
ThreadContext.REQUEST
to always mean the JAX-RS request, just as the CDI request scope doesn't always mean a servlet request.Note that the required behavior for
ThreadContext.REQUEST
is extremely similar toThreadContext.TRANSACTION
. It should be propagated along a reactive stream, but not (by default) to aManagedExecutor
job.Hope I'm not misunderstanding something fundamental here.
The text was updated successfully, but these errors were encountered: