calling reloadCache programtically.

44 views
Skip to first unread message

Yehonatan Moses

unread,
Oct 23, 2013, 4:20:13 AM10/23/13
to wr...@googlegroups.com
Hi,

I have several servers and I'd like to call reloadCache using an api (instead of jmx console to each one..)
What I currently did is simple obtaining the WroConfiguration from the ServletContext and invoking the method, but now I'm getting an error saying 

"Unable to reload cache, probably because invoked outside of context"

What exactly am I doing wrong?


Alex Objelean

unread,
Oct 23, 2013, 5:24:37 AM10/23/13
to wr...@googlegroups.com
Hi,

in order to have access to WroConfiguration and any other object from wro4j internal api, your request must be part of the wro4j lifecycle. This can be achieved using ro.isdc.wro.http.WroContextFilter (more details can be found here).

However, there is a simpler solution. Wro4j already has an infrastructure to use and evolve an API around it. It can be achieved using RequestHandler. There is already an implementation of RequestHandler called ReloadCacheRequestHandler which does exactly what you need, flushes the cache when the following request in invoked: /wro/wroAPI/reloadCache . From security reasons, this request handler is available only in development mode, but you can easily extend it and expose using your custom security policy. 

Let me know if you need more details.

Cheers,
Alex




--
You received this message because you are subscribed to the Google Groups "wro4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wro4j+un...@googlegroups.com.
To post to this group, send email to wr...@googlegroups.com.
Visit this group at http://groups.google.com/group/wro4j.
For more options, visit https://groups.google.com/groups/opt_out.

Yehonatan Moses

unread,
Oct 23, 2013, 5:39:56 AM10/23/13
to wr...@googlegroups.com
Thanks for the prompt reply, I'll look into that.

you mentioned the lifecycle of the request.. but if that the case, what's the difference between calling the method via jmx ? what makes the jmx part of the lifecycle?

Alex Objelean

unread,
Oct 23, 2013, 5:53:10 AM10/23/13
to wr...@googlegroups.com
The JMX doesn't need to access the WroConfiguration object, since the WroConfiguration itself is an MBean and can invoke methods of that object. 
I now realize that this is not an ideal approach, since a fresh instance of WroConfiguration is created for every request to WroFilter, but the MBean registered with JMX uses the very first instance of WroConfiguration created. 

Alex
Reply all
Reply to author
Forward
0 new messages