aboutsummaryrefslogtreecommitdiffstats
path: root/documentation/articles/CleaningUpResourcesInAUI.asciidoc
diff options
context:
space:
mode:
authorHenri Muurimaa <henri.muurimaa@gmail.com>2017-09-11 11:57:15 +0300
committerHenri Sara <henri.sara@gmail.com>2017-09-11 11:57:15 +0300
commitfb207248d5567a2661d5729d5149c7c8920a2efa (patch)
tree197085fb374e85ccc7eeb7d7998a7bcba9b09c43 /documentation/articles/CleaningUpResourcesInAUI.asciidoc
parente83f012cf5f1388dcab9be427575a655769f75e9 (diff)
downloadvaadin-framework-fb207248d5567a2661d5729d5149c7c8920a2efa.tar.gz
vaadin-framework-fb207248d5567a2661d5729d5149c7c8920a2efa.zip
Migrate wiki articles to Vaadin documentation (#9912)
* Vaadin Tutorial For Swing Developers * Setting And Reading Session Attributes * Enabling Server Push * Cleaning Up Resources In A UI * Sending Email From Java Applications * Using Parameters With Views * Optimizing Sluggish UI * Configuring Push For Your Enviroment * Setting And Reading Cookies * Using Polling * Creating An Application That Preserves State On Refresh * Finding The Current UI And Page And Vaadin Session * Sending Events From The Client To The Server Using RPC * Handling Logout * Remember To Set The Locale * Scalable Web Applications * MVC Basics In ITMill Toolkit * Access Control For Views * Customizing The Startup Page In An Application
Diffstat (limited to 'documentation/articles/CleaningUpResourcesInAUI.asciidoc')
-rw-r--r--documentation/articles/CleaningUpResourcesInAUI.asciidoc104
1 files changed, 104 insertions, 0 deletions
diff --git a/documentation/articles/CleaningUpResourcesInAUI.asciidoc b/documentation/articles/CleaningUpResourcesInAUI.asciidoc
new file mode 100644
index 0000000000..d26183c36f
--- /dev/null
+++ b/documentation/articles/CleaningUpResourcesInAUI.asciidoc
@@ -0,0 +1,104 @@
+[[cleaning-up-resources-in-a-ui]]
+Cleaning up resources in a UI
+-----------------------------
+
+Vaadin UIs that are open on the client side send a regular heartbeat
+to the server to indicate they are still alive, even though there is no
+ongoing user interaction. When the server does not receive a valid
+heartbeat for a given UI, it will eventually remove that UI from the
+session.
+
+By default, heartbeats are sent every five minutes, and the server
+closes an UI after three missed heartbeats. The heartbeat interval can
+be customized by providing an init parameter named `heartbeatInterval`
+in your web.xml, setting its value to the desired interval in seconds:
+
+[source,xml]
+....
+<web-app>
+ <context-param>
+ <param-name>heartbeatInterval</param-name>
+ <param-value>120</param-value>
+ </context-param>
+
+ <!-- Or per-servlet: -->
+ <servlet>
+ <!-- ... -->
+ <init-param>
+ <param-name>heartbeatInterval</param-name>
+ <param-value>120</param-value>
+ </init-param>
+ </servlet>
+</web-app>
+....
+
+To do custom cleanup in your UIs, `DetachListener`s can be registered:
+
+[source,java]
+....
+public class MyUI extends UI {
+ @Override
+ protected void init(VaadinRequest request) {
+ addDetachListener(new DetachListener() {
+
+ @Override
+ public void detach(DetachEvent event) {
+ releaseSomeResources();
+ }
+ });
+ }
+
+ private void releaseSomeResources() {
+ // ...
+ }
+....
+
+Of course, your UI could also implement `DetachListener` itself:
+
+[source,java]
+....
+public class MyUI extends UI implements DetachListener {
+ protected void init(VaadinRequest request) {
+ addDetachListener(this);
+ }
+
+ @Override
+ public void detach(DetachEvent event) {
+ // do cleanup
+ }
+}
+....
+
+If you'd like to share a listener instance between multiple UIs, the
+current UI can be queried:
+
+[source,java]
+....
+public void detach(DetachEvent event) {
+ // do cleanup
+ event.getConnector().getUI();
+
+ // or equivalent:
+ UI.getCurrent();
+}
+....
+
+Because heartbeat requests are just like any other request from the
+servlet container's viewpoint, each heartbeat extends the lifetime of
+the underlying HttpSession. This means that as long as there is an open
+UI, the session never expires even though there is no user interaction.
+This is desirable in some situations, but in others it may be not.
+
+You can control this behavior by setting an init parameter named
+`closeIdleSessions` to `true`. When it is set to true (the default is
+`false`), the session will be closed if no UI is active. Before the
+session is closed, the detach methods will be called, and cleanup is
+performed.
+
+[source,xml]
+....
+<context-param> <!-- or init-param -->
+ <param-name>closeIdleSessions</param-name>
+ <param-value>true</param-value>
+</context-param>
+....