users@grizzly.java.net

strange statistics behaviour in grizzly http webserver

From: Zoltan Arnold NAGY <Zoltan.Nagy_at_Sun.COM>
Date: Sun, 26 Apr 2009 11:13:46 +0200

Hi all,

I've started using grizzly in my project, and for that I have written an
adapter
to print out statistics.

public class StatisticsAdapter extends GrizzlyAdapter {
    final Statistics statistics;

    public StatisticsAdapter(GrizzlyWebServer webserver) {
        statistics = webserver.getStatistics();
        statistics.startGatheringStatistics();
    }

    @Override
    public void service(GrizzlyRequest request, GrizzlyResponse response) {
        try {
            PrintWriter out = response.getWriter();
            out.println("number of requests since startup: " +
statistics.getRequestStatistics().getRequestCount());
            out.println("total number of bytes received: " +
statistics.getRequestStatistics().getBytesReceived());
            out.println("total number of bytes sent: " +
statistics.getRequestStatistics().getBytesSent());
            out.println("--");
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}

then I add it as such:

        GrizzlyWebServer ws = new GrizzlyWebServer(PORT);
        ws.addGrizzlyAdapter(new StatisticsAdapter(ws), new String[] {
"/stat" });

however, it behaves strangely. lets say I download a file of size
15962823 from the webserver, then grab /stat with curl:
"number of requests since startup: 1
total number of bytes received: 0
total number of bytes sent: 15958016"

then if I do this 5 more times, then the fifth will look like (so it
should be the sixth request totally from the server's point of view)
number of requests since startup: 9
total number of bytes received: 0
total number of bytes sent: 31916032

no file was downloaded from the server in the meantime, nor there were
any requests. both number of requests and
total number of bytes sent behaves in a totally confusing manner. and
this is the exact same behaviour for every startup.

what am I doing wrong? :-)

Thanks!

Zoltan