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.

PushRemoveConnectors.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.vaadin.tests.push;
  2. import java.util.concurrent.Executors;
  3. import java.util.concurrent.ScheduledExecutorService;
  4. import java.util.concurrent.ScheduledFuture;
  5. import java.util.concurrent.TimeUnit;
  6. import org.apache.commons.lang.SerializationUtils;
  7. import com.vaadin.annotations.Push;
  8. import com.vaadin.server.VaadinRequest;
  9. import com.vaadin.tests.components.AbstractTestUIWithLog;
  10. import com.vaadin.ui.AbstractOrderedLayout;
  11. import com.vaadin.ui.Button;
  12. import com.vaadin.ui.Button.ClickEvent;
  13. import com.vaadin.ui.Button.ClickListener;
  14. import com.vaadin.ui.CheckBox;
  15. import com.vaadin.ui.HorizontalLayout;
  16. import com.vaadin.ui.Label;
  17. @Push
  18. public class PushRemoveConnectors extends AbstractTestUIWithLog {
  19. private transient final ScheduledExecutorService threadPool = Executors
  20. .newScheduledThreadPool(5);
  21. static final String START = "start";
  22. static final String STOP = "stop";
  23. private AbstractOrderedLayout verticalLayout;
  24. private transient ScheduledFuture<?> task = null;
  25. @Override
  26. protected void setup(VaadinRequest request) {
  27. final CheckBox pollingEnabled = new CheckBox("Polling enabled");
  28. pollingEnabled.addValueChangeListener(event -> setPollInterval(
  29. pollingEnabled.getValue() ? 1000 : -1));
  30. Button start = new Button("start");
  31. start.setId(START);
  32. start.addClickListener(new ClickListener() {
  33. @Override
  34. public void buttonClick(ClickEvent event) {
  35. task = threadPool.scheduleAtFixedRate(new Runnable() {
  36. @Override
  37. public void run() {
  38. access(new Runnable() {
  39. @Override
  40. public void run() {
  41. populate();
  42. log("Serialized session size: "
  43. + getSessionSize());
  44. }
  45. });
  46. }
  47. }, 1, 1, TimeUnit.SECONDS);
  48. }
  49. });
  50. Button stop = new Button("stop");
  51. stop.setId(STOP);
  52. stop.addClickListener(new ClickListener() {
  53. @Override
  54. public void buttonClick(ClickEvent event) {
  55. if (task != null) {
  56. task.cancel(true);
  57. task = null;
  58. }
  59. }
  60. });
  61. verticalLayout = new HorizontalLayout();
  62. populate();
  63. addComponents(pollingEnabled, start, stop, verticalLayout);
  64. }
  65. private void populate() {
  66. verticalLayout.removeAllComponents();
  67. for (int i = 0; i < 500; i++) {
  68. Label l = new Label(".");
  69. l.setSizeUndefined();
  70. verticalLayout.addComponent(l);
  71. }
  72. }
  73. private int getSessionSize() {
  74. return SerializationUtils.serialize(getSession()).length;
  75. }
  76. }