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 InstantReturns the time when this session was created.@NonNull StringgetId()A unique identifier for the session.@NonNull InstantReturns the last time the client sent a request associated with this session as anInstant.Returns the maximum time interval as aDurationthat sessions will be kept open between client accesses.default booleanbooleanbooleanisNew()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, valuesMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface io.micronaut.core.convert.value.MutableConvertibleValues
clear, put, putAll, putAll, removeMethods 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
Instantinstance - 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
Instantrepresenting 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 aDurationthat 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 thesetMaxInactiveIntervalmethod.- 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
Optionalof the attribute
-
isExpired
default boolean isExpired()- Returns:
- Whether the session has expired
-