View Javadoc

1   package com.atlassian.performance;
2   
3   public class EventTime {
4   
5       private final String event;
6       private final long time;
7       private final boolean timedOut;
8       private final boolean autoGenerated;
9   
10      public EventTime(String event, long time, boolean timedOut, boolean autoGenerated)
11      {
12          this.event = event;
13          this.time = time;
14          this.timedOut = timedOut;
15          this.autoGenerated = autoGenerated;
16      }
17  
18  
19  
20  
21      public static long calculateTime(long startTime)
22      {
23          return System.currentTimeMillis() - startTime;
24      }
25  
26      public EventTime(String event, long time, boolean autoGenerated)
27      {
28          this(event, time, false, autoGenerated);
29      }
30  
31      public String getEvent()
32      {
33          return event;
34      }
35  
36      public long getTime()
37      {
38          return time;
39      }
40  
41      public boolean getTimedOut()
42      {
43          return timedOut;        
44      }
45  
46      public boolean isAutoGenerated()
47      {
48          return autoGenerated;
49      }
50  
51      public static EventTime timeEvent(String name, boolean autoGenerated, TimedEvent event)
52      {
53          long startTime = System.currentTimeMillis();
54          boolean timedOut = event.run();
55          EventTime et = new EventTime(name, calculateTime(startTime), timedOut, autoGenerated);
56          return et;
57      }
58  
59  
60      public interface TimedEvent
61      {
62          /**
63           * @return True if timed out, false otherwise
64           */
65          abstract public boolean run();
66      }
67  
68  
69  }