Keeping a list of active UIs


i am trying to keep a list of all active UIs in my application.

  • set the heartbeat interval to 5 seconds, so after 15 seconds the ui should get detached

  • create a static List<UI> and adding/removing them in overridden onAttach and onDetach methods
    → adding works fine, but onDetach is only called if its not the last UI of this VaadinSession (open two or more tabs in a browser accessing the application and close one → working, close the last tab → not working)

  • added a SessionDestroyListener to the servlet
    → it never gets called, i guess using @Push sets the session-timeout to -1 and it somehow does not react to closing the browser / tab

My current solution is to manually check the heartbeat timestamp before i need to access my list of UIs if(ui.getInternals().getLastHeartbeatTimestamp() < System.currentTimeMillis() - 15 * 1000) and remove those.

Is there any better way to access all active UIs?