The below should work but it doesn't it only impacts the JSESSIONID (not the hazelcast session)HttpSession session = request.getSession();session.setMaxInactiveInterval(0); // never removedsession.setMaxInactiveInterval(60*60*24); // keep for 1 daysession.setMaxInactiveInterval(60*60); // keep for 1 hoursession.setMaxInactiveInterval(60*5); // keep for 5 minI am having lot of issues getting data expiration or timeouts working in hazelcast tomcat & via hazelcast web clustering. The below should work but it doesn't it only impacts the JSESSIONID (not the hazelcast session).
I have read (via google searches) that the std web.xml <session-config><session-timeout>30</session-timeout></session-config> doesn't work. I read this LINK:
Thanks, so I have to set the TTL in the hazelcast config? The WebFilter doesn't respect the web.xml setting?A: YESSo I thought that this should work: <init-param><param-name>session-ttl-seconds</param-name><param-value>1800</param-value></init-param> looking in the Hazelcast GIT source I do see the following in the file com/hazelcast/web/WebFilter.javaString sessionTTL = getParam("session-ttl-seconds");Yet when putting session-ttl-seconds in either web.xml or even the hazelcast.xml (under the map name or not under the map name) it just doesn't work (I am runnign a client should it go in the hazelcast-client.xml ?)
So there seems only one way (actually two different settings) to get hazelcast web clusting sesssions to "sort of" expire - I show this below.
Notes 1) I didn't alter the default map name which is "my-sessions" I though about nameing it JSESSIONID but didn't 2) I do not add the <distributable /> tag to the web.xml.
Given the map-name which is the name of my-sessions for the distributed map storing your web session objects located in <servlet_name>/MyServletExamplesClient/WEB-INF/web.xml and installed we see the syntax:
<filter>
<filter-name>hazelcast-filter</filter-name>
<filter-class>com.hazelcast.web.WebFilter</filter-class>
<init-param>
<param-name>map-name</param-name>
<param-value>my-sessions</param-value>
</init-param>
*
*
Then by matching the "map name" hazelcast.xml which controls the hazelcast instance (we attache via hazelcast clients ftom tomcat 7 servlets) we can control "almost" the eviction of web sessions. A value of 1800 for max-idle-seconds. Note our distributed hazelcast persistent servlet session stuff is under hazelcast.sessionId (and has nothing to do with JSESSIONID).<map name="my-sessions"> <in-memory-format>BINARY</in-memory-format> <backup-count>1</backup-count> <async-backup-count>0</async-backup-count> <!-- WORKS: if max-idle-seconds > 0 always removed even if the web session is not idle -->
<time-to-live-seconds>0</time-to-live-seconds>
<!-- WORKS: if max-idle-seconds > 0 only get's removed if the web
session goes idle, HOWEVER there seems to be a caveat "idle"
in this case means that a key-value pair is not accessed. When
I test doing a HttpSession session = request.getSession(); and
just getting the session without any session data for some
reason does not keep the session and it's data non-idle -->
<max-idle-seconds>1800</max-idle-seconds>
<!-- FAILS: if session-ttl-seconds > 0 only get's removed if the web session goes idle -->
<!-- <session-ttl-seconds>30</session-ttl-seconds> -->
<eviction-policy>NONE</eviction-policy>
<max-size policy=\"PER_NODE\">0</max-size>
<eviction-percentage>25</eviction-percentage>
<merge-policy>com.hazelcast.map.merge.PassThroughMergePolicy</merge-policy>
</map>
Setting max-idle to 1800 in a 7 node cluster and accessing the session every 10 minutes as follows (via a load balancer):
HttpSession session = request.getSession();
cd = new Date(session.getCreationTime());la = Date(session.getLastAccessedTime();
key = <hazelcast.sessionId>+<dataname>value = datavaluestore (key, value) expire in 30 minutes
private String buildAttributeName(String name) {
return id + HAZELCAST_SESSION_ATTRIBUTE_SEPARATOR + name;
}
my web.xml ( http://pastie.org/9146298 ) look for <param-name>FAILSsession-ttl-seconds</param-name> I added FAILSmy hazelcast-client.xml ( http://pastie.org/9146306 )