It's easy to go overboard with custom scopes, but sometimes they're just what you need. Check out Tim Boudreau's custom scopes framework.
https://github.com/timboudreau/scopes --tim On Fri, Oct 24, 2014 at 11:26 PM, Kevin Burton <[email protected]> wrote: > I have a complex stats system to monitor the behavior of our app. > > One of the things I want to do is track the name of a thread/task calling > a component. > > So I have a component called a Caller which I inject so that when a > component is created, I can see who called it. > > The problem is, how do you change the caller at runtime? > > It should be possible to do this with thread locals and a @Singleton. > > So basically you have a Task, which has a Caller dependency... then that > task just does > > String defaultCaller = caller.get(); > > try { > > caller.set( "my-task" ); > > mytask.run(); > > } finally { > caller.set( defaultCaller ); > } > > ... now I'm not super happy with thread locals, but this doesn't seem > amazingly ugly. > > Is there a better way to do this? > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/google-guice. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-guice/70f1dabe-40e0-4698-a451-6a1a07aabe28%40googlegroups.com > <https://groups.google.com/d/msgid/google-guice/70f1dabe-40e0-4698-a451-6a1a07aabe28%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CA%2BF8eeRYQ7XByXKQVnuALLTGwSxZj1VJBm8jAaQ4HNsQY%2B%2B8ug%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
