public class DefaultWebSession extends Object implements ConfigurableWebSession, Serializable
WebSession.| Constructor and Description |
|---|
DefaultWebSession(String id,
Clock clock)
Constructor to create a new session.
|
DefaultWebSession(String id,
Map<String,Object> attributes,
Clock clock,
Instant creationTime,
Instant lastAccessTime,
Duration maxIdleTime)
Constructor to load existing session.
|
| Modifier and Type | Method and Description |
|---|---|
<T> Optional<T> |
getAttribute(String name)
Return the attribute value if present.
|
Map<String,Object> |
getAttributes()
Return a map that holds session attributes.
|
Instant |
getCreationTime()
Return the time when the session was created.
|
String |
getId()
Return a unique session identifier.
|
Instant |
getLastAccessTime()
Return the last time of session access as a result of user activity such
as an HTTP request.
|
Duration |
getMaxIdleTime()
Return the maximum time after the
lastAccessTime before a session expires. |
protected Supplier<reactor.core.publisher.Mono<Void>> |
getSaveOperation() |
boolean |
isExpired()
Return
true if the session expired after maxIdleTime elapsed. |
boolean |
isStarted()
Whether a session with the client has been started explicitly via
WebSession.start() or implicitly by adding session attributes. |
reactor.core.publisher.Mono<Void> |
save()
Save the session persisting attributes (e.g.
|
void |
setLastAccessTime(Instant lastAccessTime)
Update the last access time for user-related session activity.
|
void |
setMaxIdleTime(Duration maxIdleTime)
By default this is set to 30 minutes.
|
void |
setSaveOperation(Supplier<reactor.core.publisher.Mono<Void>> saveOperation)
Set the operation to invoke when
WebSession.save() is invoked. |
void |
start()
Force the creation of a session causing the session id to be sent when
WebSession.save() is called. |
public DefaultWebSession(String id, Clock clock)
id - the session idclock - for access to current timepublic DefaultWebSession(String id, Map<String,Object> attributes, Clock clock, Instant creationTime, Instant lastAccessTime, Duration maxIdleTime)
id - the session idattributes - the attributes of the sessionclock - for access to current timecreationTime - the creation timelastAccessTime - the last access timemaxIdleTime - the configured maximum session idle timepublic String getId()
WebSessiongetId in interface WebSessionpublic Map<String,Object> getAttributes()
WebSessiongetAttributes in interface WebSessionpublic <T> Optional<T> getAttribute(String name)
WebSessiongetAttribute in interface WebSessionT - the attribute typename - the attribute namepublic Instant getCreationTime()
WebSessiongetCreationTime in interface WebSessionpublic void setLastAccessTime(Instant lastAccessTime)
ConfigurableWebSessionsetLastAccessTime in interface ConfigurableWebSessionlastAccessTime - the time of accesspublic Instant getLastAccessTime()
WebSessionmaxIdleTimeInSeconds this helps to determine when a session is
expired.getLastAccessTime in interface WebSessionpublic void setMaxIdleTime(Duration maxIdleTime)
By default this is set to 30 minutes.
setMaxIdleTime in interface WebSessionmaxIdleTime - the max idle timepublic Duration getMaxIdleTime()
WebSessionlastAccessTime before a session expires. A negative time indicates the
session doesn't expire.getMaxIdleTime in interface WebSessionpublic void setSaveOperation(Supplier<reactor.core.publisher.Mono<Void>> saveOperation)
ConfigurableWebSessionWebSession.save() is invoked.setSaveOperation in interface ConfigurableWebSessionsaveOperation - the save operationpublic void start()
WebSessionWebSession.save() is called.start in interface WebSessionpublic boolean isStarted()
WebSessionWebSession.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 WebSessionpublic reactor.core.publisher.Mono<Void> save()
WebSessionNote 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 WebSessionMono 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()
WebSessiontrue 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