Package io.micronaut.session
Interface Session
- All Superinterfaces:
io.micronaut.core.convert.ConversionServiceProvider
,io.micronaut.core.convert.value.ConvertibleValues<Object>
,Iterable<Map.Entry<String,
,Object>> io.micronaut.core.convert.value.MutableConvertibleValues<Object>
,io.micronaut.core.value.ValueResolver<CharSequence>
- All Known Implementing Classes:
InMemorySession
An interface representing a user session.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
Fields inherited from interface io.micronaut.core.convert.value.ConvertibleValues
EMPTY
-
Method Summary
Modifier and TypeMethodDescriptionget
(CharSequence attr) Retrieve an attribute for the given name.@NonNull Instant
Returns the time when this session was created.@NonNull String
getId()
A unique identifier for the session.@NonNull Instant
Returns the last time the client sent a request associated with this session as anInstant
.Returns the maximum time interval as aDuration
that sessions will be kept open between client accesses.default boolean
boolean
boolean
isNew()
setLastAccessedTime
(Instant instant) Sets the last accessed time on the session.setMaxInactiveInterval
(Duration duration) Specifies the duration between client requests before session should be invalidated.Methods inherited from interface io.micronaut.core.convert.value.ConvertibleValues
asMap, asMap, asProperties, contains, forEach, getConversionService, getValue, getValueType, isEmpty, iterator, names, subMap, subMap, subMap, values
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface io.micronaut.core.convert.value.MutableConvertibleValues
clear, put, putAll, putAll, remove
Methods inherited from interface io.micronaut.core.value.ValueResolver
get, get, get, get
-
Method Details
-
getCreationTime
Returns the time when this session was created.- Returns:
- An
Instant
instance - Throws:
IllegalStateException
- if this method is called on an invalidated session
-
getId
A unique identifier for the session.- Returns:
- The id of the session
-
getLastAccessedTime
Returns the last time the client sent a request associated with this session as anInstant
.Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time.
- Returns:
- An
Instant
representing the time the session was last accessed - Throws:
IllegalStateException
- if this method is called on an invalidated session
-
setLastAccessedTime
Sets the last accessed time on the session.- Parameters:
instant
- The instant that represents the last accessed time- Returns:
- The session
-
setMaxInactiveInterval
Specifies the duration between client requests before session should be invalidated.- Parameters:
duration
- A duration specifying the max inactive interval- Returns:
- The session
-
getMaxInactiveInterval
Duration getMaxInactiveInterval()Returns the maximum time interval as aDuration
that sessions will be kept open between client accesses. After this interval, the servlet container will invalidate the session. The maximum time interval can be set with thesetMaxInactiveInterval
method.- Returns:
- A duration specifying the time should session should remain open between client requests
- See Also:
-
isNew
boolean isNew()- Returns:
- Is the session a newly created and unsaved session
-
isModified
boolean isModified()- Returns:
- Has the session been modified
-
get
Retrieve an attribute for the given name.- Parameters:
attr
- The attribute name- Returns:
- An
Optional
of the attribute
-
isExpired
default boolean isExpired()- Returns:
- Whether the session has expired
-