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.

UIPolling.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.vaadin.tests.components.ui;
  2. import com.vaadin.server.VaadinRequest;
  3. import com.vaadin.tests.components.AbstractTestUIWithLog;
  4. import com.vaadin.tests.util.Log;
  5. import com.vaadin.v7.data.util.MethodProperty;
  6. import com.vaadin.v7.ui.TextField;
  7. public class UIPolling extends AbstractTestUIWithLog {
  8. protected static final long SLEEP_TIME = 500;
  9. private class BackgroundLogger extends Thread {
  10. @Override
  11. public void run() {
  12. int i = 0;
  13. while (true) {
  14. i++;
  15. try {
  16. Thread.sleep(SLEEP_TIME);
  17. } catch (InterruptedException e) {
  18. }
  19. final int iteration = i;
  20. access(() -> log
  21. .log((iteration * SLEEP_TIME) + "ms has passed"));
  22. }
  23. }
  24. }
  25. private BackgroundLogger logger = null;
  26. @Override
  27. protected void setup(VaadinRequest request) {
  28. log = new Log(20);
  29. log.setNumberLogRows(true);
  30. TextField pollingInterval = new TextField("Poll interval",
  31. new MethodProperty<Integer>(this, "pollInterval"));
  32. pollingInterval.setImmediate(true);
  33. pollingInterval.setValue("-1");
  34. pollingInterval.addValueChangeListener(event -> {
  35. if (logger != null) {
  36. logger.stop();
  37. logger = null;
  38. }
  39. if (getPollInterval() >= 0) {
  40. logger = new BackgroundLogger();
  41. logger.start();
  42. }
  43. });
  44. addComponent(pollingInterval);
  45. }
  46. @Override
  47. protected String getTestDescription() {
  48. return "Tests the polling feature of UI. Set the polling interval using the text field. Enabling polling will at the same time start a background thread which logs every 500ms";
  49. }
  50. @Override
  51. protected Integer getTicketNumber() {
  52. return 11495;
  53. }
  54. }