Package com.amazonaws.kinesisvideo.util
Class LoggedExitRunnable
- java.lang.Object
-
- com.amazonaws.kinesisvideo.util.LoggedExitRunnable
-
- All Implemented Interfaces:
Runnable
public abstract class LoggedExitRunnable extends Object implements Runnable
An abstract implementation ofRunnablethat provides structured logging for task execution. This class automatically logs entry and exit points of the task, as well as any errors that occur during execution.This class is designed to wrap task execution with consistent logging patterns, making it easier to track and debug asynchronous operations. All exceptions are caught and logged, preventing them from propagating up the call stack.
Example usage:
LoggedExitRunnable task = new LoggedExitRunnable("MyTask") { @Override public void execute() { // Task implementation here } }; executorService.submit(task);The logging format follows the pattern:
- On entry: [TaskName] Enter
- On error: [TaskName] Encountered error running task
- On exit: [TaskName] Leave
- See Also:
Runnable
-
-
Constructor Summary
Constructors Constructor Description LoggedExitRunnable(String runnableTaskName)Creates a new LoggedExitRunnable with the specified task name.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidexecute()To be implemented by concrete classes to define the actual task execution logic.voidrun()Implements theRunnable.run()method with structured logging.
-
-
-
Constructor Detail
-
LoggedExitRunnable
public LoggedExitRunnable(@Nonnull String runnableTaskName)
Creates a new LoggedExitRunnable with the specified task name.- Parameters:
runnableTaskName- A descriptive name for the task that will appear in log messages. Should be unique enough to identify the specific task instance in log output.- Throws:
NullPointerException- if runnableTaskName is null
-
-
Method Detail
-
run
public void run()
Implements theRunnable.run()method with structured logging. This method handles the logging of entry and exit points, as well as any errors that occur during execution.This implementation ensures that all exceptions are caught and logged, and that exit logging occurs even if an exception is thrown.
-
execute
public abstract void execute()
To be implemented by concrete classes to define the actual task execution logic.Any uncaught exceptions thrown by this method will be caught, logged, and re-thrown (propagated) by the
run()method.
-
-