Class H2LogReader
java.lang.Object
com.scivicslab.turingworkflow.plugins.logdb.H2LogReader
- All Implemented Interfaces:
AutoCloseable
Read-only H2 log reader for querying workflow logs.
This class provides access to the H2 log database for querying logs. Uses AUTO_SERVER=TRUE to connect to the H2 server started by the writer process, allowing concurrent access while logs are being written.
- Since:
- 1.0
- Author:
- devteam@scivicslab.com
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordInformation about a node in a session. -
Constructor Summary
ConstructorsConstructorDescriptionH2LogReader(String host, int port, String dbPath) Opens a remote log database via H2 TCP server.H2LogReader(Path dbPath) Opens the log database for reading.H2LogReader(Connection connection) Creates a reader using an existing connection. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this reader, releasing the database connection if owned.longGets the latest session ID.getLogsByLevel(long sessionId, LogLevel minLevel) Gets logs filtered by minimum log level.getLogsByNode(long sessionId, String nodeId) Gets logs filtered by node ID.getNodesInSession(long sessionId) Gets all nodes that participated in a session.getSummary(long sessionId) Gets a summary of the specified session.listSessions(int limit) Lists recent sessions.listSessionsFiltered(String workflowName, String overlayName, String inventoryName, LocalDateTime startedAfter, int limit) Lists sessions filtered by criteria.listSessionsFiltered(String workflowName, String overlayName, String inventoryName, LocalDateTime startedAfter, LocalDateTime endedAfter, int limit) Lists sessions filtered by criteria including end time.
-
Constructor Details
-
H2LogReader
Opens the log database for reading.- Parameters:
dbPath- path to the database file (without extension)- Throws:
SQLException- if database connection fails
-
H2LogReader
Opens a remote log database via H2 TCP server.- Parameters:
host- H2 server hostname (typically "localhost")port- H2 server TCP portdbPath- database path on the server- Throws:
SQLException- if database connection fails
-
H2LogReader
Creates a reader using an existing connection.Used internally by H2LogStore to delegate read operations. The connection will NOT be closed when this reader is closed.
- Parameters:
connection- the database connection to use
-
-
Method Details
-
getLogsByNode
Gets logs filtered by node ID.- Parameters:
sessionId- the session IDnodeId- the node ID to filter by- Returns:
- list of log entries for the specified node
-
getLogsByLevel
Gets logs filtered by minimum log level.- Parameters:
sessionId- the session IDminLevel- the minimum log level to include- Returns:
- list of log entries at or above the specified level
-
getSummary
Gets a summary of the specified session.- Parameters:
sessionId- the session ID- Returns:
- the session summary, or null if not found
-
getLatestSessionId
public long getLatestSessionId()Gets the latest session ID.- Returns:
- the latest session ID, or -1 if no sessions exist
-
listSessions
Lists recent sessions.- Parameters:
limit- maximum number of sessions to return- Returns:
- list of session summaries, ordered by start time descending
-
listSessionsFiltered
public List<SessionSummary> listSessionsFiltered(String workflowName, String overlayName, String inventoryName, LocalDateTime startedAfter, int limit) Lists sessions filtered by criteria.- Parameters:
workflowName- filter by workflow name (null to skip)overlayName- filter by overlay name (null to skip)inventoryName- filter by inventory name (null to skip)startedAfter- filter by start time (null to skip)limit- maximum number of sessions to return- Returns:
- list of session summaries matching the criteria
-
listSessionsFiltered
public List<SessionSummary> listSessionsFiltered(String workflowName, String overlayName, String inventoryName, LocalDateTime startedAfter, LocalDateTime endedAfter, int limit) Lists sessions filtered by criteria including end time.- Parameters:
workflowName- filter by workflow name (nullto skip)overlayName- filter by overlay name (nullto skip)inventoryName- filter by inventory name (nullto skip)startedAfter- filter sessions started at or after this time (nullto skip)endedAfter- filter sessions ended at or after this time (nullto skip)limit- maximum number of sessions to return- Returns:
- list of session summaries matching the criteria, ordered by start time descending
-
getNodesInSession
Gets all nodes that participated in a session.- Parameters:
sessionId- the session ID- Returns:
- list of node information, ordered by node ID
-
close
Closes this reader, releasing the database connection if owned.If this reader was created with an external connection (via
H2LogReader(Connection)), the connection is not closed.- Specified by:
closein interfaceAutoCloseable- Throws:
SQLException- if a database error occurs while closing the connection
-