I figured out the solution and it was right in front of me. My source
code
protected <T> void visitThreadLocalScope(Injector injector,
DefaultBindingScopingVisitor<T> visitor) {
if (injector == null) {
return;
}
Map<Key<?>, Binding<?>> allBindings = injector.getBindings();
for (Map.Entry<Key<?>, Binding<?>> entry :
allBindings.entrySet()) {
final Binding<?> binding = entry.getValue();
// Not interested in the return value as yet.
binding.acceptScopingVisitor(visitor);
}
}
My implementation of DefaultBindingScopingVisitor
private static final class ExitingThreadLocalScopeVisitor extends
DefaultBindingScopingVisitor<Void> {
@Override
public Void visitScope(Scope scope) {
if
(ThreadLocalScope.class.isAssignableFrom(scope.getClass())) {
ThreadLocalScope threadLocalScope =
(ThreadLocalScope) scope;
threadLocalScope.exit();
}
return null;
}
}
It is so easy and yet so powerful. Thanks for the wonderful tool.
On Mar 22, 6:20 pm, Kartik Kumar <[email protected]> wrote:
> Hi
>
> I have a possible use case where I need to introspect the Bindings returned
> from the injector. I need to find out what bindings are scoped with a custom
> scope implementation. For example, I need to scope Connection as thread
> local to manage jdbc transactions. After the transaction has been
> committed/rolled back, I need to remove all stored thread local elements to
> prevent memory leakage. I have a hook to the injector but not the modules.
>
> SPI api requires access to the modules but not the injector. Is there a way
> around this issue?
>
> Kartik
--
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.