Class Session

java.lang.Object
io.karatelabs.http.Session
All Implemented Interfaces:
io.karatelabs.js.ObjectLike

public class Session extends Object implements io.karatelabs.js.ObjectLike
Session state carrier.

Time fields (created, updated, expires) are epoch seconds (UTC), not milliseconds. This unit choice makes the value directly usable as a DynamoDB TTL attribute (which silently no-ops on millisecond values) and matches the Unix-timestamp convention. Compare against Instant.now().getEpochSecond(), never System.currentTimeMillis().

  • Field Details

    • TEMPORARY

      public static final Session TEMPORARY
  • Constructor Details

    • Session

      public Session(String id, Map<String,Object> data, long created, long updated, long expires)
  • Method Details

    • inMemory

      public static Session inMemory()
    • isTemporary

      public boolean isTemporary()
    • copy

      public Session copy()
    • setUpdated

      public void setUpdated(long updated)
      Parameters:
      updated - epoch seconds (UTC)
    • setExpires

      public void setExpires(long expires)
      Parameters:
      expires - epoch seconds (UTC)
    • getId

      public String getId()
    • getData

      public Map<String,Object> getData()
    • getCreated

      public long getCreated()
      Returns:
      epoch seconds (UTC) when the session was created
    • getUpdated

      public long getUpdated()
      Returns:
      epoch seconds (UTC) of the most recent save
    • getExpires

      public long getExpires()
      Returns:
      epoch seconds (UTC) at which the session expires (DynamoDB-TTL-compatible)
    • getMember

      public Object getMember(String name)
      Specified by:
      getMember in interface io.karatelabs.js.ObjectLike
    • putMember

      public void putMember(String name, Object value)
      Specified by:
      putMember in interface io.karatelabs.js.ObjectLike
    • removeMember

      public void removeMember(String s)
      Specified by:
      removeMember in interface io.karatelabs.js.ObjectLike
    • toMap

      public Map<String,Object> toMap()
      Specified by:
      toMap in interface io.karatelabs.js.ObjectLike
    • toString

      public String toString()
      Overrides:
      toString in class Object