The timer-keep-alive Element"

From Documentation
m (correct highlight (via JWB))
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
 
  [Default: false]
 
  [Default: false]
  
It specifies whether to keep the session alive, when receiving the <tt>onTimer</tt> event.
+
It specifies whether to keep the session alive, when receiving the <code>onTimer</code> event.
  
 
A session is considered as timeout (and then invalidated), if it doesn't receive any client requests in the specified timeout interval (see [[ZK Configuration Reference/zk.xml/The session-config Element/The session-timeout Element|the session-timeout element]] for more information).
 
A session is considered as timeout (and then invalidated), if it doesn't receive any client requests in the specified timeout interval (see [[ZK Configuration Reference/zk.xml/The session-config Element/The session-timeout Element|the session-timeout element]] for more information).
  
By setting this option to true, the <tt>onTimer</tt> event, just like any other events, will reset the session timeout counter (and then keep the session alive until timeout). Notice that, if this option is true and the timer is shorter than the session timeout, the session won't be expired.
+
By setting this option to true, the <code>onTimer</code> event, just like any other events, will reset the session timeout counter (and then keep the session alive until timeout). Notice that, if this option is true and the timer is shorter than the session timeout, the session won't be expired.
  
By default, if this option is false, it means the <tt>onTimer</tt> event is ignored when handling the session timeout. In other words, the session will expire if no other event is received before timeout.
+
By default, if this option is false, it means the <code>onTimer</code> event is ignored when handling the session timeout. In other words, the session will expire if no other event is received before timeout.
  
Notice that ZK will optimize the <tt>onTime</tt> event such that it won't be sent if there is no event listener at the server (for better performance). In other words, the following statement won't fire any <tt>onTimer</tt> event to the server.
+
Notice that ZK will optimize the <code>onTime</code> event such that it won't be sent if there is no event listener at the server (for better performance). In other words, the following statement won't fire any <code>onTimer</code> event to the server.
  
 
<source lang="xml">
 
<source lang="xml">
Line 26: Line 26:
 
</source>
 
</source>
  
== Websockets (since 8.5.0) ==
+
== Websockets ==
 +
{{versionSince |  8.5.0}}
 +
 
 
When enabled, Websockets use a persistent connection, which does not extend the HTTPSession when individual messages are sent.
 
When enabled, Websockets use a persistent connection, which does not extend the HTTPSession when individual messages are sent.
To keep the session alive using a <code><timer></code>-element you can force the request to use HTTP/AJAX with the following additional event options. This will keep the HTTPSession alive
+
To keep the session alive using a <code><timer></code>-element you can force the request to use HTTP/AJAX with the following additional event options. This will keep the HTTP session alive
  
 
<source lang="xml">
 
<source lang="xml">
Line 36: Line 38:
 
</source>
 
</source>
  
* w:onTimer - client side on timer event (to customize event options)
+
* w:onTimer - client-side on timer event (to customize event options)
* forceAjax - (force an HTTP request instead of a websocket message)
+
* forceAjax - (force an HTTP request instead of a WebSocket message)
* toServer - send the event to the server (avoids having to add a server side event listener)
+
* toServer - send the event to the server (avoids having to add a server-side event listener)
  
 
== 5.0.6 and Earlier ==
 
== 5.0.6 and Earlier ==

Latest revision as of 10:34, 19 January 2022


The timer-keep-alive Element


Syntax:

<timer-keep-alive>true|false</timer-keep-alive>
[Default: false]

It specifies whether to keep the session alive, when receiving the onTimer event.

A session is considered as timeout (and then invalidated), if it doesn't receive any client requests in the specified timeout interval (see the session-timeout element for more information).

By setting this option to true, the onTimer event, just like any other events, will reset the session timeout counter (and then keep the session alive until timeout). Notice that, if this option is true and the timer is shorter than the session timeout, the session won't be expired.

By default, if this option is false, it means the onTimer event is ignored when handling the session timeout. In other words, the session will expire if no other event is received before timeout.

Notice that ZK will optimize the onTime event such that it won't be sent if there is no event listener at the server (for better performance). In other words, the following statement won't fire any onTimer event to the server.

<timer repeats="true" running="true" delay="1000"/>

Thus, if you have to add an event listener to enable the timer-keep-alive feature, such as

<timer repeats="true" running="true" delay="1000" onTimer=""/>

Websockets

Since 8.5.0

When enabled, Websockets use a persistent connection, which does not extend the HTTPSession when individual messages are sent. To keep the session alive using a <timer>-element you can force the request to use HTTP/AJAX with the following additional event options. This will keep the HTTP session alive

<timer repeats="true" running="true" delay="10000"
       xmlns:w="client"
       w:onTimer="event.opts.toServer=true; event.opts.forceAjax=true;" />
  • w:onTimer - client-side on timer event (to customize event options)
  • forceAjax - (force an HTTP request instead of a WebSocket message)
  • toServer - send the event to the server (avoids having to add a server-side event listener)

5.0.6 and Earlier

For 5.0.6 and earlier, the above statement will cause the interpreter to start and thus cause some performance penalty. However, for better performance, you could use a composer as follows.

<timer repeats="true" running="true" delay="1000" apply="foo.DoesNothingTimer"/>

And, then implement foo.DoesNothingTimer as follows.

public class DoesNothingTimer implements Composer {
    public void doAfterCompose(Component comp) throws Exception {
        comp.addEventListener("onTimer", new SerializableEventListener() {
            public void onEvent(Event event) throws Exception {
                //does nothing
            }
        });
    }
}

Version History

Last Update : 2022/01/19


Version Date Content
     



Last Update : 2022/01/19

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.