private class InMemoryWebSessionStore.InMemoryWebSession extends java.lang.Object implements WebSession
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.Object> |
attributes |
private java.time.Instant |
creationTime |
private java.util.concurrent.atomic.AtomicReference<java.lang.String> |
id |
private java.time.Instant |
lastAccessTime |
private java.time.Duration |
maxIdleTime |
private java.util.concurrent.atomic.AtomicReference<InMemoryWebSessionStore.State> |
state |
Constructor and Description |
---|
InMemoryWebSession(java.time.Instant creationTime) |
Modifier and Type | Method and Description |
---|---|
<any> |
changeSessionId()
Generate a new id for the session and update the underlying session
storage to reflect the new id.
|
private boolean |
checkExpired(java.time.Instant currentTime) |
java.util.Map<java.lang.String,java.lang.Object> |
getAttributes()
Return a map that holds session attributes.
|
java.time.Instant |
getCreationTime()
Return the time when the session was created.
|
java.lang.String |
getId()
Return a unique session identifier.
|
java.time.Instant |
getLastAccessTime()
Return the last time of session access as a result of user activity such
as an HTTP request.
|
java.time.Duration |
getMaxIdleTime()
Return the maximum time after the
lastAccessTime before a session expires. |
<any> |
invalidate()
Invalidate the current session and clear session storage.
|
boolean |
isExpired()
Return
true if the session expired after maxIdleTime elapsed. |
private boolean |
isExpired(java.time.Instant now) |
boolean |
isStarted()
Whether a session with the client has been started explicitly via
WebSession.start() or implicitly by adding session attributes. |
<any> |
save()
Save the session persisting attributes (e.g.
|
void |
setMaxIdleTime(java.time.Duration maxIdleTime)
Configure the max amount of time that may elapse after the
lastAccessTime before a session is considered
expired. |
void |
start()
Force the creation of a session causing the session id to be sent when
WebSession.save() is called. |
private void |
updateLastAccessTime(java.time.Instant currentTime) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAttribute, getAttributeOrDefault, getRequiredAttribute
private final java.util.concurrent.atomic.AtomicReference<java.lang.String> id
private final java.util.Map<java.lang.String,java.lang.Object> attributes
private final java.time.Instant creationTime
private volatile java.time.Instant lastAccessTime
private volatile java.time.Duration maxIdleTime
private final java.util.concurrent.atomic.AtomicReference<InMemoryWebSessionStore.State> state
public java.lang.String getId()
WebSession
getId
in interface WebSession
public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
WebSession
getAttributes
in interface WebSession
public java.time.Instant getCreationTime()
WebSession
getCreationTime
in interface WebSession
public java.time.Instant getLastAccessTime()
WebSession
maxIdleTimeInSeconds
this helps to determine when a session is
expired
.getLastAccessTime
in interface WebSession
public void setMaxIdleTime(java.time.Duration maxIdleTime)
WebSession
lastAccessTime
before a session is considered
expired. A negative value indicates the session should not expire.setMaxIdleTime
in interface WebSession
public java.time.Duration getMaxIdleTime()
WebSession
lastAccessTime
before a session expires. A negative time indicates the
session doesn't expire.getMaxIdleTime
in interface WebSession
public void start()
WebSession
WebSession.save()
is called.start
in interface WebSession
public boolean isStarted()
WebSession
WebSession.start()
or implicitly by adding session attributes.
If "false" then the session id is not sent to the client and the
WebSession.save()
method is essentially a no-op.isStarted
in interface WebSession
public <any> changeSessionId()
WebSession
WebSession.getId()
reflects the new session id.changeSessionId
in interface WebSession
public <any> invalidate()
WebSession
invalidate
in interface WebSession
public <any> save()
WebSession
Note that a session must be started explicitly via WebSession.start()
or
implicitly by adding attributes or otherwise this method has no effect.
save
in interface WebSession
Mono
to indicate completion with success or error
Typically this method should be automatically invoked just before the response is committed so applications don't have to by default.
public boolean isExpired()
WebSession
true
if the session expired after maxIdleTime
elapsed.
Typically expiration checks should be automatically made when a session
is accessed, a new WebSession
instance created if necessary, at
the start of request processing so that applications don't have to worry
about expired session by default.
isExpired
in interface WebSession
private boolean isExpired(java.time.Instant now)
private boolean checkExpired(java.time.Instant currentTime)
private void updateLastAccessTime(java.time.Instant currentTime)