On 17/01/2010 20:18, Fred Faber wrote:
Is just one thread handling all the behavior within a "call" scope?

Yes and after reading your answer i am pretty sure i mixed things up. It's absolutely correct to use a threadlocal, as long as my scope is as long as the threads life or (in my
case) shorter. Ok, i actually dont need it, but how would you implement
a scope greater than the lifespan of a thread (and less then singleton)? Just curious.

If so, you can use ThreadLocals to implement the scope, as long as you signal when a thread enters and leaves the scope:

callScope.enter();
try {
   ...do stuff;
} finally {
  callScope.exit();
}


And in this example, you can use SimpleScope right out of the box.

If you are dispatching to multiple threads within the duration of a "call" scope, then you'll need to have child threads inherit their parent's values. But that question is orthogonal to designing a smaller lifespan of a longer scope (such as RequestScope), and the example above should suffice.



2010/1/17 Willi Schönborn <[email protected] <mailto:[email protected]>>

    On 17/01/2010 19:43, [email protected] <mailto:[email protected]> wrote:


        On Jan 17, 6:10 am, Willi
        Schönborn<[email protected]
        <mailto:[email protected]>>
        wrote:

            we have a custom made framework here which has 4 scopes:
            - Application
            - HTTP Session
            - HTTP Request
            - Call

            Call is something that can happen multiple times during
            one request.
            I dont think there is really a need to understand the
            semantic,  anyways
            the request is bound to a thread, so i can use a
            threadlocal to keep track
            of the current request, which itself has a reference to
            the current session.
            Any idea how i can keep track of the current call?

        Take a look at CustomScopes:
        http://code.google.com/p/google-guice/wiki/CustomScopes

    I know about custom scopes, what i need is a hint/idea/whatever
    how to implement
    a scope that does not rely on a threadlocal. All non-singleton
    scopes i know about, like
    the request scope, the session scope or the example implementatio
    of simple scope (see your link)
    are all based on a threadlocal which itself only works when you
    use threads. The problem is,
    my custom scope (@CallScoped) is shorter than a request, so i cant
    use a threadlocal.

    --
    You received this message because you are subscribed to the Google
    Groups "google-guice" group.
    To post to this group, send email to [email protected]
    <mailto:[email protected]>.
    To unsubscribe from this group, send email to
    [email protected]
    <mailto:google-guice%[email protected]>.
    For more options, visit this group at
    http://groups.google.com/group/google-guice?hl=en.






--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

Reply via email to