Class SqlStatistic

All Implemented Interfaces:
AbstractStatisticMBean, SqlStatisticMBean, AbstractMonitorMBean, Shutdownable, Runnable

public class SqlStatistic extends AbstractStatistic implements SqlStatisticMBean
This class monitors and measures SQL statements.
Since:
0.9
Author:
oliver
  • Constructor Details

    • SqlStatistic

      protected SqlStatistic()
  • Method Details

    • getInstance

      public static SqlStatistic getInstance()
      Gets the single instance of SqlStatistic.
      Returns:
      single instance of SqlStatistic
    • reset

      public void reset()
      To start a new statistic call this method. In contradiction to AbstractStatistic.reset() old ProfileMonitors will removed.
      Specified by:
      reset in interface AbstractStatisticMBean
      Overrides:
      reset in class AbstractStatistic
    • start

      public static ProfileMonitor start(String sql)
      Start the monitor for the given SQL statement.
      Parameters:
      sql - the SQL statement to be monitored
      Returns:
      the started profile monitor
    • stop

      public static void stop(ProfileMonitor mon, String command)
      Stops the given 'mon' and logs the given command with the needed time if debug is enabled.
      Parameters:
      mon - the mon
      command - the command
    • stop

      public static void stop(ProfileMonitor mon, String command, Object returnValue)
      Stops the given 'mon' and logs the given command with the needed time if debug is enabled.
      Parameters:
      mon - the monitor
      command - the SQL command
      returnValue - the monitored return value
    • addAsShutdownHook

      public static void addAsShutdownHook()
      You can register the instance as shutdown hook. If the VM is terminated the profile values are logged and dumped to a CSV file in the tmp directory.
    • registerAsMBean

      public static void registerAsMBean(String name)
      With this method you can register the monitor with your own name. This is e.g. useful if you have an application server with several applications.

      You can only register the monitor only once. If you want to register it with another name you have to first unregister it.

      Parameters:
      name - the MBean name (e.g. "my.class.Monitor")