01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jorphan.timer;
20:
21: /**
22: * A simple interface for measuring time intervals. An instance of this goes
23: * through the following lifecycle states:
24: * <dl>
25: * <dt><em>ready</em></dt>
26: * <dd>timer is ready to start a new measurement</dd>
27: * <dt><em>started</em></dt>
28: * <dd>timer has recorded the starting time interval point</dd>
29: * <dt><em>stopped</em></dt>
30: * <dd>timer has recorded the ending time interval point</dd>
31: * </dl>
32: * See individual methods for details.
33: * <p>
34: * If this library has been compiled with
35: * {@link ITimerConstants#DO_STATE_CHECKS} set to 'true' the implementation will
36: * enforce this lifecycle model and throw IllegalStateException when it is
37: * violated.
38: *
39: * @author <a href="mailto:vroubtsov@illinoisalumni.org">Vlad Roubtsov</a>
40: * @author Originally published in <a
41: * href="http://www.javaworld.com/javaworld/javaqa/2003-01/01-qa-0110-timing.html">JavaWorld</a>
42: * @version $Revision: 493784 $
43: */
44: public interface ITimer {
45: /**
46: * Starts a new time interval and advances this timer instance to 'started'
47: * state. This method can be called from 'ready' state only.
48: */
49: void start();
50:
51: /**
52: * Terminates the current time interval and advances this timer instance to
53: * 'stopped' state. Interval duration will be available via
54: * {@link #getDuration()} method. This method can be called from 'started'
55: * state only.
56: */
57: void stop();
58:
59: /**
60: * Returns the duration of the time interval that elapsed between the last
61: * calls to {@link #start()} and {@link #stop()}. This method can be called
62: * any number of times from 'stopped' state and will return the same value
63: * each time.
64: *
65: * @return interval duration in milliseconds
66: */
67: double getDuration();
68:
69: /**
70: * This method can be called from any state and will reset this timer
71: * instance back to 'ready' state.
72: */
73: void reset();
74:
75: }
|