| 1 | package net.digitaltsunami.tmeter.action; |
| 2 | |
| 3 | import net.digitaltsunami.tmeter.TimeTracker; |
| 4 | import net.digitaltsunami.tmeter.Timer; |
| 5 | import net.digitaltsunami.tmeter.record.NullTimeRecorder; |
| 6 | import net.digitaltsunami.tmeter.record.QueuedTimeRecorder; |
| 7 | import net.digitaltsunami.tmeter.record.TimeRecorder; |
| 8 | |
| 9 | /** |
| 10 | * {@link TimerAction} that records {@link Timer}s. This action can be part of |
| 11 | * an {@link ActionChain} and can be used to record timers to multiple locations |
| 12 | * or just to move the recording off of the timed process's thread. |
| 13 | * Not necessary for simple time recorders, but for |
| 14 | * those that might cause a delay it is better to move the recording task to |
| 15 | * another thread. |
| 16 | * <p> |
| 17 | * There are a couple of ways to use this action: |
| 18 | * <ol> |
| 19 | * <li>Using the {@link QueuedTimeRecorder}. This recorder uses |
| 20 | * {@link TimeRecorderAction} and performs all recording on a separate thread. |
| 21 | * <ol> |
| 22 | * <li>Create an instance of {@link QueuedTimeRecorder} |
| 23 | * <li>Set the {@link TimeTracker#setDefaultTimeRecorder(queuedTimeRecorder)} |
| 24 | * </ol> |
| 25 | * <li>As part of an action chain |
| 26 | * <ol> |
| 27 | * <li>Create an instance of this class with an implementation of |
| 28 | * {@link TimeRecorder} |
| 29 | * <li>Add the instance to the TimeTracker action chain using |
| 30 | * {@link TimeTracker#addAction(TimerAction)} |
| 31 | * <li>If the processing threads should not record the timers, then set the default time |
| 32 | * recorder for TimeTracker to {@link NullTimeRecorder} |
| 33 | * using {@link TimeTracker#setDefaultTimeRecorder(TimeRecorder)}. |
| 34 | * </ol> |
| 35 | * </ol> |
| 36 | * |
| 37 | * @author dhagberg |
| 38 | * |
| 39 | */ |
| 40 | public class TimeRecorderAction extends TimerAction { |
| 41 | private final TimeRecorder recorder; |
| 42 | |
| 43 | public TimeRecorderAction(TimeRecorder recorder) { |
| 44 | this.recorder = recorder; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | protected void processTimer(Timer timer) { |
| 49 | recorder.record(timer); |
| 50 | } |
| 51 | |
| 52 | } |