Jonathan Hart | 4b5c6dc | 2015-10-13 14:27:48 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Jonathan Hart | 4b5c6dc | 2015-10-13 14:27:48 -0700 | [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.incubator.net.intf; |
| 18 | |
| 19 | import org.onosproject.event.AbstractEvent; |
gaurav | 2c626cc | 2016-04-26 04:18:33 +0530 | [diff] [blame] | 20 | import org.joda.time.LocalDateTime; |
| 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
Jonathan Hart | 4b5c6dc | 2015-10-13 14:27:48 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Describes an interface event. |
| 25 | */ |
| 26 | public class InterfaceEvent extends AbstractEvent<InterfaceEvent.Type, Interface> { |
| 27 | |
gaurav | 2c626cc | 2016-04-26 04:18:33 +0530 | [diff] [blame] | 28 | private final Interface prevSubject; |
| 29 | |
Jonathan Hart | 4b5c6dc | 2015-10-13 14:27:48 -0700 | [diff] [blame] | 30 | public enum Type { |
| 31 | /** |
| 32 | * Indicates a new interface has been added. |
| 33 | */ |
| 34 | INTERFACE_ADDED, |
| 35 | |
| 36 | /** |
| 37 | * Indicates an interface has been updated. |
| 38 | */ |
| 39 | INTERFACE_UPDATED, |
| 40 | |
| 41 | /** |
| 42 | * Indicates an interface has been removed. |
| 43 | */ |
| 44 | INTERFACE_REMOVED |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Creates an interface event with type and subject. |
| 49 | * |
| 50 | * @param type event type |
| 51 | * @param subject subject interface |
| 52 | */ |
| 53 | public InterfaceEvent(Type type, Interface subject) { |
gaurav | 2c626cc | 2016-04-26 04:18:33 +0530 | [diff] [blame] | 54 | this(type, subject, null); |
Jonathan Hart | 4b5c6dc | 2015-10-13 14:27:48 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | /** |
gaurav | 2c626cc | 2016-04-26 04:18:33 +0530 | [diff] [blame] | 58 | * Creates an interface event with type, subject and time of event. |
Jonathan Hart | 4b5c6dc | 2015-10-13 14:27:48 -0700 | [diff] [blame] | 59 | * |
| 60 | * @param type event type |
| 61 | * @param subject subject interface |
| 62 | * @param time time of event |
| 63 | */ |
| 64 | public InterfaceEvent(Type type, Interface subject, long time) { |
gaurav | 2c626cc | 2016-04-26 04:18:33 +0530 | [diff] [blame] | 65 | this(type, subject, null, time); |
Jonathan Hart | 4b5c6dc | 2015-10-13 14:27:48 -0700 | [diff] [blame] | 66 | } |
| 67 | |
gaurav | 2c626cc | 2016-04-26 04:18:33 +0530 | [diff] [blame] | 68 | /** |
| 69 | * Creates an interface event with type, subject and previous subject. |
| 70 | * |
| 71 | * @param type event type |
| 72 | * @param subject subject interface |
Charles Chan | ab69c2c | 2016-06-13 12:06:31 -0700 | [diff] [blame^] | 73 | * @param prevSubject previous interface subject |
gaurav | 2c626cc | 2016-04-26 04:18:33 +0530 | [diff] [blame] | 74 | */ |
| 75 | public InterfaceEvent(Type type, Interface subject, Interface prevSubject) { |
| 76 | super(type, subject); |
| 77 | this.prevSubject = prevSubject; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Creates an interface event with type, subject, previous subject and time. |
| 82 | * |
| 83 | * @param type event type |
| 84 | * @param subject subject interface |
Charles Chan | ab69c2c | 2016-06-13 12:06:31 -0700 | [diff] [blame^] | 85 | * @param prevSubject previous interface subject |
gaurav | 2c626cc | 2016-04-26 04:18:33 +0530 | [diff] [blame] | 86 | * @param time time of event |
| 87 | */ |
| 88 | public InterfaceEvent(Type type, Interface subject, Interface prevSubject, long time) { |
| 89 | super(type, subject, time); |
| 90 | this.prevSubject = prevSubject; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Returns the previous interface subject. |
| 95 | * |
| 96 | * @return previous subject of interface or null if the event is not interface specific. |
| 97 | */ |
| 98 | public Interface prevSubject() { |
| 99 | return prevSubject; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public String toString() { |
| 104 | if (prevSubject == null) { |
| 105 | return super.toString(); |
| 106 | } |
| 107 | return toStringHelper(this) |
| 108 | .add("time", new LocalDateTime(time())) |
| 109 | .add("type", type()) |
| 110 | .add("subject", subject()) |
| 111 | .add("prevSubject", prevSubject) |
| 112 | .toString(); |
| 113 | } |
Jonathan Hart | 4b5c6dc | 2015-10-13 14:27:48 -0700 | [diff] [blame] | 114 | } |