Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

PushRemoveConnectors.java 3.1KB

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