Still working through my first cup of coffee, but couldn't that cache
be initialized in a ContextListener? Failing that, could use lazy
initialization in the method servicing the request. ie if
context.getAttribute("A_MAP_KEY") == null create and setAttribute.
On Apr 6, 3:58 am, Happy Feet <[email protected]>
wrote:
> Hi all, I'm refactoring a GWT app and plumbing in Guice to remove
> some of the cruft thats developing in our web.xml. I'm using guice to
> map the RPC services called by GWT client code. Roughly following the
> approach outlined
> here.http://stuffthathappens.com/blog/2009/09/14/guice-with-gwt/
>
> This approach requires moving away from extending RemoteServiceServlet
> but also means I no longer get access to the init(), shutdown() and
> destroy() methods that would normally be available via the
> ServletApi.
>
> This is not a problem for most of the services we've developed but in
> one case I've stumbled across a snippet of code in our service that
> relies on using init() to Create an object that passes in a reference
> to the servlet and kick off a thread that calls a method on the
> servlet class that polls a service and maintains a cache that can be
> used by the GWT service. Please see code below ( shortened for
> clarity )
>
> public class MyServiceImpl extends RemoteServiceServlet implements
> MyService{
>
> private CacheRefresh cr = null;
>
> public void init(ServletConfig servletConfig){
> super.init(servletConfig);
> cr = new CachRefresh(servletContext, this) ;
> cr.start();
> }
>
> public String someMethod(){ .. }
>
> }
>
> public class CacheRefresh extends Thread{
> public CacheRefresh(ServletContext context, MyServiceImpl
> servlet){
> ...
> }
>
> public void run(){
> context.setAttribute("A_MAP_KEY", servlet.someMethod() )
> }}
>
> I appreciate that using Threads in this way is also probably not a
> good idea. This is code I've inherited and I'll get round to doing
> something better there in due course.
>
> Does anyone have any good ideas on how to resolve this? The only
> option I can think of at the momen is to leave it is and configured by
> the mapping in the web.xml file. I don't like the idea of having
> configuration in loads of places and scattered around like pixy dust.
>
> Any suggestions welcome.
--
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.