Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | |
| 17 | package org.onosproject.netconf.ctl; |
| 18 | |
| 19 | import org.onosproject.netconf.NetconfDeviceInfo; |
| 20 | import org.onosproject.netconf.NetconfDeviceOutputEvent; |
| 21 | import org.onosproject.netconf.NetconfDeviceOutputEventListener; |
| 22 | import org.slf4j.Logger; |
| 23 | import 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 | */ |
| 29 | public 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); |
| 51 | //TODO tell onos about closed session |
| 52 | break; |
| 53 | case DEVICE_ERROR: |
| 54 | log.warn("Device {} has error: {}", 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 | } |