blob: c2a33033df2d25d2569518b9abd77c3bfa1aa973 [file] [log] [blame]
alshabibeff00542015-09-23 13:22:33 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.pim.impl;
17
18import org.jboss.netty.util.HashedWheelTimer;
19
Rusty Eddy95421642015-10-21 17:22:13 -070020import static com.google.common.base.Preconditions.checkNotNull;
21
alshabibeff00542015-09-23 13:22:33 -070022/**
23 * PIM Timer used for PIM Neighbors.
24 */
25public final class PIMTimer {
26
27 private static volatile HashedWheelTimer timer;
28
29 // Ban public construction
30 private PIMTimer() {
31 }
32
33 /**
34 * Returns the singleton hashed-wheel timer.
35 *
36 * @return hashed-wheel timer
37 */
38 public static HashedWheelTimer getTimer() {
39 if (PIMTimer.timer == null) {
40 initTimer();
41 }
42 return PIMTimer.timer;
43 }
44
45 // Start the PIM timer.
46 private static synchronized void initTimer() {
47 if (PIMTimer.timer == null) {
48
49 // Create and start a new hashed wheel timer, if it does not exist.
50 HashedWheelTimer hwTimer = new HashedWheelTimer();
51 hwTimer.start();
52 PIMTimer.timer = hwTimer;
53 }
54 }
Rusty Eddy95421642015-10-21 17:22:13 -070055
56 public static void start() {
57 if (PIMTimer.timer == null) {
58 getTimer();
59 }
60 checkNotNull(timer);
61 timer.start();
62 }
63
64 public static void stop() {
65 if (PIMTimer.timer == null) {
66 // No need to stop
67 return;
68 }
69 checkNotNull(timer);
70 timer.stop();
71 }
alshabibeff00542015-09-23 13:22:33 -070072}