From 27283e29d5c6c5620ee85b9de266cdcb945020ac Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Fri, 1 Dec 2017 08:37:03 +0100 Subject: [PATCH] Optimize `HazelcastSessionRepository.SessionUpdateEntryProcessor` Closes gh-947 --- .../hazelcast/HazelcastSessionRepository.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastSessionRepository.java b/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastSessionRepository.java index 78b418c6..195372c1 100644 --- a/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastSessionRepository.java +++ b/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastSessionRepository.java @@ -233,8 +233,9 @@ public class HazelcastSessionRepository implements session.getMaxInactiveInterval().getSeconds(), TimeUnit.SECONDS); } else if (session.changed) { - this.sessions.executeOnKey(session.getId(), new SessionUpdateEntryProcessor( - session.getDelegate(), session.delta)); + this.sessions.executeOnKey(session.getId(), + new SessionUpdateEntryProcessor(session.getLastAccessedTime(), + session.getMaxInactiveInterval(), session.delta)); } session.clearFlags(); } @@ -435,20 +436,24 @@ public class HazelcastSessionRepository implements private static final class SessionUpdateEntryProcessor extends AbstractEntryProcessor { - private final MapSession session; + private final Instant lastAccessedTime; + + private final Duration maxInactiveInterval; private final Map delta; - SessionUpdateEntryProcessor(MapSession session, Map delta) { - this.session = session; + SessionUpdateEntryProcessor(Instant lastAccessedTime, + Duration maxInactiveInterval, Map delta) { + this.lastAccessedTime = lastAccessedTime; + this.maxInactiveInterval = maxInactiveInterval; this.delta = delta; } @Override public Object process(Map.Entry entry) { MapSession value = entry.getValue(); - value.setLastAccessedTime(this.session.getLastAccessedTime()); - value.setMaxInactiveInterval(this.session.getMaxInactiveInterval()); + value.setLastAccessedTime(this.lastAccessedTime); + value.setMaxInactiveInterval(this.maxInactiveInterval); for (final Map.Entry attribute : this.delta.entrySet()) { if (attribute.getValue() != null) { value.setAttribute(attribute.getKey(), attribute.getValue());