Hi thanks for the replies,

Yes I want to do it per Page so I can monitor the performance per page.

Here is how I implemented it, I am not sure if I always get the name
of the Page name in the implementation of onEndRequest. (Allthough
during tests I always got the name of the Page.)

public class JAMonMonitoredWebRequestCycle extends WebRequestCycle {

    static final String UNIT = "ms.";

    private ThreadLocal<Long> startTimes = new ThreadLocal<Long>();

    public JAMonMonitoredWebRequestCycle(WebApplication application,
WebRequest request, Response response) {
        super(application, request, response);
    }

    @Override
    protected void onBeginRequest() {
        super.onBeginRequest();
        addStartTimeToThreadLocal();
    }

    @Override
    protected void onEndRequest() {
        super.onEndRequest();
        calculateDurationAndAddToMonitor();
    }


    private void addStartTimeToThreadLocal() {
        startTimes.set(System.currentTimeMillis());
    }

    private void calculateDurationAndAddToMonitor() {
        if(startTimes.get() != null) {
            Class<?> pageClass = null;
            if(getWebResponse().isAjax() && getWebRequest().getPage() != null) {
                pageClass = getWebRequest().getPage().getClass();
            } else {
                pageClass = getResponsePageClass();
            }
            if(pageClass != null) {
                MonitorFactory.add(pageClass.toString(), UNIT,
System.currentTimeMillis() - startTimes.get().doubleValue());
            }
            startTimes.set(null);
        }
    }

}


I believe the Page to be rendered is not availble yet in the
onBeginRequest so I use MonitorFactory.add() in the onEndRequest and
store the startTime in a ThreadLocal. While typing this email I am
thinking that WebRequestCycle is statefull so I probably do need the
ThreadLocal right?

Lars

On Jan 30, 2008 8:22 PM, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
> On Jan 30, 2008 11:20 AM, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> > but per page...
>
> Why don't you just answer then.
>
>
> Eelco
>
> ---------------------------------------------------------------------
> 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]

Reply via email to