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
ConstructorsConstructorDescriptionThis 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
Modifier and TypeMethodDescriptionprotected intchecksum()computeIfAbsent(String key, Function<String, Object> mappingFunction) Put some data in a session if absent.protected intcrc()data()voiddestroy()Destroy the sessionvoidflushed(boolean skipCrc) Mark this session as flushed, this gives the object a change to clear any state management flags.<T> TGet some data from the sessionid()voidbooleanbooleanisEmpty()booleanlongoldId()Put some data in a sessionputIfAbsent(String key, Object obj) Put some data in a session if absentprotected intreadDataFromBuffer(int pos, Buffer buffer) protected voidreadDataFromBuffer(Buffer buffer) <T> TRemove some data from the sessionvoidMark the session as being accessed.protected voidsetData(JsonObject data) protected voidprotected voidprotected voidsetLastAccessed(long lastAccessed) voidsetPRNG(VertxContextPRNG prng) protected voidsetTimeout(long timeout) protected voidsetVersion(int version) longtimeout()intversion()protected voidwriteDataToBuffer(Buffer buffer)
-
Constructor Details
-
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
-
AbstractSession
-
-
Method Details
-
setId
-
setTimeout
protected void setTimeout(long timeout) -
setData
-
setData
-
setLastAccessed
protected void setLastAccessed(long lastAccessed) -
setVersion
protected void setVersion(int version) -
setPRNG
-
flushed
public void flushed(boolean skipCrc) Description copied from interface:io.vertx.ext.web.sstore.impl.SessionInternalMark this session as flushed, this gives the object a change to clear any state management flags.- Specified by:
flushedin 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
-
regenerateId
- Specified by:
regenerateIdin interfaceSession- Returns:
- The new unique ID of the session.
-
timeout
-
get
-
put
-
putIfAbsent
-
computeIfAbsent
Description copied from interface:SessionPut 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:
computeIfAbsentin interfaceSession- Parameters:
key- the key for the datamappingFunction- a mapping function- Returns:
- a reference to this, so the API can be used fluently
-
remove
-
data
-
isEmpty
-
lastAccessed
public long lastAccessed()- Specified by:
lastAccessedin interfaceSession- Returns:
- the time the session was last accessed
-
setAccessed
public void setAccessed()Description copied from interface:SessionMark the session as being accessed.- Specified by:
setAccessedin interfaceSession
-
destroy
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceSession- Returns:
- has the session been destroyed?
-
isRegenerated
public boolean isRegenerated()- Specified by:
isRegeneratedin interfaceSession- Returns:
- has the session been renewed?
-
oldId
-
version
public int version() -
incrementVersion
public void incrementVersion() -
crc
protected int crc() -
checksum
protected int checksum() -
writeDataToBuffer
-
readDataFromBuffer
-
readDataFromBuffer
-