001package org.avaje.metric;
002
003/**
004 * A TimedEvent that is ended with either success or error.
005 * <p>
006 * Note that it is generally preferred to use {@link TimedMetric#addEventSince(boolean, long)} as
007 * that avoids an object creation and the associated GC so has slightly less overhead.
008 * <p>
009 * Example:
010 *
011 * <pre>
012 * <code>
013 *  TimedMetric metric = MetricManager.getTimedMetric(MyService.class, "sayHello");
014 *  ...
015 *
016 *  TimedEvent timedEvent = metric.startEvent();
017 *  try {
018 *    ...
019 *
020 *  } finally {
021 *    // Add the event to the 'success' statistics
022 *    timedEvent.endWithSuccess();
023 *  }
024 *
025 * </code>
026 * </pre>
027 *
028 * @see TimedMetric#startEvent()
029 */
030public interface TimedEvent {
031
032  /**
033   * End specifying whether the event was successful or in error.
034   */
035  void end(boolean withSuccess);
036
037  /**
038   * This timed event ended with successful execution (e.g. Successful SOAP Operation or SQL execution).
039   */
040  void endWithSuccess();
041
042  /**
043   * This timed event ended with an error or fault execution (e.g. SOAP Fault or SQL exception).
044   */
045  void endWithError();
046
047}