Class StatusManager
java.lang.Object
uno.anahata.ai.status.StatusManager
Manages and broadcasts the operational status of a
Chat session.
This class tracks the current ChatStatus, monitors API errors for retry logic,
records token usage metadata, and notifies registered StatusListeners of state changes.
-
Constructor Summary
ConstructorsConstructorDescriptionStatusManager(Chat chat) Constructs a new StatusManager for the given Chat instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(StatusListener listener) Adds a listener to be notified of status changes.voidClears the history of API errors.Gets an unmodifiable list of all recorded API errors.Gets the most recent API error record.voidrecordApiError(String modelId, String apiKey, int retryAttempt, long backoffAmount, Throwable throwable) Records an API error and updates the status toWAITING_WITH_BACKOFF.voidRecords the timestamp of the most recent user input.voidremoveListener(StatusListener listener) Removes a previously added status listener.voidreset()Resets the status manager to its initial state.voidsetLastUsage(com.google.genai.types.GenerateContentResponseUsageMetadata lastUsage) Sets the usage metadata from the last API response.voidsetStatus(ChatStatus newStatus) Updates the current operational status and notifies listeners.
-
Constructor Details
-
StatusManager
Constructs a new StatusManager for the given Chat instance.- Parameters:
chat- The Chat instance to manage status for.
-
-
Method Details
-
addListener
Adds a listener to be notified of status changes.- Parameters:
listener- The listener to add.
-
removeListener
Removes a previously added status listener.- Parameters:
listener- The listener to remove.
-
recordUserInputTime
public void recordUserInputTime()Records the timestamp of the most recent user input. -
setStatus
Updates the current operational status and notifies listeners.- Parameters:
newStatus- The new status to set.
-
setLastUsage
public void setLastUsage(com.google.genai.types.GenerateContentResponseUsageMetadata lastUsage) Sets the usage metadata from the last API response.- Parameters:
lastUsage- The usage metadata.
-
clearApiErrors
public void clearApiErrors()Clears the history of API errors. -
reset
public void reset()Resets the status manager to its initial state. -
recordApiError
public void recordApiError(String modelId, String apiKey, int retryAttempt, long backoffAmount, Throwable throwable) Records an API error and updates the status toWAITING_WITH_BACKOFF.- Parameters:
modelId- The ID of the model being called.apiKey- The last 5 characters of the API key used.retryAttempt- The current retry attempt number.backoffAmount- The amount of time to wait before the next retry.throwable- The exception that occurred.
-
getApiErrors
Gets an unmodifiable list of all recorded API errors.- Returns:
- The list of API error records.
-
getLastApiError
Gets the most recent API error record.- Returns:
- The last error record, or
nullif no errors have occurred.
-
