blob: 8fcb13ace3515517334e78ab77b9661b354db73e [file] [log] [blame]
Andrea Campanella49f88382017-01-30 10:37:32 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Andrea Campanella49f88382017-01-30 10:37:32 -08003 *
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
17package org.onosproject.faultmanagement.alarms.gui;
18
19import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEvent;
20import org.onosproject.incubator.net.faultmanagement.alarm.AlarmListener;
21
22/**
23 * Encapsulates the behavior of monitoring when new alarms are stored.
24 */
25public class AlarmMonitor {
26
27 private final AlarmTopovMessageHandler messageHandler;
28 private final AlarmListener alarmListener = new TopoAlarmListener();
29 private volatile boolean isMonitoring;
30
31
32 /**
33 * Constructs a traffic monitor.
34 *
35 * @param msgHandler the alarm message handler
36 */
37 public AlarmMonitor(AlarmTopovMessageHandler msgHandler) {
38 messageHandler = msgHandler;
39 messageHandler.alarmService.addListener(alarmListener);
40 }
41
42 /**
43 * Activates updating the alarms onf the GUI client.
44 */
45 protected void startMonitorig() {
46 isMonitoring = true;
47 }
48
49 /**
50 * De-activates updating the alarms onf the GUI client.
51 */
52 protected void stopMonitoring() {
53 isMonitoring = false;
54 }
55
56 //internal alarm listener
57 private class TopoAlarmListener implements AlarmListener {
58
59 @Override
60 public void event(AlarmEvent event) {
61 if (isMonitoring) {
62 messageHandler.sendAlarmHighlights();
63 }
64 }
65 }
66}