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 long
The creation time in millisecondsprotected Long
The expiration time in milliseconds.protected String
The session id.protected boolean
Flag indicating whether session was invalidated.protected long
The last accessed time in milliseconds.protected Long
The maximum inactive interval in milliseconds.protected final String
The 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
ConstructorsModifierConstructorDescriptionprotected
AbstractSession
(SessionIdGenerator<A, B> sessionIdGenerator, SessionStore<A, B> sessionStore, Long maxInactiveInterval, Long expirationTime) Creates a new session.protected
AbstractSession
(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 TypeMethodDescriptionlong
Returns the session creation time in milliseconds.long
Returns the time in milliseconds at which the session is set to expire.getId()
Returns the session unique identifier.long
Returns the session last accessed time in milliseconds.Returns the maximum inactive interval in milliseconds.Returns the original session identifier.Invalidates the session.boolean
Determines whether the session has expired.boolean
Determines whether the session has been invalidated.refreshId
(boolean force) Refreshes the session id.save()
Saves the session.void
setExpirationTime
(long expirationTime) Sets the session expiration time in milliseconds.protected void
setLastAccessedTime
(long lastAccessedTime) Sets the last accessed time.void
setMaxInactiveInterval
(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: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 interfaceSession<A>
- Returns:
- the original session id for an existing session or
null
if the session is new
-
getId
Description copied from interface:Session
Returns the session unique identifier.
-
getCreationTime
public long getCreationTime()Description copied from interface:Session
Returns the session creation time in milliseconds.
- Specified by:
getCreationTime
in interfaceSession<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 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:Session
Sets the maximum inactive interval in milliseconds.
The maximum inactive interval replaces the expiration time if any was set.
- Specified by:
setMaxInactiveInterval
in interfaceSession<A>
- Parameters:
maxInactiveInterval
- a maximum inactive interval in milliseconds
-
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 interfaceSession<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 interfaceSession<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 interfaceSession<A>
- Returns:
- the session expiration time
-
isExpired
public boolean isExpired()Description copied from interface:Session
Determines whether the session has expired.
-
isInvalidated
public boolean isInvalidated()Description copied from interface:Session
Determines whether the session has been invalidated.
- Specified by:
isInvalidated
in interfaceSession<A>
- Returns:
- true if the session has been invalidated, false otherwise
-
refreshId
Description copied from interface:Session
Refreshes the session id.
-
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. -
invalidate
Description copied from interface:Session
Invalidates the session.
- Specified by:
invalidate
in interfaceSession<A>
- Returns:
- a mono which completes when the session is invalidated
-