tom | 8bf2e6b | 2014-09-10 20:53:54 -0700 | [diff] [blame] | 1 | package org.onlab.util; |
| 2 | |
| 3 | import 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 | */ |
| 9 | public final class Timer { |
| 10 | |
| 11 | private static HashedWheelTimer timer; |
| 12 | |
| 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) { |
| 24 | Timer.timer = new HashedWheelTimer(); |
| 25 | Timer.timer.start(); |
| 26 | } |
| 27 | return Timer.timer; |
| 28 | } |
| 29 | |
| 30 | } |