Monday, April 13, 2009

Wicket on Google App Engine

Like many others I am using Wicket on Google App Engine re-writing one of my pet projects. Google App Engine does not allow for user applications to start new threads so in order to get Wicket working, you need to disable the ModificiationWatcher by setting the resource poll frequency to NULL. This has a huge disadvantage when you're in development mode, because you'd have to restart the servlet engine each and every time you make a change in one of your HTML or other resource files.
Well - I dug into the Wicket internals and found out the ModificationWatcher was NOT meant to be plugable.. Yikes!.. Well I tried different approaches but found one that worked like a charm and it was dead simple:

Create the "org.apache.wicket.util.watch" package in your project, add a Class called ModificationWatcher and make it a copy of the ModificationWatcher from the original Wicket sources. Remove all threading but keep the base logic in the "start(Duration pollFrequency)" method.

Now override "newWebRequest" in your WebApplication class like this:

@Override
protected WebRequest newWebRequest(HttpServletRequest servletRequest) {
getResourceSettings().getResourceWatcher(true).start(getResourceSettings().getResourcePollFrequency());
return super.newWebRequest(servletRequest);
}

and vupti you've got reload of resource files again, even on Google App Engine. Remember this is only for development, but I cant see any other ways of doing it.

And to the wicket developers - please make the ModificationWathcer extendable someway.

9 Comments:

Blogger Morten said...

Hi Lars. Nice work! I'll go ahead and try it out...

16/4/09 23:15  
Blogger Trevor Kimenye said...

For those wondering how a stripped down version of ModificationWatcher would look like:


public void start(final Duration pollFrequency)
{
// Construct task with the given polling frequency
//task = new Task("ModificationWatcher");

//task.run(pollFrequency, new ICode()
//{
// public void run(final Logger log)
// {
// Iterate over a copy of the list of entries to avoid
// concurrent
// modification problems without the associated liveness issues
// of holding a lock while potentially polling file times!
for (final Iterator iterator = new ArrayList(modifiableToEntry.values()).iterator(); iterator
.hasNext();)
{
// Get next entry
final Entry entry = (Entry)iterator.next();

// If the modifiable has been modified after the last known
// modification time
final Time modifiableLastModified = entry.modifiable.lastModifiedTime();

if (modifiableLastModified.after(entry.lastModifiedTime))
{
// Notify all listeners that the modifiable was modified
entry.listeners.notifyListeners();

// Update timestamp
entry.lastModifiedTime = modifiableLastModified;
}
}
// }
//});
}

public void destroy()
{
//if (task != null)
//{
// task.stop();
// task.interrupt();
//}
}


I know, its really fugly.

1/6/09 06:10  
Blogger   said...

hi.

Could you publish the source of the ModificationWatcher that works on appengine?

thanks.

5/6/09 15:28  
Blogger Trevor Kimenye said...

This comment has been removed by the author.

6/6/09 04:28  
Blogger Trevor Kimenye said...

I've posted a version of the ModificationWatcher and detailed info on my blog: http://kimenye.blogspot.com/2009/06/google-app-engine-wicket.html

7/6/09 08:22  
Blogger Nick Wiedenbrueck said...

The resource modification watching will be fixed as of Wicket 1.4.0-RC6. The Wicket guys introduced a replaceable IModificationWatcher interface.

https://issues.apache.org/jira/browse/WICKET-2340

2/7/09 08:17  
Anonymous Anonymous said...

I found this site using [url=http://google.com]google.com[/url] And i want to thank you for your work. You have done really very good site. Great work, great site! Thank you!

Sorry for offtopic

8/11/09 18:31  
Anonymous Anonymous said...

This comment has been removed by a blog administrator.

14/11/09 22:08  
Blogger 123 123 said...

This comment has been removed by a blog administrator.

25/12/09 12:48  

Post a Comment

<< Home