Class Session

java.lang.Object
com.google.adk.JsonBaseModel
com.google.adk.sessions.Session

public final class Session extends JsonBaseModel
A Session object that encapsulates the State and Events of a session.
  • Method Details

    • builder

      public static Session.Builder builder(String id)
    • builder

      public static Session.Builder builder(SessionKey sessionKey)
      Creates a new Session.Builder with the given session key.
    • sessionKey

      public SessionKey sessionKey()
      Returns the session key.
    • id

      public String id()
    • state

      public Map<String,Object> state()
    • events

      @Deprecated public List<Event> events()
      Deprecated.
      Prefer immutableEvents() when reading or iterating over events (to avoid ConcurrentModificationException), and addEvent(Event) or addEvents(Collection) when appending events.
      Returns the mutable list of events backing this session, which also serves as the monitor for all event-helper synchronization.
    • immutableEvents

      public com.google.common.collect.ImmutableList<Event> immutableEvents()
      Returns a thread-safe, immutable snapshot of the session's events, synchronizing on the backing events() list. Use this method whenever reading, iterating, streaming, filtering, or slicing (List.subList(int, int)) session events to avoid ConcurrentModificationException under concurrent modifications.
    • addEvent

      public void addEvent(Event event)
      Appends a single Event to the session's event list while synchronizing on the backing events() list; prefer over events().add(event).
    • addEvents

      public void addEvents(Collection<Event> events)
      Appends all Events in the given collection to the session's event list while synchronizing on the backing events() list; prefer over events().addAll(events).
    • appName

      public String appName()
    • userId

      public String userId()
    • lastUpdateTime

      public void lastUpdateTime(Instant lastUpdateTime)
    • lastUpdateTime

      public Instant lastUpdateTime()
    • getLastUpdateTimeAsDouble

      public double getLastUpdateTimeAsDouble()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • fromJson

      public static Session fromJson(String json)