gaurav
Committed by Gerrit Code Review

changes for getting the previous subject of the modified interface.

Change-Id: I7dffe0598dee92dfb8a458cb01b819df7e6a5e57
...@@ -17,12 +17,16 @@ ...@@ -17,12 +17,16 @@
17 package org.onosproject.incubator.net.intf; 17 package org.onosproject.incubator.net.intf;
18 18
19 import org.onosproject.event.AbstractEvent; 19 import org.onosproject.event.AbstractEvent;
20 +import org.joda.time.LocalDateTime;
21 +import static com.google.common.base.MoreObjects.toStringHelper;
20 22
21 /** 23 /**
22 * Describes an interface event. 24 * Describes an interface event.
23 */ 25 */
24 public class InterfaceEvent extends AbstractEvent<InterfaceEvent.Type, Interface> { 26 public class InterfaceEvent extends AbstractEvent<InterfaceEvent.Type, Interface> {
25 27
28 + private final Interface prevSubject;
29 +
26 public enum Type { 30 public enum Type {
27 /** 31 /**
28 * Indicates a new interface has been added. 32 * Indicates a new interface has been added.
...@@ -47,18 +51,64 @@ public class InterfaceEvent extends AbstractEvent<InterfaceEvent.Type, Interface ...@@ -47,18 +51,64 @@ public class InterfaceEvent extends AbstractEvent<InterfaceEvent.Type, Interface
47 * @param subject subject interface 51 * @param subject subject interface
48 */ 52 */
49 public InterfaceEvent(Type type, Interface subject) { 53 public InterfaceEvent(Type type, Interface subject) {
50 - super(type, subject); 54 + this(type, subject, null);
51 } 55 }
52 56
53 /** 57 /**
54 - * Creates an interface event with type, subject and time. 58 + * Creates an interface event with type, subject and time of event.
55 * 59 *
56 * @param type event type 60 * @param type event type
57 * @param subject subject interface 61 * @param subject subject interface
58 * @param time time of event 62 * @param time time of event
59 */ 63 */
60 public InterfaceEvent(Type type, Interface subject, long time) { 64 public InterfaceEvent(Type type, Interface subject, long time) {
65 + this(type, subject, null, time);
66 + }
67 +
68 + /**
69 + * Creates an interface event with type, subject and previous subject.
70 + *
71 + * @param type event type
72 + * @param subject subject interface
73 + * @param subject previous interface subject
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
85 + * @param subject previous interface subject
86 + * @param time time of event
87 + */
88 + public InterfaceEvent(Type type, Interface subject, Interface prevSubject, long time) {
61 super(type, subject, 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;
62 } 100 }
63 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 + }
64 } 114 }
......
...@@ -171,7 +171,7 @@ public class InterfaceManager extends ListenerRegistry<InterfaceEvent, Interface ...@@ -171,7 +171,7 @@ public class InterfaceManager extends ListenerRegistry<InterfaceEvent, Interface
171 if (oldIntf.isPresent()) { 171 if (oldIntf.isPresent()) {
172 old.remove(oldIntf.get()); 172 old.remove(oldIntf.get());
173 if (!oldIntf.get().equals(intf)) { 173 if (!oldIntf.get().equals(intf)) {
174 - process(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_UPDATED, intf)); 174 + process(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_UPDATED, intf, oldIntf.get()));
175 } 175 }
176 } else { 176 } else {
177 process(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf)); 177 process(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf));
......