The advice Nathan gave me for reloading the VelocityEngine at runtime, worked exactly as he predicted. Excellent, I can now turn caching on/off from within the application at runtime. Makes a huge difference to performance.
I use Log4j and my own resource loader so the advice about LogSystemCommonsLog and WebAppLoader were not applicable in my particular situation. Thanks, Steve -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] .org] On Behalf Of Steve O'Hara Sent: 05 September 2007 20:21 To: Velocity Users List Subject: RE: How to dynamically reload settings Blimey..... The mere mention of "...race condition..." is enough to keep me awake at night, or at the very least visit the pub for a few large ones! I'll give it a go at some stage and let the list know when/if I'm successful. Thanks for the very detailed and thorough explanation Nathan. Cheers, Steve -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] .org] On Behalf Of Nathan Bubna Sent: 04 September 2007 17:44 To: Velocity Users List Subject: Re: How to dynamically reload settings Forcing a call to the loadConfiguration method won't help. That would only try to re-init() the servlet's VelocityEngine (or something like that), and it's not currently possible to do that. In order to change settings, you'll need to replace the VelocityEngine. This is possible, but it'll probably take a bit of work on your part. You need to change your VelocityViewServlet class to recognize some sort of special "reset" servlet request. When it handles that request, it should create a new VelocityEngine, load and set the properties on it, call init() on that new engine, and then pass that already initialized engine to the setVelocityEngine() method. and wait, there's more... if you are pointing commons-logging to the LogSystemCommonsLog class, you will also want to pass your new engine to that class's static setVelocityEngine() method. and... if you are using the WebappLoader as your ResourceLoader (which is the default for the VVS), then you will need to set the ServletContext as an application attribute via a call like this. myNewEngine.setApplicationAttribute(SERVLET_CONTEXT_KEY, getServletContext()); oh, and these things should all be done *BEFORE* passing the new engine to the VVS's setVelocityEngine() method, or else you will get weird race condition stuff. and of course, i've never done any of this, but it should work. just be sure to do all the config and setup of the new VelocityEngine before you pass it to the setVelocityEngine() method. On 9/3/07, Steve O'Hara <[EMAIL PROTECTED]> wrote: > I'm extending the VelocityViewServlet class and overriding the > loadConfiguration method to load properties from my own storage area. > This is fine and works great, but there are circumstances within the > application where I need to change some settings dynamically e.g. > cacheing. > > Is there a way in which I can force Velocity to reload itself? i.e. > force a call to the loadConfiguration method > > Thanks, > Steve > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
