Jian Li | 38e4d94 | 2018-07-03 22:19:16 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | package org.onosproject.openstackvtap.api; |
| 17 | |
| 18 | import org.onlab.util.Tools; |
| 19 | import org.onosproject.event.AbstractEvent; |
| 20 | |
| 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | |
| 23 | /** |
| 24 | * Describes vTap event. |
| 25 | */ |
| 26 | public class OpenstackVtapEvent extends AbstractEvent<OpenstackVtapEvent.Type, OpenstackVtap> { |
| 27 | |
| 28 | /** |
| 29 | * Type of vTap events. |
| 30 | */ |
| 31 | public enum Type { |
| 32 | |
| 33 | /** |
| 34 | * Signifies that a new vTap has been added. |
| 35 | */ |
| 36 | VTAP_ADDED, |
| 37 | |
| 38 | /** |
| 39 | * Signifies that a vTap has been removed. |
| 40 | */ |
| 41 | VTAP_REMOVED, |
| 42 | |
| 43 | /** |
| 44 | * Signifies that a vTap data changed. |
| 45 | */ |
| 46 | VTAP_UPDATED, |
| 47 | } |
| 48 | |
| 49 | private OpenstackVtap prevSubject; |
| 50 | |
| 51 | /** |
| 52 | * Creates an event of a given type and for the specified vTap and the |
| 53 | * current time. |
| 54 | * |
| 55 | * @param type vTap event type |
| 56 | * @param vTap event vTap subject |
| 57 | */ |
| 58 | public OpenstackVtapEvent(Type type, OpenstackVtap vTap) { |
| 59 | super(type, vTap); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Creates an event of a given type and for the specified vTap and time. |
| 64 | * |
| 65 | * @param type vTap event type |
| 66 | * @param vTap event vTap subject |
| 67 | * @param time occurrence time |
| 68 | */ |
| 69 | public OpenstackVtapEvent(Type type, OpenstackVtap vTap, long time) { |
| 70 | super(type, vTap, time); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Creates an event with previous subject. |
| 75 | * |
| 76 | * The previous subject is ignored if the type is not moved or updated |
| 77 | * |
| 78 | * @param type vTap event type |
| 79 | * @param vTap event vTap subject |
| 80 | * @param prevSubject previous vTap subject |
| 81 | */ |
| 82 | public OpenstackVtapEvent(Type type, OpenstackVtap vTap, OpenstackVtap prevSubject) { |
| 83 | super(type, vTap); |
| 84 | if (type == Type.VTAP_UPDATED) { |
| 85 | this.prevSubject = prevSubject; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Gets the previous subject in this vTap event. |
| 91 | * |
| 92 | * @return the previous subject, or null if previous subject is not |
| 93 | * specified. |
| 94 | */ |
| 95 | public OpenstackVtap prevSubject() { |
| 96 | return this.prevSubject; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String toString() { |
| 101 | return toStringHelper(this) |
| 102 | .add("time", Tools.defaultOffsetDataTime(time())) |
| 103 | .add("type", type()) |
| 104 | .add("subject", subject()) |
| 105 | .add("prevSubject", prevSubject()) |
| 106 | .toString(); |
| 107 | } |
| 108 | } |