public interface Session
This object can be accessed via the context registry.
Access to the actual session data is provided by getData()
method this object.
The persistence mechanism used is determined by the implementation of SessionStore
available.
SessionModule
Modifier and Type | Method and Description |
---|---|
default Operation |
clear()
A convenience shorthand for
SessionData.clear() . |
default <T> Promise<java.util.Optional<T>> |
get(java.lang.Class<T> type)
A convenience shorthand for
SessionData.get(Class) . |
default <T> Promise<java.util.Optional<T>> |
get(java.lang.Class<T> type,
SessionSerializer serializer)
A convenience shorthand for
SessionData.get(Class, SessionSerializer) . |
default <T> Promise<java.util.Optional<T>> |
get(SessionKey<T> key)
A convenience shorthand for
SessionData.get(SessionKey) . |
default <T> Promise<java.util.Optional<T>> |
get(SessionKey<T> key,
SessionSerializer serializer)
A convenience shorthand for
SessionData.get(SessionKey, SessionSerializer) . |
default Promise<java.util.Optional<?>> |
get(java.lang.String name)
A convenience shorthand for
SessionData.get(String) . |
default Promise<java.util.Optional<?>> |
get(java.lang.String name,
SessionSerializer serializer)
A convenience shorthand for
SessionData.get(String, SessionSerializer) . |
Promise<SessionData> |
getData()
The session data.
|
SessionSerializer |
getDefaultSerializer()
The serializer that is used when a serializer is not explicitly given.
|
java.lang.String |
getId()
The unique ID for this session.
|
JavaSessionSerializer |
getJavaSerializer()
The value serializer that is guaranteed to be able to serialize/deserialize any Java object that implements
Serializable . |
default Promise<java.util.Set<SessionKey<?>>> |
getKeys()
A convenience shorthand for
SessionData.getKeys() . |
boolean |
isDirty()
Whether or not any changes have been made to the session data since it was accessed.
|
default Operation |
remove(java.lang.Class<?> type)
A convenience shorthand for
SessionData.remove(Class) . |
default Operation |
remove(SessionKey<?> key)
A convenience shorthand for
SessionData.remove(SessionKey) . |
default Operation |
remove(java.lang.String name)
A convenience shorthand for
SessionData.remove(String) . |
default <T> Promise<T> |
require(java.lang.Class<T> type)
A convenience shorthand for
SessionData.require(Class) . |
default <T> Promise<T> |
require(java.lang.Class<T> type,
SessionSerializer serializer)
A convenience shorthand for
SessionData.require(Class, SessionSerializer) . |
default <T> Promise<T> |
require(SessionKey<T> key)
A convenience shorthand for
SessionData.require(SessionKey) . |
default <T> Promise<T> |
require(SessionKey<T> key,
SessionSerializer serializer)
A convenience shorthand for
SessionData.require(SessionKey, SessionSerializer) . |
default Promise<?> |
require(java.lang.String name)
A convenience shorthand for
SessionData.require(String) . |
default Promise<?> |
require(java.lang.String name,
SessionSerializer serializer)
A convenience shorthand for
SessionData.require(String, SessionSerializer) . |
Operation |
save()
Persists the session data.
|
default <T> Operation |
set(java.lang.Class<T> type,
T value)
A convenience shorthand for
SessionData.set(Class, Object) . |
default <T> Operation |
set(java.lang.Class<T> type,
T value,
SessionSerializer serializer)
A convenience shorthand for
SessionData.set(Class, Object, SessionSerializer) . |
default <T> Operation |
set(SessionKey<T> key,
T value)
A convenience shorthand for
SessionData.set(SessionKey, Object) . |
default <T> Operation |
set(SessionKey<T> key,
T value,
SessionSerializer serializer)
A convenience shorthand for
SessionData.set(SessionKey, Object, SessionSerializer) . |
default <T> Operation |
set(java.lang.String name,
T value)
A convenience shorthand for
SessionData.set(String, Object) . |
default <T> Operation |
set(java.lang.String name,
T value,
SessionSerializer serializer)
A convenience shorthand for
SessionData.set(String, Object, SessionSerializer) . |
default <T> Operation |
set(T value)
A convenience shorthand for
SessionData.set(Object) . |
default <T> Operation |
set(T value,
SessionSerializer serializer)
A convenience shorthand for
SessionData.set(Object, SessionSerializer) . |
Operation |
terminate()
Terminates the session and session id.
|
java.lang.String getId()
Call this method will provision a new ID if necessary.
Provisioning and tracking of the ID is provided by the bound SessionId
implementation.
Promise<SessionData> getData()
The data is available via a promise to support backing SessionStore
implementations that load the data asynchronously.
default Promise<java.util.Set<SessionKey<?>>> getKeys()
SessionData.getKeys()
.default <T> Promise<java.util.Optional<T>> get(SessionKey<T> key)
SessionData.get(SessionKey)
.T
- the type of objectkey
- the keyrequire(SessionKey)
default <T> Promise<java.util.Optional<T>> get(SessionKey<T> key, SessionSerializer serializer)
SessionData.get(SessionKey, SessionSerializer)
.T
- the type of objectkey
- the keyserializer
- the serializerrequire(SessionKey, SessionSerializer)
default Promise<java.util.Optional<?>> get(java.lang.String name)
SessionData.get(String)
.name
- the object namerequire(String)
default Promise<java.util.Optional<?>> get(java.lang.String name, SessionSerializer serializer)
SessionData.get(String, SessionSerializer)
.name
- the object nameserializer
- the serializerrequire(String, SessionSerializer)
default <T> Promise<java.util.Optional<T>> get(java.lang.Class<T> type)
SessionData.get(Class)
.T
- the typetype
- the typerequire(Class)
default <T> Promise<java.util.Optional<T>> get(java.lang.Class<T> type, SessionSerializer serializer)
SessionData.get(Class, SessionSerializer)
.T
- the typetype
- the typeserializer
- the serializerrequire(Class, SessionSerializer)
default <T> Promise<T> require(SessionKey<T> key)
SessionData.require(SessionKey)
.T
- the typekey
- the object keydefault <T> Promise<T> require(SessionKey<T> key, SessionSerializer serializer)
SessionData.require(SessionKey, SessionSerializer)
.T
- the typekey
- the object keyserializer
- the serializerdefault <T> Promise<T> require(java.lang.Class<T> type)
SessionData.require(Class)
.T
- the typetype
- the typedefault <T> Promise<T> require(java.lang.Class<T> type, SessionSerializer serializer)
SessionData.require(Class, SessionSerializer)
.T
- the typetype
- the typeserializer
- the serializerdefault Promise<?> require(java.lang.String name)
SessionData.require(String)
.name
- the object namedefault Promise<?> require(java.lang.String name, SessionSerializer serializer)
SessionData.require(String, SessionSerializer)
.name
- the object nameserializer
- the serializerdefault <T> Operation set(SessionKey<T> key, T value)
SessionData.set(SessionKey, Object)
.T
- the typekey
- the keyvalue
- the valuedefault <T> Operation set(SessionKey<T> key, T value, SessionSerializer serializer)
SessionData.set(SessionKey, Object, SessionSerializer)
.T
- the typekey
- the keyvalue
- the valueserializer
- the serializerdefault <T> Operation set(java.lang.Class<T> type, T value)
SessionData.set(Class, Object)
.T
- the typetype
- the typevalue
- the valuedefault <T> Operation set(java.lang.Class<T> type, T value, SessionSerializer serializer)
SessionData.set(Class, Object, SessionSerializer)
.T
- the typetype
- the typevalue
- the valueserializer
- the serializerdefault <T> Operation set(java.lang.String name, T value)
SessionData.set(String, Object)
.T
- the typename
- the namevalue
- the valuedefault <T> Operation set(java.lang.String name, T value, SessionSerializer serializer)
SessionData.set(String, Object, SessionSerializer)
.T
- the typename
- the namevalue
- the valueserializer
- the serializerdefault <T> Operation set(T value)
SessionData.set(Object)
.T
- the typevalue
- the valuedefault <T> Operation set(T value, SessionSerializer serializer)
SessionData.set(Object, SessionSerializer)
.T
- the typevalue
- the valueserializer
- the serializerdefault Operation remove(SessionKey<?> key)
SessionData.remove(SessionKey)
.key
- the keydefault Operation remove(java.lang.Class<?> type)
SessionData.remove(Class)
.type
- the typedefault Operation remove(java.lang.String name)
SessionData.remove(String)
.name
- the namedefault Operation clear()
SessionData.clear()
.boolean isDirty()
Operation save()
It is generally not necessary to call this method explicitly.
The SessionModule
installs a response finalizer
that will
call this method if the session is dirty
.
This method is effectively a noop if the session data has not yet been accessed.
If the session data has been accessed, calling this method will initiate a store of the data regardless of whether the data is dirty or not.
The isDirty()
will always return true
after calling this method, until changes are made to the session data.
Operation terminate()
Calling this method will immediately reset the state of the session data, and initiate a call to SessionStore.remove(AsciiString)
on the underlying store.
This effectively resets the state of this object.
This method also invokes the SessionId.terminate()
method, which prevents the same ID from being used subsequently.
JavaSessionSerializer getJavaSerializer()
Serializable
.
Ratpack extensions, libraries etc. should explicitly use this serializer (e.g. with SessionData.set(SessionKey, Object, SessionSerializer)
when reading and writing to the session as it is not guaranteed that the default serializer
relies on Java serialization.
Serializable
objectsSessionSerializer getDefaultSerializer()
The default configuration of SessionModule
configures this serializer to be the same as the Java serializer
.
However, if you'd prefer to use a different serialization strategy by default in your application you can override this binding.