gaurav
Committed by Gerrit Code Review

changes for getting the previous subject of the modified interface.

Change-Id: I7dffe0598dee92dfb8a458cb01b819df7e6a5e57
......@@ -17,12 +17,16 @@
package org.onosproject.incubator.net.intf;
import org.onosproject.event.AbstractEvent;
import org.joda.time.LocalDateTime;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Describes an interface event.
*/
public class InterfaceEvent extends AbstractEvent<InterfaceEvent.Type, Interface> {
private final Interface prevSubject;
public enum Type {
/**
* Indicates a new interface has been added.
......@@ -47,18 +51,64 @@ public class InterfaceEvent extends AbstractEvent<InterfaceEvent.Type, Interface
* @param subject subject interface
*/
public InterfaceEvent(Type type, Interface subject) {
super(type, subject);
this(type, subject, null);
}
/**
* Creates an interface event with type, subject and time.
* Creates an interface event with type, subject and time of event.
*
* @param type event type
* @param subject subject interface
* @param time time of event
*/
public InterfaceEvent(Type type, Interface subject, long time) {
this(type, subject, null, time);
}
/**
* Creates an interface event with type, subject and previous subject.
*
* @param type event type
* @param subject subject interface
* @param subject previous interface subject
*/
public InterfaceEvent(Type type, Interface subject, Interface prevSubject) {
super(type, subject);
this.prevSubject = prevSubject;
}
/**
* Creates an interface event with type, subject, previous subject and time.
*
* @param type event type
* @param subject subject interface
* @param subject previous interface subject
* @param time time of event
*/
public InterfaceEvent(Type type, Interface subject, Interface prevSubject, long time) {
super(type, subject, time);
this.prevSubject = prevSubject;
}
/**
* Returns the previous interface subject.
*
* @return previous subject of interface or null if the event is not interface specific.
*/
public Interface prevSubject() {
return prevSubject;
}
@Override
public String toString() {
if (prevSubject == null) {
return super.toString();
}
return toStringHelper(this)
.add("time", new LocalDateTime(time()))
.add("type", type())
.add("subject", subject())
.add("prevSubject", prevSubject)
.toString();
}
}
......
......@@ -171,7 +171,7 @@ public class InterfaceManager extends ListenerRegistry<InterfaceEvent, Interface
if (oldIntf.isPresent()) {
old.remove(oldIntf.get());
if (!oldIntf.get().equals(intf)) {
process(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_UPDATED, intf));
process(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_UPDATED, intf, oldIntf.get()));
}
} else {
process(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf));
......