mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-18 10:51:04 +02:00
Carry previous location information in HostEvent
Change-Id: I06957d368a8a547cc3adb36bce4aaf96c432f4c8
This commit is contained in:
parent
0fc6134f16
commit
ec0425c18c
@ -15,8 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.onosproject.net.host;
|
package org.onosproject.net.host;
|
||||||
|
|
||||||
|
import org.joda.time.LocalDateTime;
|
||||||
import org.onosproject.event.AbstractEvent;
|
import org.onosproject.event.AbstractEvent;
|
||||||
import org.onosproject.net.Host;
|
import org.onosproject.net.Host;
|
||||||
|
import org.onosproject.net.HostLocation;
|
||||||
|
|
||||||
|
import static com.google.common.base.MoreObjects.toStringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes end-station host event.
|
* Describes end-station host event.
|
||||||
@ -48,6 +52,8 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> {
|
|||||||
HOST_MOVED
|
HOST_MOVED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HostLocation prevLocation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an event of a given type and for the specified host and the
|
* Creates an event of a given type and for the specified host and the
|
||||||
* current time.
|
* current time.
|
||||||
@ -70,4 +76,35 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> {
|
|||||||
super(type, host, time);
|
super(type, host, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an event with HOST_MOVED type along with the previous location
|
||||||
|
* of the host.
|
||||||
|
*
|
||||||
|
* @param host event host subject
|
||||||
|
* @param prevLocation previous location of the host
|
||||||
|
*/
|
||||||
|
public HostEvent(Host host, HostLocation prevLocation) {
|
||||||
|
super(Type.HOST_MOVED, host);
|
||||||
|
this.prevLocation = prevLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the previous location information in this host event.
|
||||||
|
*
|
||||||
|
* @return the previous location, or null if previous location is not
|
||||||
|
* specified.
|
||||||
|
*/
|
||||||
|
public HostLocation prevLocation() {
|
||||||
|
return this.prevLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return toStringHelper(this)
|
||||||
|
.add("time", new LocalDateTime(time()))
|
||||||
|
.add("type", type())
|
||||||
|
.add("subject", subject())
|
||||||
|
.add("prevLocation", prevLocation())
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkState;
|
|||||||
import static org.onosproject.net.DefaultAnnotations.merge;
|
import static org.onosproject.net.DefaultAnnotations.merge;
|
||||||
import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED;
|
import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED;
|
||||||
import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED;
|
import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED;
|
||||||
import static org.onosproject.net.host.HostEvent.Type.HOST_MOVED;
|
|
||||||
import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED;
|
import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED;
|
||||||
import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT;
|
import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT;
|
||||||
import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE;
|
import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE;
|
||||||
@ -89,7 +88,7 @@ public class ECHostStore
|
|||||||
|
|
||||||
private EventuallyConsistentMap<HostId, DefaultHost> hosts;
|
private EventuallyConsistentMap<HostId, DefaultHost> hosts;
|
||||||
|
|
||||||
private final ConcurrentHashMap<HostId, ConnectPoint> locations =
|
private final ConcurrentHashMap<HostId, HostLocation> locations =
|
||||||
new ConcurrentHashMap<>();
|
new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private EventuallyConsistentMapListener<HostId, DefaultHost> hostLocationTracker =
|
private EventuallyConsistentMapListener<HostId, DefaultHost> hostLocationTracker =
|
||||||
@ -254,11 +253,11 @@ public class ECHostStore
|
|||||||
public void event(EventuallyConsistentMapEvent<HostId, DefaultHost> event) {
|
public void event(EventuallyConsistentMapEvent<HostId, DefaultHost> event) {
|
||||||
DefaultHost host = checkNotNull(event.value());
|
DefaultHost host = checkNotNull(event.value());
|
||||||
if (event.type() == PUT) {
|
if (event.type() == PUT) {
|
||||||
ConnectPoint prevLocation = locations.put(host.id(), host.location());
|
HostLocation prevLocation = locations.put(host.id(), host.location());
|
||||||
if (prevLocation == null) {
|
if (prevLocation == null) {
|
||||||
notifyDelegate(new HostEvent(HOST_ADDED, host));
|
notifyDelegate(new HostEvent(HOST_ADDED, host));
|
||||||
} else if (!Objects.equals(prevLocation, host.location())) {
|
} else if (!Objects.equals(prevLocation, host.location())) {
|
||||||
notifyDelegate(new HostEvent(HOST_MOVED, host));
|
notifyDelegate(new HostEvent(host, prevLocation));
|
||||||
} else {
|
} else {
|
||||||
notifyDelegate(new HostEvent(HOST_UPDATED, host));
|
notifyDelegate(new HostEvent(HOST_UPDATED, host));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user