| 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package net.digitaltsunami.tmeter.action; |
| 5 | |
| 6 | import java.util.Collection; |
| 7 | |
| 8 | import net.digitaltsunami.tmeter.Timer; |
| 9 | import net.digitaltsunami.tmeter.TimerBasicStatistics; |
| 10 | |
| 11 | /** |
| 12 | * Timer statistics action that publishes all accumulated statistics to the |
| 13 | * provided {@link TimerStatsPublisher}. |
| 14 | * <p> |
| 15 | * Note: This action is defined to accumulate and publish statistic with each |
| 16 | * completion of a timer. As such, the publisher may come under heavy load. |
| 17 | * |
| 18 | * @author dhagberg |
| 19 | * |
| 20 | */ |
| 21 | public class TimerStatsPublisherAction extends TimerStatsAction { |
| 22 | private final TimerStatsPublisher publisher; |
| 23 | |
| 24 | /** |
| 25 | * Create an instance with the required publisher. |
| 26 | * |
| 27 | * @param publisher |
| 28 | * Publisher to which all events will be sent. |
| 29 | */ |
| 30 | public TimerStatsPublisherAction(TimerStatsPublisher publisher) { |
| 31 | super(); |
| 32 | if (publisher == null) { |
| 33 | throw new IllegalArgumentException("Publisher cannot be null"); |
| 34 | } |
| 35 | this.publisher = publisher; |
| 36 | } |
| 37 | |
| 38 | /* |
| 39 | * (non-Javadoc) |
| 40 | * |
| 41 | * @see |
| 42 | * net.digitaltsunami.tmeter.action.TimerAction#processTimer(net.digitaltsunami |
| 43 | * .tmeter.Timer) |
| 44 | */ |
| 45 | @Override |
| 46 | protected void processTimer(Timer timer) { |
| 47 | super.processTimer(timer); |
| 48 | publisher.publish(getTimerStatisticsSnapshot(timer.getTaskName())); |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * (non-Javadoc) |
| 53 | * |
| 54 | * @see net.digitaltsunami.tmeter.action.TimerStatsAction#reset() |
| 55 | */ |
| 56 | @Override |
| 57 | protected void reset() { |
| 58 | Collection<TimerBasicStatistics> stats = getAllTimerStatisticsSnapshot(); |
| 59 | super.reset(); |
| 60 | publisher.reset(stats); |
| 61 | } |
| 62 | |
| 63 | } |