Package io.vertx.ext.web
Interface Session
-
- All Known Implementing Classes:
AbstractSession
public interface SessionRepresents a browser session.Sessions persist between HTTP requests for a single browser session. They are deleted when the browser is closed, or they time-out. Session cookies are used to maintain sessions using a secure UUID.
Sessions can be used to maintain data for a browser session, e.g. a shopping basket.
The context must have first been routed to a
SessionHandlerfor sessions to be available.- Author:
- Tim Fox
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description SessioncomputeIfAbsent(String key, Function<String,Object> mappingFunction)Put some data in a session if absent.Map<String,Object>data()voiddestroy()Destroy the session<T> Tget(String key)Get some data from the sessionStringid()booleanisDestroyed()booleanisEmpty()booleanisRegenerated()longlastAccessed()StringoldId()Sessionput(String key, Object obj)Put some data in a sessionSessionputIfAbsent(String key, Object obj)Put some data in a session if absentSessionregenerateId()<T> Tremove(String key)Remove some data from the sessionvoidsetAccessed()Mark the session as being accessed.longtimeout()default Stringvalue()The short representation of the session to be added to the session cookie.
-
-
-
Method Detail
-
regenerateId
Session regenerateId()
- Returns:
- The new unique ID of the session.
-
id
String id()
- Returns:
- The unique ID of the session. This is generated using a random secure UUID.
-
put
Session put(String key, Object obj)
Put some data in a session- Parameters:
key- the key for the dataobj- the data- Returns:
- a reference to this, so the API can be used fluently
-
putIfAbsent
Session putIfAbsent(String key, Object obj)
Put some data in a session if absent- Parameters:
key- the key for the dataobj- the data- Returns:
- a reference to this, so the API can be used fluently
-
computeIfAbsent
Session computeIfAbsent(String key, Function<String,Object> mappingFunction)
Put some data in a session if absent. If the specified key is not already associated with a value (or is mapped tonull), attempts to compute its value using the given mapping function and enters it into this map unlessnull.- Parameters:
key- the key for the datamappingFunction- a mapping function- Returns:
- a reference to this, so the API can be used fluently
-
get
<T> T get(String key)
Get some data from the session- Parameters:
key- the key of the data- Returns:
- the data
-
remove
<T> T remove(String key)
Remove some data from the session- Parameters:
key- the key of the data- Returns:
- the data that was there or null if none there
-
isEmpty
boolean isEmpty()
- Returns:
- true if the session has data
-
lastAccessed
long lastAccessed()
- Returns:
- the time the session was last accessed
-
destroy
void destroy()
Destroy the session
-
isDestroyed
boolean isDestroyed()
- Returns:
- has the session been destroyed?
-
isRegenerated
boolean isRegenerated()
- Returns:
- has the session been renewed?
-
oldId
String oldId()
- Returns:
- old ID if renewed
-
timeout
long timeout()
- Returns:
- the amount of time in ms, after which the session will expire, if not accessed.
-
setAccessed
void setAccessed()
Mark the session as being accessed.
-
value
default String value()
The short representation of the session to be added to the session cookie. By default is the session id.- Returns:
- short representation string.
-
-