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: * This non-instantiable non-extendible class acts as a Factory for
23: * {@link ITimer} implementations.
24: *
25: * @author <a href="mailto:vroubtsov@illinoisalumni.org">Vlad Roubtsov</a>
26: * @author Originally published in <a
27: * href="http://www.javaworld.com/javaworld/javaqa/2003-01/01-qa-0110-timing.html">JavaWorld</a>
28: * @version $Revision: 493784 $
29: */
30: public final class TimerFactory {
31: /**
32: * Creates a new instance of {@link ITimer} which is returned in 'ready'
33: * state. If the JNI-based/high-resolution implementation is not available
34: * this will return an instance of <code>JavaSystemTimer</code>, so this
35: * method is guaranteed not to fail.
36: *
37: * @return ITimer a new timer instance in 'ready' state [never null]
38: */
39: public static ITimer newTimer() {
40: try {
41: return new HRTimer();
42: } catch (Throwable t) {
43: return new JavaSystemTimer();
44: }
45: }
46:
47: /**
48: * Private default constructor to prevent instantiation.
49: */
50: private TimerFactory() {
51: }
52: }
|