Class DebugEventListener

java.lang.Object
org.pjdbc.debug.DebugEventListener
All Implemented Interfaces:
PjdbcEventListener

public class DebugEventListener extends Object implements PjdbcEventListener
Pre-built event listener that logs all PJDBC events for debugging.

Usage:


 // Enable debug logging
 PjdbcDebug.enable();

 // Or with custom output
 PjdbcDebug.enable(System.err);

 // Or register directly
 PjdbcListeners.register(new DebugEventListener());
 

Output format:

 [PJDBC 14:23:45.123] RETRY sql="SELECT..." attempt=2 delay=100ms cause="Connection reset"
 [PJDBC 14:23:45.234] CIRCUIT_BREAKER name="default" CLOSED → OPEN
 [PJDBC 14:23:45.345] SQL_TRANSFORM "SELECT *" → "SELECT id, name"
 
Since:
2.3.0
  • Constructor Details

    • DebugEventListener

      public DebugEventListener()
      Create a debug listener that writes to System.err.
    • DebugEventListener

      public DebugEventListener(PrintStream out)
      Create a debug listener with custom output.
      Parameters:
      out - the output stream
    • DebugEventListener

      public DebugEventListener(PrintStream out, boolean includeStackTrace)
      Create a debug listener with custom output and stack trace option.
      Parameters:
      out - the output stream
      includeStackTrace - whether to include stack traces for errors
  • Method Details

    • onRetry

      public void onRetry(String sql, SQLException cause, int attempt, long delayMs)
      Description copied from interface: PjdbcEventListener
      Called when a retry is about to be attempted.
      Specified by:
      onRetry in interface PjdbcEventListener
      Parameters:
      sql - the SQL statement being retried (may be null for non-SQL operations)
      cause - the exception that triggered the retry
      attempt - the retry attempt number (1 for first retry, 2 for second, etc.)
      delayMs - the delay in milliseconds before the retry will be attempted
    • onCircuitBreakerStateChange

      public void onCircuitBreakerStateChange(String name, String oldState, String newState)
      Description copied from interface: PjdbcEventListener
      Called when a circuit breaker changes state.
      Specified by:
      onCircuitBreakerStateChange in interface PjdbcEventListener
      Parameters:
      name - the circuit breaker name
      oldState - the previous state (CLOSED, OPEN, or HALF_OPEN)
      newState - the new state
    • onSqlTransformed

      public void onSqlTransformed(String original, String transformed)
      Description copied from interface: PjdbcEventListener
      Called when SQL is transformed by a filter driver.
      Specified by:
      onSqlTransformed in interface PjdbcEventListener
      Parameters:
      original - the original SQL statement
      transformed - the transformed SQL statement
    • onFederatedQuery

      public void onFederatedQuery(String sql, List<String> targetUrls)
      Description copied from interface: PjdbcEventListener
      Called when a query is executed against multiple federated databases.
      Specified by:
      onFederatedQuery in interface PjdbcEventListener
      Parameters:
      sql - the SQL statement being executed
      targetUrls - the JDBC URLs of the target databases
    • onCircuitBreakerRejection

      public void onCircuitBreakerRejection(String name, String state)
      Description copied from interface: PjdbcEventListener
      Called when a request is rejected by a circuit breaker.
      Specified by:
      onCircuitBreakerRejection in interface PjdbcEventListener
      Parameters:
      name - the circuit breaker name
      state - the current circuit breaker state
    • onChaosInjected

      public void onChaosInjected(String type, String sql, String details)
      Description copied from interface: PjdbcEventListener
      Called when chaos injection occurs (for ChaosDriver).
      Specified by:
      onChaosInjected in interface PjdbcEventListener
      Parameters:
      type - the type of chaos injected (e.g., "delay", "exception", "timeout")
      sql - the SQL statement affected (may be null)
      details - additional details about the chaos injection