Class PerformanceTrackerImpl

java.lang.Object
org.tquadrat.foundation.perflog.internal.PerformanceTrackerImpl
All Implemented Interfaces:
PerformanceTracker

@ClassVersion(sourceVersion="$Id: PerformanceTrackerImpl.java 1258 2026-06-04 18:33:06Z tquadrat $") @API(status=STABLE, since="0.25.0") public final class PerformanceTrackerImpl extends Object implements PerformanceTracker

The implementation for the interface PerformanceTracker.

Author:
Thomas Thrien (thomas.thrien@tquadrat.org)
Version:
$Id: PerformanceTrackerImpl.java 1258 2026-06-04 18:33:06Z tquadrat $
Since:
0.25.0
UML Diagram
UML Diagram for "org.tquadrat.foundation.perflog.internal.PerformanceTrackerImpl"

UML Diagram for "org.tquadrat.foundation.perflog.internal.PerformanceTrackerImpl"

UML Diagram for "org.tquadrat.foundation.perflog.internal.PerformanceTrackerImpl"
  • Field Details

    • m_Aborted

      private boolean m_Aborted
      The flag that indicates whether the tracker was aborted.
    • m_Context

      private final Map<String,String> m_Context
      The context data.
    • m_EndTime

      private long m_EndTime

      The end time for this performance tracker.

      This is not an absolute time, but a relative value.

      See Also:
    • m_PerfLogManager

      The reference to the performance manager that created this tracker.
    • m_PerformanceSection

      The performance section for this tracker.
    • m_Started

      private boolean m_Started
      The flag that indicates whether the tracker was started.
    • m_StartTime

      private long m_StartTime

      The start time for this performance tracker.

      This is not an absolute time, but a relative value.

      See Also:
    • m_Stopped

      private boolean m_Stopped
      The flag that indicates whether the tracker was stopped.
    • m_TimedOut

      private boolean m_TimedOut

      The flag that indicates whether this tracker was aborted because of a timeout.

    • m_TimeOutFuture

      The future that is used for the timeout handling.

      Will be null when the timeout is disabled.

    • m_Timestamp

      The absolute time when this performance tracker was started. This is only used for reporting purposes.

  • Constructor Details

    • PerformanceTrackerImpl

      public PerformanceTrackerImpl(PerfLogManager perfLogManager, PerformanceSection performanceSection)
      Creates a new instance of PerformanceTrackerImpl.
      Parameters:
      perfLogManager - The reference to the performance manager that created this tracker instance.
      performanceSection - The reference to the definition for the performance section.
  • Method Details

    • abort

      public final void abort()

      Stops the performance timer.

      If the tracker has been aborted or stopped already, nothing happens. Same if it was never started.

      Specified by:
      abort in interface PerformanceTracker
    • abort

      public final void abort(String message)

      Stops the performance timer and takes a message describing the reason for the abort.

      If the tracker has been aborted or stopped already, nothing happens. Same if it was never started.

      Specified by:
      abort in interface PerformanceTracker
      Parameters:
      message - The message describing the reason for the abort.
    • abort

      public final void abort(String message, Throwable cause)

      Stops the performance timer and takes a message describing the reason for the abort, plus the exception that caused it.

      If the tracker has been aborted or stopped already, nothing happens. Same if it was never started.

      Specified by:
      abort in interface PerformanceTracker
      Parameters:
      message - The message describing the reason for the abort.
      cause - The exception that caused the abort.
    • abort

      public final void abort(boolean flag)

      Stops the performance timer and sets the timeout flag.

      If the tracker has been aborted or stopped already, nothing happens. Same if it was never started.

      Parameters:
      flag - true if the tracker timed out, false if this is a "regular" abort.
    • abort

      private final void abort(String message, Throwable cause, boolean flag)

      Stops the performance timer, sets the timeout flag and sends a report if required.

      If the tracker has been aborted or stopped already, nothing happens. Same if it was never started.

      Parameters:
      message - The message describing the reason for the abort.
      cause - The exception that caused the abort.
      flag - true if the tracker timed out, false if this is a "regular" abort.
    • addContext

      public final PerformanceTracker addContext(String name, String value)

      Adds context information to this tracker. This is also transferred to the PerfLogMBean when the tracker is stopped or aborted.

      The given name must conform a valid JSON name and may not start with an underscore ("_"/#x005f).

      The given name is unique; if a value is added with an already known name, it will overwrite the existing value.

      A call to PerformanceTracker.start() will not reset the context.

      An example on how to use the context may look like this:

      1//---* Load Data *-------------------------------------------------------------
      2try( final var tracker = PerfLogUtils.holdAndStart( PS1 ) )
      3{
      4    tracker.setContext( "Source", … );
      5
      6    // Do something here!!
      78}
      
      Specified by:
      addContext in interface PerformanceTracker
      Parameters:
      name - The name of the context value.
      value - The context value; null removes the entry with the given name.
      Returns:
      This instance.
    • getContext

      public final Map<String,String> getContext()
      Returns the context information.
      Returns:
      The context information.
    • getElapsedTime

      Returns the elapsed time in nanoseconds.
      Returns:
      An instance of Optional holding the elapsed time.
    • getPerformanceSection

      Returns the performance section.
      Returns:
      The performance section.
    • getStatus

      Returns the status of this tracker instance.
      Specified by:
      getStatus in interface PerformanceTracker
      Returns:
      The tracker status.
    • getTimestamp

      public final Instant getTimestamp()
      Returns the timestamp.
      Returns:
      The timestamp.
    • isThresholdExceeded

      public boolean isThresholdExceeded()

      Checks whether the threshold was exceeded. This means the operation covered by the performance section for this tracker took longer than the estimated time.

      Returns:
      true if the operation took longer than the provided threshold, false otherwise, or no threshold was provided.
    • isTimedOut

      public final boolean isTimedOut()

      Checks whether the tracker was aborted due to a timeout.

      Returns:
      true if the tracker was aborted due to a timeout, false if it is still running, if it was regularly stopped, if aborted due to other reasons, or if the timeout was disabled for the respective performance section.
    • registerTimeoutMonitor

      private final void registerTimeoutMonitor()
      Registers the timeout monitor for this performance tracker.
    • reset

      public final PerformanceTracker reset(boolean resetContext) throws IllegalStateException

      Resets the instance.

      If the tracker was already started, but never stopped or aborted, an IllegalStateException is thrown.

      Specified by:
      reset in interface PerformanceTracker
      Parameters:
      resetContext - true if also the context should be reset, false to keep the current context.
      Returns:
      This instance.
      Throws:
      IllegalStateException - The tracker was already started but not stopped or aborted.
    • start

      public final void start() throws IllegalStateException

      Resets the instance and starts the performance timer.

      If the tracker was already started, but never stopped or aborted, an IllegalStateException is thrown.

      Specified by:
      start in interface PerformanceTracker
      Throws:
      IllegalStateException - The tracker was already started but not stopped or aborted.
    • stop

      public final void stop() throws IllegalStateException

      Stops the performance timer and transfers the elapsed time to the PerfLogMBean for further processing.

      If the tracker has been aborted already, nothing happens. Same if it was never started.

      Specified by:
      stop in interface PerformanceTracker
      Throws:
      IllegalStateException - The tracker was already stopped previously.
    • terminateTimeoutMonitoring

      private final void terminateTimeoutMonitoring()
      Terminates the timeout monitor.