I took a similar approach with the DWR-Guice integration, for which I
needed simple lifecycle management. There's a mini-framework for
defining context-specific scopes that can be closed with an explicit
method call, with pluggable type-specific handlers that are called for
every object of matching type associated with a given context.
("Context" is the parameterizable part of the framework; for example,
in a request scope, the context is the individual request.)

This mini-framework is really independent of DWR, but in the earliest
release the relevant code was mixed up in the same package as the DWR-
specific stuff, as you can see via this out-of-date link:

http://dev.priorartisans.com/tim/dwr-guice/

The main interface here is ContextScope:

http://dev.priorartisans.com/tim/dwr-guice/xref/org/directwebremoting/guice/ContextScope.html

In practice, I use the java.io.Closeable interface with a Closeable-
specific handler, so that all Closeable objects in the context have
their close() method called when the containing context is closed.
Even when a closeable class doesn't have any relation to I/O, it's
just feels easier and nicer to implement an existing standard
interface.

More recently, I've factored out the non-DWR Guice utilities into a
separate package, but I haven't had a chance to bundle it nicely.

Several people have said that the lack of detailed documentation and
examples for this mini-framework is a showstopper for them.

--tim


On Oct 6, 9:48 am, "James Strachan" <[EMAIL PROTECTED]> wrote:
> Since adding a patch for issue 
> 78http://code.google.com/p/google-guice/issues/detail?id=78
>
> I've taken a stab at adding support for @PreDestroy and Spring's
> DisposableBean lifecycles; building on top of my previous patch.
>
> So far the close hooks only work with Singleton scoped objects; but
> I've also added the functionality into the REQUEST and SESSION scoped
> Scopes too - though I've not yet added any code to the Servlet package
> to invoke the close() methods yet.
>
> I've introduced a Closeable interface which a Provider can implement
> (and a Scope can return a custom Provider which implements this); so
> if a Scope implements Closeable you can then close it down cleanly;
> ensuring that all objects are closed and each exception thrown is
> collected (rather like we do with the Errors class when binding
> objects).

--~--~---------~--~----~------------~-------~--~----~
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