blob: 7719fa14ac8a7285dcbff8e26308147ec91b6c8d [file] [log] [blame]
tom8bf2e6b2014-09-10 20:53:54 -07001package org.onlab.util;
2
3import org.jboss.netty.util.HashedWheelTimer;
4
5/**
6 * Hashed-wheel timer singleton. Care must be taken to shutdown the timer
7 * only when the VM is ready to exit.
8 */
9public final class Timer {
10
Yuta HIGUCHIf9ce4972014-10-04 22:13:47 -070011 private static volatile HashedWheelTimer timer;
tom8bf2e6b2014-09-10 20:53:54 -070012
13 // Ban public construction
14 private Timer() {
15 }
16
17 /**
18 * Returns the singleton hashed-wheel timer.
19 *
20 * @return hashed-wheel timer
21 */
22 public static HashedWheelTimer getTimer() {
23 if (Timer.timer == null) {
Yuta HIGUCHIf9ce4972014-10-04 22:13:47 -070024 initTimer();
25 }
26 return Timer.timer;
27 }
28
29 private static synchronized void initTimer() {
30 if (Timer.timer == null) {
tom8bf2e6b2014-09-10 20:53:54 -070031 Timer.timer = new HashedWheelTimer();
32 Timer.timer.start();
33 }
tom8bf2e6b2014-09-10 20:53:54 -070034 }
35
36}