blob: da5d51d8734869f3a4d8867a3f105bbd729f85d6 [file] [log] [blame]
Yuta HIGUCHIe3ae8212017-04-20 10:18:41 -07001/*
2 * Copyright 2017-present 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.netconf;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import org.slf4j.Logger;
21import org.slf4j.LoggerFactory;
22
23/**
24 * Listener to listen for event about specific Device.
25 */
26public class FilteringNetconfDeviceOutputEventListener
27 implements NetconfDeviceOutputEventListener {
28
29 private static final Logger log =
30 LoggerFactory.getLogger(FilteringNetconfDeviceOutputEventListener.class);
31
32 private final NetconfDeviceInfo deviceInfo;
33
34 public FilteringNetconfDeviceOutputEventListener(NetconfDeviceInfo deviceInfo) {
35 this.deviceInfo = checkNotNull(deviceInfo);
36 }
37
38 @Override
39 public void event(NetconfDeviceOutputEvent event) {
40 switch (event.type()) {
41 case DEVICE_REPLY:
42 log.debug("Device {} has reply: {}", deviceInfo, event.getMessagePayload());
43 break;
44 case DEVICE_NOTIFICATION:
45 log.info("Device {} has notification: {}", deviceInfo, event.getMessagePayload());
46 break;
47 case DEVICE_UNREGISTERED:
48 log.warn("Device {} has closed session", deviceInfo);
49 break;
50 case DEVICE_ERROR:
51 log.warn("Device {} has error: {}", deviceInfo, event.getMessagePayload());
52 break;
53 case SESSION_CLOSED:
54 log.warn("Device {} has closed Session: {}", deviceInfo, event.getMessagePayload());
55 break;
56 default:
57 log.warn("Wrong event type {} ", event.type());
58 }
59
60 }
61
62 @Override
63 public boolean isRelevant(NetconfDeviceOutputEvent event) {
64 return deviceInfo.equals(event.getDeviceInfo());
65 }
66}