Class PerfLogUtils.PerformanceTrackerHolder
- All Implemented Interfaces:
AutoCloseable, PerformanceTracker
- Enclosing class:
PerfLogUtils
A holder for
PerformanceTracker
that allows to use it with try-with-resources.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: PerfLogUtils.java 1258 2026-06-04 18:33:06Z tquadrat $
- Since:
- 0.25.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.perflog.PerfLogUtils.PerformanceTrackerHolder"
-
Nested Class Summary
Nested classes/interfaces inherited from interface PerformanceTracker
PerformanceTracker.TrackerStatus -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanThe flag that indicates whetherclose()was already called on this instance.private PerfLogManagerThe reference to a volatile instance ofPerfLogManager.private final PerformanceTrackerThe wrapped instance ofPerformanceTracker. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateCreates a new instance ofPerformanceTrackerHolderthat does not hold an instance ofPerformanceTracker.privateCreates a new instance ofPerformanceTrackerHolderthat holds an instance ofPerformanceTracker.privatePerformanceTrackerHolder(PerfLogManager manager, PerformanceSectionName name) Creates a new instance ofPerformanceTrackerHolderthat holds an instance ofPerformanceTracker, created by callingPerfLogManager.createPerformanceTracker(PerformanceSectionName)on the givenPerfLogManagerinstance with the givenPerformanceSectionName. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidabort()Stops the performance timer.voidStops the performance timer and takes a message describing the reason for the abort.voidStops the performance timer and takes a message describing the reason for the abort, plus the exception that caused it.final PerformanceTrackeraddContext(String name, String value) Adds context information to this tracker.final <T> PerformanceTrackeraddContext(String name, T value, StringConverter<T> stringConverter) Adds context information to this tracker.final voidclose()Returns the status of this tracker instance.final PerformanceTrackerreset(boolean resetContext) Resets the instance.final voidstart()Resets the instance and starts the performance timer.final voidstop()Stops the performance timer and transfers the elapsed time to thePerfLogMBeanfor further processing.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PerformanceTracker
isActive
-
Field Details
-
m_IsClosed
The flag that indicates whetherclose()was already called on this instance. -
m_Manager
The reference to a volatile instance of
PerfLogManager.It is kept here to prevent it from prematurely being garbage collected.
-
m_Tracker
The wrapped instance of
PerformanceTracker.It can be
null.
-
-
Constructor Details
-
PerformanceTrackerHolder
Creates a new instance of
PerformanceTrackerHolderthat holds an instance ofPerformanceTracker.- Parameters:
tracker- The tracker instance to wrap.- Throws:
ClassCastException- If called with an instance ofHolder.
-
PerformanceTrackerHolder
Creates a new instance of
PerformanceTrackerHolderthat holds an instance ofPerformanceTracker, created by callingPerfLogManager.createPerformanceTracker(PerformanceSectionName)on the givenPerfLogManagerinstance with the givenPerformanceSectionName.- Parameters:
manager- The Performance Logging manager.name- The performance section name.
-
PerformanceTrackerHolder
private PerformanceTrackerHolder()Creates a new instance ofPerformanceTrackerHolderthat does not hold an instance ofPerformanceTracker.
-
-
Method Details
-
abort
Stops the performance timer.
If the tracker has been aborted or stopped already, nothing happens. Same if it was never started.
- Specified by:
abortin interfacePerformanceTracker
-
abort
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:
abortin interfacePerformanceTracker- Parameters:
message- The message describing the reason for the abort.
-
abort
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:
abortin interfacePerformanceTracker- Parameters:
message- The message describing the reason for the abort.cause- The exception that caused the abort.
-
addContext
Adds context information to this tracker. This is also transferred to the
PerfLogMBeanwhen 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!! 7 … 8}
- Specified by:
addContextin interfacePerformanceTracker- Parameters:
name- The name of the context value.value- The context value;nullremoves the entry with the given name.- Returns:
- This instance.
-
addContext
public final <T> PerformanceTracker addContext(String name, T value, StringConverter<T> stringConverter) Adds context information to this tracker. This is also transferred to the
PerfLogMBeanwhen the tracker is stopped.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.- Specified by:
addContextin interfacePerformanceTracker- Type Parameters:
T- The type of the context value.- Parameters:
name- The name of the context value.value- The context value;nullremoves the entry with the given name.stringConverter- The instance ofStringConverterthat is used to translate the value into a String.- Returns:
- This instance.
- See Also:
-
close
- Specified by:
closein interfaceAutoCloseable
-
getStatus
Returns the status of this tracker instance.- Specified by:
getStatusin interfacePerformanceTracker- Returns:
- The tracker status.
-
reset
Resets the instance.
If the tracker was already started, but never stopped or aborted, an
IllegalStateExceptionis thrown.Throws also an
IllegalStateExceptionif this instance ofPerformanceTrackerHolderwas already closed.- Specified by:
resetin interfacePerformanceTracker- Parameters:
resetContext-trueif also the context should be reset,falseto keep the current context.- Returns:
- This instance.
- Throws:
IllegalArgumentException
-
start
Resets the instance and starts the performance timer.
If the tracker was already started, but never stopped or aborted, an
IllegalStateExceptionis thrown.- Specified by:
startin interfacePerformanceTracker- Throws:
IllegalArgumentException
-
stop
Stops the performance timer and transfers the elapsed time to the
PerfLogMBeanfor further processing.If the tracker has been aborted already, nothing happens. Same if it was never started.
- Specified by:
stopin interfacePerformanceTracker- Throws:
IllegalArgumentException
-
