blob: 63a95ba14c01b828a27324d48bb2bc5e08a6e74e [file] [log] [blame]
Andrea Campanella101417d2015-12-11 17:58:07 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Andrea Campanella101417d2015-12-11 17:58:07 -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.netconf.ctl;
18
19import org.onosproject.netconf.NetconfDeviceInfo;
20import org.onosproject.netconf.NetconfDeviceOutputEvent;
21import org.onosproject.netconf.NetconfDeviceOutputEventListener;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
25/**
26 * Example of a listener for events that happen a Netconf session established
27 * for a particular NETCONF device.
28 */
29public class NetconfDeviceOutputEventListenerImpl implements NetconfDeviceOutputEventListener {
30
31 private static final Logger log =
32 LoggerFactory.getLogger(NetconfDeviceOutputEventListenerImpl.class);
33
34 private NetconfDeviceInfo deviceInfo;
35
36 public NetconfDeviceOutputEventListenerImpl(NetconfDeviceInfo deviceInfo) {
37 this.deviceInfo = deviceInfo;
38 }
39
40 @Override
41 public void event(NetconfDeviceOutputEvent event) {
42 switch (event.type()) {
43 case DEVICE_REPLY:
44 log.debug("Device {} has reply: {}", deviceInfo, event.getMessagePayload());
45 break;
46 case DEVICE_NOTIFICATION:
47 log.info("Device {} has notification: {}", deviceInfo, event.getMessagePayload());
48 break;
49 case DEVICE_UNREGISTERED:
50 log.warn("Device {} has closed session", deviceInfo);
Andrea Campanella101417d2015-12-11 17:58:07 -080051 break;
52 case DEVICE_ERROR:
53 log.warn("Device {} has error: {}", deviceInfo, event.getMessagePayload());
54 break;
Andrea Campanellac3627842017-04-04 18:06:54 +020055 case SESSION_CLOSED:
56 log.warn("Device {} has closed Session: {}", deviceInfo, event.getMessagePayload());
57 break;
Andrea Campanella101417d2015-12-11 17:58:07 -080058 default:
59 log.warn("Wrong event type {} ", event.type());
60 }
61
62 }
63
64 @Override
65 public boolean isRelevant(NetconfDeviceOutputEvent event) {
66 return deviceInfo.equals(event.getDeviceInfo());
67 }
68}