Interface Session
-
public interface Session
A mechanism for associating semi persistent data with an individual user/client.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.- See Also:
SessionModule
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Operation
clear()
A convenience shorthand forSessionData.clear()
.default <T> Promise<Optional<T>>
get(Class<T> type)
A convenience shorthand forSessionData.get(Class)
.default <T> Promise<Optional<T>>
get(Class<T> type, SessionSerializer serializer)
A convenience shorthand forSessionData.get(Class, SessionSerializer)
.default Promise<Optional<?>>
get(String name)
A convenience shorthand forSessionData.get(String)
.default Promise<Optional<?>>
get(String name, SessionSerializer serializer)
A convenience shorthand forSessionData.get(String, SessionSerializer)
.default <T> Promise<Optional<T>>
get(SessionKey<T> key)
A convenience shorthand forSessionData.get(SessionKey)
.default <T> Promise<Optional<T>>
get(SessionKey<T> key, SessionSerializer serializer)
A convenience shorthand forSessionData.get(SessionKey, SessionSerializer)
.Promise<SessionData>
getData()
The session data.SessionSerializer
getDefaultSerializer()
The serializer that is used when a serializer is not explicitly given.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 implementsSerializable
.default Promise<Set<SessionKey<?>>>
getKeys()
A convenience shorthand forSessionData.getKeys()
.boolean
isDirty()
Whether or not any changes have been made to the session data since it was accessed.default Operation
remove(Class<?> type)
A convenience shorthand forSessionData.remove(Class)
.default Operation
remove(String name)
A convenience shorthand forSessionData.remove(String)
.default Operation
remove(SessionKey<?> key)
A convenience shorthand forSessionData.remove(SessionKey)
.default <T> Promise<T>
require(Class<T> type)
A convenience shorthand forSessionData.require(Class)
.default <T> Promise<T>
require(Class<T> type, SessionSerializer serializer)
A convenience shorthand forSessionData.require(Class, SessionSerializer)
.default Promise<?>
require(String name)
A convenience shorthand forSessionData.require(String)
.default Promise<?>
require(String name, SessionSerializer serializer)
A convenience shorthand forSessionData.require(String, SessionSerializer)
.default <T> Promise<T>
require(SessionKey<T> key)
A convenience shorthand forSessionData.require(SessionKey)
.default <T> Promise<T>
require(SessionKey<T> key, SessionSerializer serializer)
A convenience shorthand forSessionData.require(SessionKey, SessionSerializer)
.Operation
save()
Persists the session data.default <T> Operation
set(Class<T> type, T value)
A convenience shorthand forSessionData.set(Class, Object)
.default <T> Operation
set(Class<T> type, T value, SessionSerializer serializer)
A convenience shorthand forSessionData.set(Class, Object, SessionSerializer)
.default <T> Operation
set(String name, T value)
A convenience shorthand forSessionData.set(String, Object)
.default <T> Operation
set(String name, T value, SessionSerializer serializer)
A convenience shorthand forSessionData.set(String, Object, SessionSerializer)
.default <T> Operation
set(SessionKey<T> key, T value)
A convenience shorthand forSessionData.set(SessionKey, Object)
.default <T> Operation
set(SessionKey<T> key, T value, SessionSerializer serializer)
A convenience shorthand forSessionData.set(SessionKey, Object, SessionSerializer)
.default <T> Operation
set(T value)
A convenience shorthand forSessionData.set(Object)
.default <T> Operation
set(T value, SessionSerializer serializer)
A convenience shorthand forSessionData.set(Object, SessionSerializer)
.Operation
terminate()
Terminates the session and session id.
-
-
-
Method Detail
-
getId
String getId()
The unique ID for this session.Call this method will provision a new ID if necessary. Provisioning and tracking of the ID is provided by the bound
SessionId
implementation.- Returns:
- the ID for this session
-
getData
Promise<SessionData> getData()
The session data.The data is available via a promise to support backing
SessionStore
implementations that load the data asynchronously.- Returns:
- the session data
-
getKeys
default Promise<Set<SessionKey<?>>> getKeys()
A convenience shorthand forSessionData.getKeys()
.- Returns:
- the keys of all objects currently in the session
-
get
default <T> Promise<Optional<T>> get(SessionKey<T> key)
A convenience shorthand forSessionData.get(SessionKey)
.- Type Parameters:
T
- the type of object- Parameters:
key
- the key- Returns:
- the value for the given key
- See Also:
require(SessionKey)
-
get
default <T> Promise<Optional<T>> get(SessionKey<T> key, SessionSerializer serializer)
A convenience shorthand forSessionData.get(SessionKey, SessionSerializer)
.- Type Parameters:
T
- the type of object- Parameters:
key
- the keyserializer
- the serializer- Returns:
- the value for the given key
- See Also:
require(SessionKey, SessionSerializer)
-
get
default Promise<Optional<?>> get(String name)
A convenience shorthand forSessionData.get(String)
.- Parameters:
name
- the object name- Returns:
- the value for the given key
- See Also:
require(String)
-
get
default Promise<Optional<?>> get(String name, SessionSerializer serializer)
A convenience shorthand forSessionData.get(String, SessionSerializer)
.- Parameters:
name
- the object nameserializer
- the serializer- Returns:
- the value for the given key
- See Also:
require(String, SessionSerializer)
-
get
default <T> Promise<Optional<T>> get(Class<T> type)
A convenience shorthand forSessionData.get(Class)
.- Type Parameters:
T
- the type- Parameters:
type
- the type- Returns:
- the value for the given key
- See Also:
require(Class)
-
get
default <T> Promise<Optional<T>> get(Class<T> type, SessionSerializer serializer)
A convenience shorthand forSessionData.get(Class, SessionSerializer)
.- Type Parameters:
T
- the type- Parameters:
type
- the typeserializer
- the serializer- Returns:
- the value for the given key
- See Also:
require(Class, SessionSerializer)
-
require
default <T> Promise<T> require(SessionKey<T> key)
A convenience shorthand forSessionData.require(SessionKey)
.- Type Parameters:
T
- the type- Parameters:
key
- the object key- Returns:
- the value for the given key
-
require
default <T> Promise<T> require(SessionKey<T> key, SessionSerializer serializer)
A convenience shorthand forSessionData.require(SessionKey, SessionSerializer)
.- Type Parameters:
T
- the type- Parameters:
key
- the object keyserializer
- the serializer- Returns:
- the value for the given key
-
require
default <T> Promise<T> require(Class<T> type)
A convenience shorthand forSessionData.require(Class)
.- Type Parameters:
T
- the type- Parameters:
type
- the type- Returns:
- the value for the given key
-
require
default <T> Promise<T> require(Class<T> type, SessionSerializer serializer)
A convenience shorthand forSessionData.require(Class, SessionSerializer)
.- Type Parameters:
T
- the type- Parameters:
type
- the typeserializer
- the serializer- Returns:
- the value for the given key
-
require
default Promise<?> require(String name)
A convenience shorthand forSessionData.require(String)
.- Parameters:
name
- the object name- Returns:
- the value for the given key
-
require
default Promise<?> require(String name, SessionSerializer serializer)
A convenience shorthand forSessionData.require(String, SessionSerializer)
.- Parameters:
name
- the object nameserializer
- the serializer- Returns:
- the value for the given key
-
set
default <T> Operation set(SessionKey<T> key, T value)
A convenience shorthand forSessionData.set(SessionKey, Object)
.- Type Parameters:
T
- the type- Parameters:
key
- the keyvalue
- the value- Returns:
- the operation for setting the value
-
set
default <T> Operation set(SessionKey<T> key, T value, SessionSerializer serializer)
A convenience shorthand forSessionData.set(SessionKey, Object, SessionSerializer)
.- Type Parameters:
T
- the type- Parameters:
key
- the keyvalue
- the valueserializer
- the serializer- Returns:
- the operation for setting the value
-
set
default <T> Operation set(Class<T> type, T value)
A convenience shorthand forSessionData.set(Class, Object)
.- Type Parameters:
T
- the type- Parameters:
type
- the typevalue
- the value- Returns:
- the operation for setting the value
-
set
default <T> Operation set(Class<T> type, T value, SessionSerializer serializer)
A convenience shorthand forSessionData.set(Class, Object, SessionSerializer)
.- Type Parameters:
T
- the type- Parameters:
type
- the typevalue
- the valueserializer
- the serializer- Returns:
- the operation for setting the value
-
set
default <T> Operation set(String name, T value)
A convenience shorthand forSessionData.set(String, Object)
.- Type Parameters:
T
- the type- Parameters:
name
- the namevalue
- the value- Returns:
- the operation for setting the value
-
set
default <T> Operation set(String name, T value, SessionSerializer serializer)
A convenience shorthand forSessionData.set(String, Object, SessionSerializer)
.- Type Parameters:
T
- the type- Parameters:
name
- the namevalue
- the valueserializer
- the serializer- Returns:
- the operation for setting the value
-
set
default <T> Operation set(T value)
A convenience shorthand forSessionData.set(Object)
.- Type Parameters:
T
- the type- Parameters:
value
- the value- Returns:
- the operation for setting the value
-
set
default <T> Operation set(T value, SessionSerializer serializer)
A convenience shorthand forSessionData.set(Object, SessionSerializer)
.- Type Parameters:
T
- the type- Parameters:
value
- the valueserializer
- the serializer- Returns:
- the operation for setting the value
-
remove
default Operation remove(SessionKey<?> key)
A convenience shorthand forSessionData.remove(SessionKey)
.- Parameters:
key
- the key- Returns:
- the operation for removing the value
-
remove
default Operation remove(Class<?> type)
A convenience shorthand forSessionData.remove(Class)
.- Parameters:
type
- the type- Returns:
- the operation for removing the value
-
remove
default Operation remove(String name)
A convenience shorthand forSessionData.remove(String)
.- Parameters:
name
- the name- Returns:
- the operation for removing the value
-
clear
default Operation clear()
A convenience shorthand forSessionData.clear()
.- Returns:
- the operation for clearing the session
-
isDirty
boolean isDirty()
Whether or not any changes have been made to the session data since it was accessed.- Returns:
- whether or not any changes have been made to the session data since it was accessed
-
save
Operation save()
Persists the session data.It is generally not necessary to call this method explicitly. The
SessionModule
installs aresponse finalizer
that will call this method if the sessionis 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 returntrue
after calling this method, until changes are made to the session data.- Returns:
- the save operation
-
terminate
Operation terminate()
Terminates the session and session id.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.- Returns:
- the terminate operation
-
getJavaSerializer
JavaSessionSerializer getJavaSerializer()
The value serializer that is guaranteed to be able to serialize/deserialize any Java object that implementsSerializable
.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 thedefault serializer
relies on Java serialization.- Returns:
- a serializer for
Serializable
objects
-
getDefaultSerializer
SessionSerializer getDefaultSerializer()
The serializer that is used when a serializer is not explicitly given.The default configuration of
SessionModule
configures this serializer to be the same as theJava serializer
. However, if you'd prefer to use a different serialization strategy by default in your application you can override this binding.- Returns:
- the serializer to use by default
-
-