1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.ehcache.util;
17
18 /***
19 * Loader for the TimeProvider implementation that will be used in SlewClock
20 * Changing this before loading the SlewClock class enables you to use some custom {@link SlewClock.TimeProvider} implementation.
21 * The default is {@link System#currentTimeMillis()}
22 *
23 * @author Alex Snaps
24 * @see SlewClock.TimeProvider
25 */
26 final class TimeProviderLoader {
27
28 private static SlewClock.TimeProvider timeProvider = new SlewClock.TimeProvider() {
29 public final long currentTimeMillis() {
30 return System.currentTimeMillis();
31 }
32 };
33
34 private TimeProviderLoader() {
35
36 }
37
38 /***
39 * Getter
40 * @return the currently set timeProvider
41 */
42 public static synchronized SlewClock.TimeProvider getTimeProvider() {
43 return timeProvider;
44 }
45
46 /***
47 * Setter, needs to be set before the {@link SlewClock} class is being loaded!
48 * @param timeProvider the {@link SlewClock.TimeProvider} implementation to use.
49 */
50 public static synchronized void setTimeProvider(final SlewClock.TimeProvider timeProvider) {
51 TimeProviderLoader.timeProvider = timeProvider;
52 }
53 }