Class SessionDAO

java.lang.Object
com.smeup.kokos.sdk.dao.SessionDAO

public class SessionDAO extends Object
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 Details

    • SessionDAO

      public SessionDAO(KokosUser session)
  • Method Details

    • save

      public void save(String context, Map<String,String> data, int ttlInSeconds)
      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 - data
      ttlInSeconds - time to live (seconds)
    • saveVariables

      public void saveVariables(Map<String,String> variables, int ttlInSeconds)
    • read

      public Map<String,String> read(String context)
      Read session data in app given the context
      Parameters:
      context - the session context key
      Returns:
      data as String Map
    • readVariables

      public Map<String,String> readVariables()
    • clear

      public void clear()
      Clear the session. Clear all keys that refers to sessionId
    • refresh

      public void refresh(int ttlInSeconds)
    • tryAcquireLock

      public boolean tryAcquireLock(String context, String ownerId, long ttlInMillis)
      Acquires a lock bound to the current session and provided context. Key format: {sessionId}_{app}_lock_{context}
      Parameters:
      context - the lock context key
      ownerId - 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

      public boolean releaseLock(String context, String ownerId)
      Releases the lock only if it is still owned by ownerId.
      Parameters:
      context - the lock context key
      ownerId - lock owner id
      Returns:
      true when the lock is released, false when lock was not owned by ownerId or absent
    • isLockOwnedBy

      public boolean isLockOwnedBy(String context, String ownerId)
      Checks if the lock exists and is currently owned by ownerId.
      Parameters:
      context - the lock context key
      ownerId - lock owner id
      Returns:
      true when ownerId currently owns the lock