You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RoundTripTesterConnector.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package com.vaadin.tests.widgetset.client;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import com.google.gwt.core.client.Duration;
  5. import com.google.gwt.user.client.ui.HTML;
  6. import com.vaadin.client.ui.AbstractComponentConnector;
  7. import com.vaadin.shared.ui.Connect;
  8. import com.vaadin.tests.widgetset.server.RoundTripTester;
  9. @Connect(RoundTripTester.class)
  10. public class RoundTripTesterConnector extends AbstractComponentConnector {
  11. private double lastPrintedTime = -1;
  12. private int receivedPings = 0;
  13. private List<Double> throughputData = new ArrayList<>();
  14. private int payloadSize = 0;
  15. @Override
  16. protected void init() {
  17. super.init();
  18. registerRpc(RoundTripTesterRpc.class, new RoundTripTesterRpc() {
  19. @Override
  20. public void ping(int nr, String payload) {
  21. getRpcProxy(RoundTripTesterRpc.class).ping(nr + 1, payload);
  22. payloadSize = payload.length();
  23. double now = Duration.currentTimeMillis();
  24. if (lastPrintedTime == -1) {
  25. lastPrintedTime = now;
  26. return;
  27. }
  28. receivedPings++;
  29. if (now - lastPrintedTime > 1000) {
  30. double roundtripsPerSecond = receivedPings
  31. / (now - lastPrintedTime) * 1000;
  32. throughputData.add(roundtripsPerSecond);
  33. getWidget().setText(
  34. roundtripsPerSecond + " roundtrips/second");
  35. lastPrintedTime = now;
  36. receivedPings = 0;
  37. }
  38. }
  39. @Override
  40. public void done() {
  41. String result = "Test results for payload of size "
  42. + payloadSize + ":";
  43. double max = -1;
  44. double min = 1239482038939.0;
  45. double avg = 0;
  46. for (Double throughput : throughputData) {
  47. if (throughput > max) {
  48. max = throughput;
  49. }
  50. if (throughput < min) {
  51. min = throughput;
  52. }
  53. avg += throughput;
  54. }
  55. avg /= throughputData.size();
  56. for (Double throughput : throughputData) {
  57. result += "<br/>" + formatThroughput(throughput);
  58. }
  59. result += "<br/>Max: " + formatThroughput(max);
  60. result += "<br/>Min: " + formatThroughput(min);
  61. result += "<br/>Average: " + formatThroughput(avg);
  62. getWidget().setHTML(result);
  63. getRpcProxy(RoundTripTesterRpc.class).done();
  64. }
  65. private String formatThroughput(double throughput) {
  66. return throughput + " roundtrips / second";
  67. }
  68. });
  69. }
  70. @Override
  71. public HTML getWidget() {
  72. return (HTML) super.getWidget();
  73. }
  74. }