Title: Message
Okay, I will add the clear() and remove() methods to Container so that the whole concept of removing components from pages becomes possible. I will then play around with some different ways to remove and re-apply components to pages - either via AOP or via page base classes as Juergen suggests. I think there may by some side effects that I haven't noticed yet which may make things interesting (e.g. are components needed before the page gets as far as rendering?). My goal will be to make this possible without any other modifications to the Wicket core. I will then document how to do it within the Wicket Reference Manual (probably in a section on Scalability).
 
Chris
 
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: 11 November 2004 10:55
To: '[EMAIL PROTECTED]'
Subject: AW: [Wicket-develop] Thoughts on page lifecycle

I agree with the clear() and remove() functions, because they are required to remove the components. But do we really need the additional doBeforeRender and doAfterRender() methods. Assuming many projects have project-specific base-pages, isn't it trivial to put there? Just like
 
void handleRender(final RequestCycle)
{
    doBeforeRender();
    super.handleRender();
    doAfterRender();
} 
 
This is how I do it in several cases (see displaytag examples), where the the component and/or model is not yet known while within the constructor. An example: user specific information can only be accessed after the user has logged in, which is handled during checkAccess(). I postponed retrieving the information until handleRender().
 
regards
Juergen
 

Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Christopher Turner
Gesendet: Donnerstag, 11. November 2004 10:28
An: '[EMAIL PROTECTED]'
Betreff: [Wicket-develop] Thoughts on page lifecycle

Hi All,

I have been thinking about the lifecycle of pages in Wicket, specifically about how I can utilise Wicket in a project where there will potentially be a very large number of sessions and not a huge amount of application server memory. Obviously, detachable models go a long way to keeping down the amount of stuff stored in the session. However, there is still the overhead of holding the page objects and all of their components in the session. In this project there is one particular page that has a very large number of components, which in turn results in some fairly heavy memory requirements. I think I've come up with a neat solution that involves minimal code changes but I thought I'd run it by everyone for opinions before I take it any further.

Basically my idea is to add two new protected lifecycle methods into Page:

protected void doBeforeRender(RequestCycle cycle) {
        // Empty default implementation
}

protected void doAfterRender(RequestCycle cycle) {
        // Empty default implementation
}


I then modify HttpRequestCycle to be:

protected void handleRender() {
        ...
        page.doBeforeRender(this);
        page.render(this);
        page.doAfterRender(this);
        ...
}


Finally I need to add new protected method to Container that allows us to remove all of the components from a container:

protected void clear() {
        childForName.clear();
}


By default this has no effect on anything. However, if I am concerned about session space (but happy to accept more object creation and finalization) I can then provide an alternative implementation for pages:

public class LowSessionMemoryPage extends HtmlPage {

        public LowSessionMemoryPage(...) {
                // Do initalisation, create models and so on but don't create components
        }

        protected void doBeforeRender(RequestCycle cycle) {
                // Create and add the components each time
                add(new Label("label1", new Model("example")));
                // and so on...
        }

        protected void toAfterRender(RequestCycle cycle) {
                // Remove all the components
                this.clear();
        }

}


The net effect of this is that we only have to store the actual page objects and any model objects (which are detachable) that the page needs to keep track of. Components are created and destroyed as part of each cycle. An extra advantage is that we can have far more control over the amount of data that gets clustered.

There is then a natural extension to this whereby we add an additional method to Container:

protected void remove(String componentName) {
        // remove the named component
}


This then allows a hybrid approach whereby we can create small components in the page constructor but create and destroy larger ones as part of every render cycle.


I know when Jonathan devised Wicket he was looking to a world where application server memory and network bandwidth for clustering were not a problem. However, I think many people will evaluating Wicket for very large projects will be sceptical about holding page and component hierarchy objects in the session - especially in a clustered environment. This expanded approach has no impact on most day-to-day Wicket projects but does provide increased scalability required for large projects for minimal additional learning curve or extra code.

Comments anyone?

Regards,
Chris

Reply via email to