It seems that all Guice's out-of-the-box Scope implementations are
inherently Thread-based (or ignore Threads entirely):
Scopes.SINGLETON and Scopes.NO_SCOPE ignore Threads and are the edge
cases: global scope and no scope.
ServletScopes.REQUEST and ServletScopes.SESSION ultimately depend on
retrieving scoped objects from a ThreadLocal<Context>. The retrieved
Context holds a reference to the HttpServletRequest that holds a
reference to the scoped objects stored as named attributes (where name
is derived from com.google.inject.Key).
Class SimpleScope from the custom scope Guice wiki also provides a per-
Thread implementation using a ThreadLocal<Map<Key<?>, Object>> member
variable.
With that preamble, my question is this: how does one go about
creating a non-Thread-based Scope? It seems that something that I can
use to look up a Map<Key<?>, Object> is missing, as the only things
passed in to Scope.scope() are a Key<T> and a Provider<T>.
Thanks in advance for your time.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
the scope manager could pick a random number. or it could use the time of day. or it can reference a static value set by another thread. I don't mean to be facetious but it is really that arbitrary.
do you have a use case in mind? I would be happy to fill in more details if need be.
On Mar 24, 2010 4:11 PM, "Russ Milliken" <russ.m...@gmail.com> wrote:
I don't understand your reference to a Thread. I want a Scope that is not Thread-based. MyScopeManager in your example should not determine which objects are "in scope" based on what Thread is in context. Given that, how should my Scope implementation or MyScopeManager determine in which scope the given Key resides?
Thanks,
-Russ
On Wed, Mar 24, 2010 at 3:08 PM, Fred Faber <ffa...@gmail.com> wrote:
>
> You can do this if your lookup key is accessible to the thread performing the lookup, at lookup ...
>
>
>
> On Wed, Mar 24, 2010 at 2:47 PM, Russ <russ.m...@gmail.com> wrote:
>>
>>
>>
>> ...
--
> You received this message because you are subscribed to the Google Groups "google-guice" group.
> ...
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To p...
On what do you wish to base your Scope, if not on Thread identity?
Max.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
Fundamentally, the Java programming language only gives you two ways of
accessing state when buried deep in infrastruture:
1) Static fields
2) ThreadLocals
So those are the only options you have for implementing Guice scopes.
If you're using a windowing toolkit and want a scope specific to it, you
could use a static or threadlocal to get a reference to a relevant
windowing object and thus ask the windowing object about its current
state .... but you still need a static or threadlocal in there to get a
reference to the windowing toolkit.
Max.