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

public interface Session extends io.micronaut.core.convert.value.MutableConvertibleValues<Object>

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 Type
    Method
    Description
    default Optional<Object>
    Retrieve an attribute for the given name.
    @NonNull Instant
    Returns the time when this session was created.
    @NonNull String
    A unique identifier for the session.
    @NonNull Instant
    Returns the last time the client sent a request associated with this session as an Instant.
    Returns the maximum time interval as a Duration that sessions will be kept open between client accesses.
    default boolean
     
    boolean
     
    boolean
     
    Sets the last accessed time on the session.
    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

      @NonNull @NonNull Instant 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

      @NonNull @NonNull String getId()
      A unique identifier for the session.
      Returns:
      The id of the session
    • getLastAccessedTime

      @NonNull @NonNull Instant getLastAccessedTime()
      Returns the last time the client sent a request associated with this session as an Instant.

      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

      Session setLastAccessedTime(Instant instant)
      Sets the last accessed time on the session.
      Parameters:
      instant - The instant that represents the last accessed time
      Returns:
      The session
    • setMaxInactiveInterval

      Session setMaxInactiveInterval(Duration duration)
      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 a Duration 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 the setMaxInactiveInterval 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

      default Optional<Object> get(CharSequence attr)
      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