Hello, 

how can we track the execution time of a server round trip? 
I mean: From the end user perspective. 

We have tried something naïve by writing an extension to a simple button and
overwriting the actionPerformed method on the client half-object.

But obviously, the communication after the button click is asynchronously
and the actionPerformed method returns immediately. 

Is there only one request to the server issued by the button click? 
Is it possible to plug-in some code at the place when the response has been
rendered by the UI engine to determine the stop event?

Cheers
Stefan

import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCLabel;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.application.event.serializable.IActionListener;
import com.ulcjava.base.client.UIButton;
import com.ulcjava.base.development.DevelopmentRunner;

public class TrackingApplication extends AbstractApplication {

  public void start() {

    ULCLabel label = new ULCLabel("Hello World!");
    TULCButton button = new TULCButton("Click me!");
    button.addActionListener(new IActionListener() {

      public void actionPerformed(ActionEvent arg0) {
        long t0 = System.currentTimeMillis();
        // Do something (useless) ... which takes some time
        double value = System.currentTimeMillis()/115200886343d;
        for (long i=0;i<1000000;i++) {
          value = Math.asin(Math.sin(value));
        }
        long t1 = System.currentTimeMillis();
        System.out.println("Server time (in ms):"+(t1-t0));
      }
      
    });

    ULCFrame frame = new ULCFrame("Hello Sample");
    frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
    ULCBoxPane pane = new ULCBoxPane(1, 1);
    pane.add(label);
    pane.add(button);
    frame.add(pane);
    frame.setVisible(true);
  }

  public static void main(String[] args) {
    DevelopmentRunner.setApplicationClass(TrackingApplication.class);
    DevelopmentRunner.main(args);
  }

  public static class TULCButton extends ULCButton {

    public TULCButton(String label){
      super(label);
    }
    
    protected String typeString() {
      return TUIButton.class.getName();
    }      
  }

  public static class TUIButton extends UIButton {

    public void actionPerformed(java.awt.event.ActionEvent arg0) {
      long t0 = System.currentTimeMillis();
      super.actionPerformed(arg0);
      long t1 = System.currentTimeMillis();
      System.out.println("Round trip:"+(t1-t0)+" ms ("+arg0+")");
    }        
  }    
}



_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to