avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <dona...@apache.org>
Subject Re: Using ThreadContext
Date Fri, 26 Oct 2001 11:56:19 GMT
On Fri, 26 Oct 2001 01:46, Peter Royal wrote:
> I remembered seeing Pete's message a few weeks back about the new
> ThreadContext code so I thought I would check it out when I was revamping a
> piece of my project that uses ThreadLocal's (the never-ending quest to use
> avalon to its fullest :)


> Maybe I'm missing something here, I can't see how to read data from a
> ThreadContext.

you can't because that would break the pattern. Users can set the 
ThreadContext if they have the correct permission but it is completely and 
utterly up to the Policy to determine what happens. The users can never 
directly interfer with that part of process.

> You create a new ThreadContext (MyTC) by using its 2-part constructor that
> takes a policy and a Map. The ThreadContext class uses the policy to
> validate all items in the Map before propogating them to its own internal
> Map.
> I would then take MyTC and use ThreadContext.setThreadContext() to assign
> it to the current thread. (Stored in the internal InheritableThreadLocal).
> I can then also retrieve MyTC by using ThreadContext.getThreadContext()..
> but then what? There isn't any way to get at the internal Map of my data
> that I can see.

right - see above ;)

The only reason ThreadContext.getThreadContext() exists is because sometimes 
you may want to cache current context, apply another context, call another 
method. After the method finishes you can set your old thread context back in 

> Pete, I'm not sure what your vision was for accessing the data in that map,
> be it exposing a ThreadContextAccessor or what. If you tell me what you
> want it to do, I can write the code.

Well I was almost finished it as it is. My intention is that the policy 
object is the only object in the system that actually does anything and it is 
completely up to it to determine how a context is applied. 

Does that make sense ?



| Never argue with an idiot, they'll drag you down to |
| their level, and beat you with experience           |

To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org

View raw message