Package com.smeup.kokos.sdk.dao
Class SessionDAO
java.lang.Object
com.smeup.kokos.sdk.dao.SessionDAO
- Author:
- mattia.bonardi The interface to access to the session. The SessionDAO uses redis as primary datasource, else use inMemorySession user session: { [session_id]_[app]_[context]: Object }
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the session.booleanisLockOwnedBy(String context, String ownerId) Checks if the lock exists and is currently owned by ownerId.Read session data in app given the contextvoidrefresh(int ttlInSeconds) booleanreleaseLock(String context, String ownerId) Releases the lock only if it is still owned by ownerId.voidSave session data in app given the context key.voidsaveVariables(Map<String, String> variables, int ttlInSeconds) booleantryAcquireLock(String context, String ownerId, long ttlInMillis) Acquires a lock bound to the current session and provided context.
-
Constructor Details
-
SessionDAO
-
-
Method Details
-
save
Save session data in app given the context key.- Parameters:
context- the session context key. (i.e. 'rpgle', define the session relative to rpgle)data- datattlInSeconds- time to live (seconds)
-
saveVariables
-
read
Read session data in app given the context- Parameters:
context- the session context key- Returns:
- data as String Map
-
readVariables
-
clear
public void clear()Clear the session. Clear all keys that refers to sessionId -
refresh
public void refresh(int ttlInSeconds) -
tryAcquireLock
Acquires a lock bound to the current session and provided context. Key format: {sessionId}_{app}_lock_{context}- Parameters:
context- the lock context keyownerId- lock owner id (e.g. request id)ttlInMillis- lock ttl in milliseconds- Returns:
- true when lock is acquired, false when lock is already held
-
releaseLock
Releases the lock only if it is still owned by ownerId.- Parameters:
context- the lock context keyownerId- lock owner id- Returns:
- true when the lock is released, false when lock was not owned by ownerId or absent
-
isLockOwnedBy
Checks if the lock exists and is currently owned by ownerId.- Parameters:
context- the lock context keyownerId- lock owner id- Returns:
- true when ownerId currently owns the lock
-