Class SimpleContextManager
java.lang.Object
com.techcognita.javachatx.context.SimpleContextManager
- All Implemented Interfaces:
ContextManager
Simple implementation of the ContextManager interface.
Manages session context using in-memory storage.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddToHistory(String sessionId, com.google.gson.JsonObject message) Add a message to the conversation history.voidclearContext(String sessionId) Clear context data for a session.getContext(String sessionId, String key) Retrieve context data for a session.com.google.gson.JsonObjectgetHistory(String sessionId) Get the conversation history for a session.com.google.gson.JsonObjectgetSessionContext(String sessionId) Get all context data for a session as a JSON object.voidsetContext(String sessionId, String key, Object value) Store context data for a session.
-
Constructor Details
-
SimpleContextManager
public SimpleContextManager()
-
-
Method Details
-
setContext
Description copied from interface:ContextManagerStore context data for a session.- Specified by:
setContextin interfaceContextManager- Parameters:
sessionId- The session identifierkey- The context keyvalue- The context value
-
getContext
Description copied from interface:ContextManagerRetrieve context data for a session.- Specified by:
getContextin interfaceContextManager- Parameters:
sessionId- The session identifierkey- The context key- Returns:
- The context value, or null if not found
-
getSessionContext
Description copied from interface:ContextManagerGet all context data for a session as a JSON object.- Specified by:
getSessionContextin interfaceContextManager- Parameters:
sessionId- The session identifier- Returns:
- All context data for the session
-
clearContext
Description copied from interface:ContextManagerClear context data for a session.- Specified by:
clearContextin interfaceContextManager- Parameters:
sessionId- The session identifier
-
addToHistory
Description copied from interface:ContextManagerAdd a message to the conversation history.- Specified by:
addToHistoryin interfaceContextManager- Parameters:
sessionId- The session identifiermessage- The message to add to history
-
getHistory
Description copied from interface:ContextManagerGet the conversation history for a session.- Specified by:
getHistoryin interfaceContextManager- Parameters:
sessionId- The session identifier- Returns:
- The conversation history
-