By definition: bq. A context with a certain scope is said to propagate from one point in the execution of the program to another when the set of mapped instances of contextual types with that scope is preserved.
Application context is an example of propagating context. However, other built-in normal scopes (such as request context) usually do not propagate and are only bound to a single thread. It seems there are use cases where propagation makes sense (async jax-rs/servlet).
Weld context management API currently does not allow to:
# *"capture"* the current instances easily ({{javax.enterprise.context.spi.Context#get()}} can only be used if the set of beans for the given scope is known - requires a portable extension etc.) # *"clear"* the external storage without destroying the contextual instances (i.e. the context needs to be invalidated before) # *"initialize"* the external storage with the map of current instances (e.g. {{HttpServletRequest}} in case of request context bound to {{ServletRequest}}).
h2. Proposal
h3. ManagedContext Introduce {{WeldAlterableContext}}
Add {{org.jboss.weld.context. ManagedContext#getCurrentInstances() WeldAlterableContext }} method (name to interface into API. This interface will be discussed) that returns an immutable map implemented by all contexts supporting propagation and will contain methods to *capture* current context state in a given thread returning you a collection of {{javax.enterprise. all active contextual instances from that context .spi.Contextual}} and to *clear and set* the current instance state of the contextual type. Contextual is not guaranteed to be designed correctly as context, feeding it a map key so we might need to return a map collection of {{org.jboss.weld.serialization.spi.BeanIdentifier}} to current contextual instances instead. This method would be used to "capture" the as its new state. By default, the method would throw
h3. Introduce helper methods on {{ UnsupportedOperationException WeldManager }} .
*UPDATE:* Note that we cannot actually return just a map of {{ Contextual WeldManager }} -> {{Object}} because we need will provide additional means to preserve get hold of all scopes in the application, subsequently allowing user to grab all underlying contexts (implementing {{ CreationalContext WeldAlterableContext }} too so that we're able to destroy the dependent objects correctly ) .
h3. BoundContext Compose a human-readable test as an example
Add {{org.jboss.weld.context.BoundContext#reset()}} method (name to Apart from docs, there should be discussed) an easy to read test that would accept a map of {{javax.enterprise.context.spi.Contextual}} will show how to the current instance of the contextual type propagate contexts ( or BeanIdentifier->instance, see above ideally all of them ) which will server as a guide for users . This method would be used to "reset" the external storage and clear all threadl local caches. By default, the method would throw {{UnsupportedOperationException}}. |
|