Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 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; |
| 18 | |
| 19 | import org.onosproject.event.AbstractEvent; |
| 20 | |
Yuta HIGUCHI | 0454d70 | 2017-03-17 10:08:38 -0700 | [diff] [blame] | 21 | import com.google.common.base.MoreObjects; |
| 22 | |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 23 | import java.util.Optional; |
| 24 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 25 | /** |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 26 | * Describes a NETCONF device related event. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 27 | */ |
| 28 | public final class NetconfDeviceOutputEvent extends |
| 29 | AbstractEvent<NetconfDeviceOutputEvent.Type, Object> { |
| 30 | |
| 31 | private final String messagePayload; |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 32 | private final Optional<Integer> messageID; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 33 | private final NetconfDeviceInfo deviceInfo; |
| 34 | |
| 35 | /** |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 36 | * Type of device related events. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 37 | */ |
| 38 | public enum Type { |
| 39 | /** |
| 40 | * Signifies that sent a reply to a request. |
| 41 | */ |
| 42 | DEVICE_REPLY, |
| 43 | |
| 44 | /** |
| 45 | * Signifies that the device sent a notification. |
| 46 | */ |
| 47 | DEVICE_NOTIFICATION, |
| 48 | |
| 49 | /** |
| 50 | * Signifies that the device is not reachable. |
| 51 | */ |
| 52 | DEVICE_UNREGISTERED, |
| 53 | |
| 54 | /** |
| 55 | * Signifies that the device has encountered an error. |
| 56 | */ |
| 57 | DEVICE_ERROR, |
| 58 | |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 59 | /** |
| 60 | * Signifies that the device has closed the session. |
| 61 | * ONOS will try to reopen it, if it fails again |
| 62 | * it will mark the device as unreachable. |
| 63 | */ |
| 64 | SESSION_CLOSED, |
| 65 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Creates an event of a given type and for the specified subject and the |
| 70 | * current time. |
| 71 | * |
| 72 | * @param type event type |
| 73 | * @param subject event subject |
| 74 | * @param payload message from the device |
| 75 | * @param msgID id of the message related to the event |
| 76 | * @param netconfDeviceInfo device of event |
| 77 | */ |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 78 | public NetconfDeviceOutputEvent(Type type, Object subject, String payload, |
| 79 | Optional<Integer> msgID, |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 80 | NetconfDeviceInfo netconfDeviceInfo) { |
| 81 | super(type, subject); |
| 82 | messagePayload = payload; |
| 83 | this.messageID = msgID; |
| 84 | deviceInfo = netconfDeviceInfo; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Creates an event of a given type and for the specified subject and time. |
| 89 | * |
| 90 | * @param type event type |
| 91 | * @param subject event subject |
| 92 | * @param payload message from the device |
| 93 | * @param msgID id of the message related to the event |
| 94 | * @param netconfDeviceInfo device of event |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 95 | * @param time occurrence time |
| 96 | */ |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 97 | public NetconfDeviceOutputEvent(Type type, Object subject, String payload, |
| 98 | Optional<Integer> msgID, |
| 99 | NetconfDeviceInfo netconfDeviceInfo, |
| 100 | long time) { |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 101 | super(type, subject, time); |
| 102 | messagePayload = payload; |
| 103 | deviceInfo = netconfDeviceInfo; |
| 104 | this.messageID = msgID; |
| 105 | } |
| 106 | |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 107 | /** |
| 108 | * return the message payload of the reply form the device. |
| 109 | * @return reply |
| 110 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 111 | public String getMessagePayload() { |
| 112 | return messagePayload; |
| 113 | } |
| 114 | |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 115 | /** |
| 116 | * Event-related device information. |
| 117 | * @return information about the device |
| 118 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 119 | public NetconfDeviceInfo getDeviceInfo() { |
| 120 | return deviceInfo; |
| 121 | } |
| 122 | |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 123 | /** |
| 124 | * Reply messageId. |
| 125 | * @return messageId |
| 126 | */ |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 127 | public Optional<Integer> getMessageID() { |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 128 | return messageID; |
| 129 | } |
Yuta HIGUCHI | 0454d70 | 2017-03-17 10:08:38 -0700 | [diff] [blame] | 130 | |
| 131 | @Override |
| 132 | public String toString() { |
| 133 | return MoreObjects.toStringHelper(this) |
| 134 | .add("messageID", messageID) |
| 135 | .add("deviceInfo", deviceInfo) |
| 136 | .add("messagePayload", messagePayload) |
| 137 | .toString(); |
| 138 | } |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 139 | } |