All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.spring.common.session.SessionUpdateRemappingFunction Maven / Gradle / Ivy

The newest version!
package org.infinispan.spring.common.session;

import java.io.Serializable;
import java.time.Duration;
import java.time.Instant;
import java.util.Map;
import java.util.function.BiFunction;

import org.springframework.session.MapSession;

public class SessionUpdateRemappingFunction implements BiFunction, Serializable {

   private static final long serialVersionUID = 1L;

   private Instant lastAccessedTime;
   private Duration maxInactiveInterval;
   private Map delta;

   @Override
   public MapSession apply(final String key, final MapSession value) {
      if (value == null) {
         return null;
      }
      if (this.lastAccessedTime != null) {
         value.setLastAccessedTime(this.lastAccessedTime);
      }
      if (this.maxInactiveInterval != null) {
         value.setMaxInactiveInterval(this.maxInactiveInterval);
      }
      if (this.delta != null) {
         for (final Map.Entry attribute : this.delta.entrySet()) {
            if (attribute.getValue() != null) {
               value.setAttribute(attribute.getKey(), attribute.getValue());
            } else {
               value.removeAttribute(attribute.getKey());
            }
         }
      }
      return value;
   }

   Instant getLastAccessedTime() {
      return lastAccessedTime;
   }

   void setLastAccessedTime(final Instant lastAccessedTime) {
      this.lastAccessedTime = lastAccessedTime;
   }

   Duration getMaxInactiveInterval() {
      return maxInactiveInterval;
   }

   void setMaxInactiveInterval(final Duration maxInactiveInterval) {
      this.maxInactiveInterval = maxInactiveInterval;
   }

   Map getDelta() {
      return delta;
   }

   void setDelta(final Map delta) {
      this.delta = delta;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy