Class AbstractSession<A,B extends Session<A>>
- Type Parameters:
A- the session data typeB- the session type
- All Implemented Interfaces:
Session<A>
- Direct Known Subclasses:
AbstractJWTSession
Base Session implementation class.
- Since:
- 1.13
- Author:
- Jeremy Kuhn
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final longThe creation time in millisecondsprotected LongThe expiration time in milliseconds.protected StringThe session id.protected booleanFlag indicating whether session was invalidated.protected longThe last accessed time in milliseconds.protected LongThe maximum inactive interval in milliseconds.protected final StringThe original id.protected final SessionIdGenerator<A, B> The session id generator.protected final SessionStore<A, B> The session store.Fields inherited from interface io.inverno.mod.session.Session
DEFAULT_MAX_INACTIVE_INTERVAL -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSession(SessionIdGenerator<A, B> sessionIdGenerator, SessionStore<A, B> sessionStore, Long maxInactiveInterval, Long expirationTime) Creates a new session.protectedAbstractSession(SessionIdGenerator<A, B> sessionIdGenerator, SessionStore<A, B> sessionStore, String id, long creationTime, long lastAccessedTime, Long maxInactiveInterval, Long expirationTime, boolean isNew) Creates an existing session. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the session creation time in milliseconds.longReturns the time in milliseconds at which the session is set to expire.getId()Returns the session unique identifier.longReturns the session last accessed time in milliseconds.Returns the maximum inactive interval in milliseconds.Returns the original session identifier.Invalidates the session.booleanDetermines whether the session has expired.booleanDetermines whether the session has been invalidated.refreshId(boolean force) Refreshes the session id.save()Saves the session.voidsetExpirationTime(long expirationTime) Sets the session expiration time in milliseconds.protected voidsetLastAccessedTime(long lastAccessedTime) Sets the last accessed time.voidsetMaxInactiveInterval(long maxInactiveInterval) Sets the maximum inactive interval in milliseconds.
-
Field Details
-
sessionIdGenerator
The session id generator. -
sessionStore
The session store. -
originalId
The original id. -
creationTime
protected final long creationTimeThe creation time in milliseconds -
id
The session id. -
lastAccessedTime
protected long lastAccessedTimeThe last accessed time in milliseconds. -
maxInactiveInterval
The maximum inactive interval in milliseconds. -
expirationTime
The expiration time in milliseconds. -
invalidated
protected boolean invalidatedFlag indicating whether session was invalidated.
-
-
Constructor Details
-
AbstractSession
protected AbstractSession(SessionIdGenerator<A, B> sessionIdGenerator, SessionStore<A, throws IllegalArgumentExceptionB> sessionStore, Long maxInactiveInterval, Long expirationTime) Creates a new session.
- Parameters:
sessionIdGenerator- the session id generatorsessionStore- the session storemaxInactiveInterval- the maximum inactive interval in millisecondsexpirationTime- 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, throws IllegalArgumentExceptionB> sessionStore, String id, long creationTime, long lastAccessedTime, Long maxInactiveInterval, Long expirationTime, boolean isNew) Creates an existing session.
- Parameters:
sessionIdGenerator- the session id generatorsessionStore- the session storeid- the original session idcreationTime- the creation time in millisecondslastAccessedTime- the last accessed time in millisecondsmaxInactiveInterval- the maximum inactive interval in millisecondsexpirationTime- the expiration time in millisecondsisNew- 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
Description copied from interface:SessionReturns the original session identifier.
The original session id is the value that was used to resolve an existing session or
nullfor a new session.- Specified by:
getOriginalIdin interfaceSession<A>- Returns:
- the original session id for an existing session or
nullif the session is new
-
getId
Description copied from interface:SessionReturns the session unique identifier.
-
getCreationTime
public long getCreationTime()Description copied from interface:SessionReturns the session creation time in milliseconds.
- Specified by:
getCreationTimein interfaceSession<A>- Returns:
- the session creation time
-
getLastAccessedTime
public long getLastAccessedTime()Description copied from interface:SessionReturns 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:
getLastAccessedTimein interfaceSession<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:SessionSets the maximum inactive interval in milliseconds.
The maximum inactive interval replaces the expiration time if any was set.
- Specified by:
setMaxInactiveIntervalin interfaceSession<A>- Parameters:
maxInactiveInterval- a maximum inactive interval in milliseconds
-
getMaxInactiveInterval
Description copied from interface:SessionReturns the maximum inactive interval in milliseconds.
The maximum inactive interval is
nullwhen a specific expiration time was set.- Specified by:
getMaxInactiveIntervalin interfaceSession<A>- Returns:
- the maximum inactive interval in milliseconds or
nullif the session is set to expire at a specific time
-
setExpirationTime
public void setExpirationTime(long expirationTime) Description copied from interface:SessionSets the session expiration time in milliseconds.
The expiration time replaces the maximum inactive interval if any was set.
- Specified by:
setExpirationTimein interfaceSession<A>- Parameters:
expirationTime- an expiration time in milliseconds
-
getExpirationTime
public long getExpirationTime()Description copied from interface:SessionReturns 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:
getExpirationTimein interfaceSession<A>- Returns:
- the session expiration time
-
isExpired
public boolean isExpired()Description copied from interface:SessionDetermines whether the session has expired.
-
isInvalidated
public boolean isInvalidated()Description copied from interface:SessionDetermines whether the session has been invalidated.
- Specified by:
isInvalidatedin interfaceSession<A>- Returns:
- true if the session has been invalidated, false otherwise
-
refreshId
Description copied from interface:SessionRefreshes the session id.
-
save
Description copied from interface:SessionSaves 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. -
invalidate
Description copied from interface:SessionInvalidates the session.
- Specified by:
invalidatein interfaceSession<A>- Returns:
- a mono which completes when the session is invalidated
-