Class AbstractSession<A,B extends Session<A>>

java.lang.Object
io.inverno.mod.session.AbstractSession<A,B>
Type Parameters:
A - the session data type
B - the session type
All Implemented Interfaces:
Session<A>
Direct Known Subclasses:
AbstractJWTSession

public abstract class AbstractSession<A,B extends Session<A>> extends Object implements Session<A>

Base Session implementation class.

Since:
1.13
Author:
Jeremy Kuhn
  • Field Details

    • sessionIdGenerator

      protected final SessionIdGenerator<A,B extends Session<A>> sessionIdGenerator
      The session id generator.
    • sessionStore

      protected final SessionStore<A,B extends Session<A>> sessionStore
      The session store.
    • originalId

      protected final String originalId
      The original id.
    • creationTime

      protected final long creationTime
      The creation time in milliseconds
    • id

      protected String id
      The session id.
    • lastAccessedTime

      protected long lastAccessedTime
      The last accessed time in milliseconds.
    • maxInactiveInterval

      protected Long maxInactiveInterval
      The maximum inactive interval in milliseconds.
    • expirationTime

      protected Long expirationTime
      The expiration time in milliseconds.
    • invalidated

      protected boolean invalidated
      Flag indicating whether session was invalidated.
  • Constructor Details

    • AbstractSession

      protected AbstractSession(SessionIdGenerator<A,B> sessionIdGenerator, SessionStore<A,B> sessionStore, Long maxInactiveInterval, Long expirationTime) throws IllegalArgumentException

      Creates a new session.

      Parameters:
      sessionIdGenerator - the session id generator
      sessionStore - the session store
      maxInactiveInterval - the maximum inactive interval in milliseconds
      expirationTime - the expiration time in milliseconds
      Throws:
      IllegalArgumentException - if both maximum inactive interval and expiration time are null
    • AbstractSession

      protected AbstractSession(SessionIdGenerator<A,B> sessionIdGenerator, SessionStore<A,B> sessionStore, String id, long creationTime, long lastAccessedTime, Long maxInactiveInterval, Long expirationTime, boolean isNew) throws IllegalArgumentException

      Creates an existing session.

      Parameters:
      sessionIdGenerator - the session id generator
      sessionStore - the session store
      id - the original session id
      creationTime - the creation time in milliseconds
      lastAccessedTime - the last accessed time in milliseconds
      maxInactiveInterval - the maximum inactive interval in milliseconds
      expirationTime - the expiration time in milliseconds
      isNew - true to set the original id to null, false otherwise
      Throws:
      IllegalArgumentException - if both maximum inactive interval and expiration time are null
  • Method Details

    • getOriginalId

      public String getOriginalId()
      Description copied from interface: Session

      Returns the original session identifier.

      The original session id is the value that was used to resolve an existing session or null for a new session.

      Specified by:
      getOriginalId in interface Session<A>
      Returns:
      the original session id for an existing session or null if the session is new
    • getId

      public String getId()
      Description copied from interface: Session

      Returns the session unique identifier.

      Specified by:
      getId in interface Session<A>
      Returns:
      a unique identifier
    • getCreationTime

      public long getCreationTime()
      Description copied from interface: Session

      Returns the session creation time in milliseconds.

      Specified by:
      getCreationTime in interface Session<A>
      Returns:
      the session creation time
    • getLastAccessedTime

      public long getLastAccessedTime()
      Description copied from interface: Session

      Returns the session last accessed time in milliseconds.

      The last accessed time shall only be updated when saving a session, it is not updated when the session is resolved and as a result the last accessed time effectively corresponds to the last saved time.

      Specified by:
      getLastAccessedTime in interface Session<A>
      Returns:
      the session last accessed time
    • setLastAccessedTime

      protected void setLastAccessedTime(long lastAccessedTime)

      Sets the last accessed time.

      Parameters:
      lastAccessedTime - the last accessed time
    • setMaxInactiveInterval

      public void setMaxInactiveInterval(long maxInactiveInterval)
      Description copied from interface: Session

      Sets the maximum inactive interval in milliseconds.

      The maximum inactive interval replaces the expiration time if any was set.

      Specified by:
      setMaxInactiveInterval in interface Session<A>
      Parameters:
      maxInactiveInterval - a maximum inactive interval in milliseconds
    • getMaxInactiveInterval

      public Long getMaxInactiveInterval()
      Description copied from interface: Session

      Returns the maximum inactive interval in milliseconds.

      The maximum inactive interval is null when a specific expiration time was set.

      Specified by:
      getMaxInactiveInterval in interface Session<A>
      Returns:
      the maximum inactive interval in milliseconds or null if the session is set to expire at a specific time
    • setExpirationTime

      public void setExpirationTime(long expirationTime)
      Description copied from interface: Session

      Sets the session expiration time in milliseconds.

      The expiration time replaces the maximum inactive interval if any was set.

      Specified by:
      setExpirationTime in interface Session<A>
      Parameters:
      expirationTime - an expiration time in milliseconds
    • getExpirationTime

      public long getExpirationTime()
      Description copied from interface: Session

      Returns the time in milliseconds at which the session is set to expire.

      This method calculates and returns the actual time when the session will expire when a maximum inactive interval is set, otherwise it returns the specific expiration time that was set.

      Specified by:
      getExpirationTime in interface Session<A>
      Returns:
      the session expiration time
    • isExpired

      public boolean isExpired()
      Description copied from interface: Session

      Determines whether the session has expired.

      Specified by:
      isExpired in interface Session<A>
      Returns:
      true if the session has expired, false otherwise
    • isInvalidated

      public boolean isInvalidated()
      Description copied from interface: Session

      Determines whether the session has been invalidated.

      Specified by:
      isInvalidated in interface Session<A>
      Returns:
      true if the session has been invalidated, false otherwise
    • refreshId

      public Mono<String> refreshId(boolean force)
      Description copied from interface: Session

      Refreshes the session id.

      Specified by:
      refreshId in interface Session<A>
      Parameters:
      force - true to force refresh, false to only refresh the id if it is stale
      Returns:
      a mono that emits the new session identifier or an empty mono if the identifier did not need to be refreshed
    • save

      public Mono<Void> save()
      Description copied from interface: Session

      Saves the session.

      This basically updates the session last accessed time and any updates to expiration settings.

      Assuming session data were resolved, whether they are saved is implementation specific. This actually widely depends on the session store and the strategy chosen to optimize underlying data store usage. Implementors must however at least guarantee that data that are explicitly set on a session using Session.setData(Object) are saved.

      Specified by:
      save in interface Session<A>
      Returns:
      a mono which completes when the session is saved
    • invalidate

      public Mono<Void> invalidate()
      Description copied from interface: Session

      Invalidates the session.

      Specified by:
      invalidate in interface Session<A>
      Returns:
      a mono which completes when the session is invalidated