Package io.vertx.ext.web.sstore
Class AbstractSession
- java.lang.Object
-
- io.vertx.ext.web.sstore.AbstractSession
-
- All Implemented Interfaces:
Session
,io.vertx.ext.web.sstore.impl.SessionInternal
public abstract class AbstractSession extends Object implements Session, io.vertx.ext.web.sstore.impl.SessionInternal
The abstract session class provides a barebones implementation for session storage implementors. This class will contain all the related data required for a session plus a couple of helper methods to verify the integrity and versioning of the data. This checksum is important to reduce the amount of times data is pushed to be stored on a backend. As a Vert.x Web user, you should not have to deal with this class directly but with the public interface that it implements.- Author:
- Paulo Lopes
-
-
Constructor Summary
Constructors Constructor Description AbstractSession()
This constructor is mandatory (even though not referenced anywhere) is required for serialization purposes.AbstractSession(VertxContextPRNG random)
AbstractSession(VertxContextPRNG random, long timeout, int length)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
checksum()
Session
computeIfAbsent(String key, java.util.function.Function<String,Object> mappingFunction)
Put some data in a session if absent.protected int
crc()
Map<String,Object>
data()
void
destroy()
Destroy the sessionvoid
flushed(boolean skipCrc)
Mark this session as flushed, this gives the object a change to clear any state management flags.<T> T
get(String key)
Get some data from the sessionString
id()
void
incrementVersion()
boolean
isDestroyed()
boolean
isEmpty()
boolean
isRegenerated()
long
lastAccessed()
String
oldId()
Session
put(String key, Object obj)
Put some data in a sessionSession
putIfAbsent(String key, Object obj)
Put some data in a session if absentprotected int
readDataFromBuffer(int pos, Buffer buffer)
protected void
readDataFromBuffer(Buffer buffer)
Session
regenerateId()
<T> T
remove(String key)
Remove some data from the sessionvoid
setAccessed()
Mark the session as being accessed.protected void
setData(JsonObject data)
protected void
setData(Map<String,Object> data)
protected void
setId(String id)
protected void
setLastAccessed(long lastAccessed)
void
setPRNG(VertxContextPRNG prng)
protected void
setTimeout(long timeout)
protected void
setVersion(int version)
long
timeout()
int
version()
protected void
writeDataToBuffer(Buffer buffer)
-
-
-
Constructor Detail
-
AbstractSession
public AbstractSession()
This constructor is mandatory (even though not referenced anywhere) is required for serialization purposes. Do not remove. It is required as part of the contract of the ClusterSerializable interface which some implementations might require.
-
AbstractSession
public AbstractSession(VertxContextPRNG random)
-
AbstractSession
public AbstractSession(VertxContextPRNG random, long timeout, int length)
-
-
Method Detail
-
setId
protected void setId(String id)
-
setTimeout
protected void setTimeout(long timeout)
-
setData
protected void setData(JsonObject data)
-
setLastAccessed
protected void setLastAccessed(long lastAccessed)
-
setVersion
protected void setVersion(int version)
-
setPRNG
public void setPRNG(VertxContextPRNG prng)
-
flushed
public void flushed(boolean skipCrc)
Description copied from interface:io.vertx.ext.web.sstore.impl.SessionInternal
Mark this session as flushed, this gives the object a change to clear any state management flags.- Specified by:
flushed
in interfaceio.vertx.ext.web.sstore.impl.SessionInternal
- Parameters:
skipCrc
- if the intention is NOT to keep using the session after this call, a small optimization can be performed (skip updating the internal CRC) which is unnecessary.
-
id
public String id()
-
regenerateId
public Session regenerateId()
- Specified by:
regenerateId
in interfaceSession
- Returns:
- The new unique ID of the session.
-
timeout
public long timeout()
-
get
public <T> T get(String key)
Description copied from interface:Session
Get some data from the session
-
put
public Session put(String key, Object obj)
Description copied from interface:Session
Put some data in a session
-
putIfAbsent
public Session putIfAbsent(String key, Object obj)
Description copied from interface:Session
Put some data in a session if absent- Specified by:
putIfAbsent
in interfaceSession
- Parameters:
key
- the key for the dataobj
- the data- Returns:
- a reference to this, so the API can be used fluently
-
computeIfAbsent
public Session computeIfAbsent(String key, java.util.function.Function<String,Object> mappingFunction)
Description copied from interface:Session
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
.- Specified by:
computeIfAbsent
in interfaceSession
- Parameters:
key
- the key for the datamappingFunction
- a mapping function- Returns:
- a reference to this, so the API can be used fluently
-
remove
public <T> T remove(String key)
Description copied from interface:Session
Remove some data from the session
-
isEmpty
public boolean isEmpty()
-
lastAccessed
public long lastAccessed()
- Specified by:
lastAccessed
in interfaceSession
- Returns:
- the time the session was last accessed
-
setAccessed
public void setAccessed()
Description copied from interface:Session
Mark the session as being accessed.- Specified by:
setAccessed
in interfaceSession
-
destroy
public void destroy()
Description copied from interface:Session
Destroy the session
-
isDestroyed
public boolean isDestroyed()
- Specified by:
isDestroyed
in interfaceSession
- Returns:
- has the session been destroyed?
-
isRegenerated
public boolean isRegenerated()
- Specified by:
isRegenerated
in interfaceSession
- Returns:
- has the session been renewed?
-
version
public int version()
-
incrementVersion
public void incrementVersion()
-
crc
protected int crc()
-
checksum
protected int checksum()
-
writeDataToBuffer
protected void writeDataToBuffer(Buffer buffer)
-
readDataFromBuffer
protected int readDataFromBuffer(int pos, Buffer buffer)
-
readDataFromBuffer
protected void readDataFromBuffer(Buffer buffer)
-
-