Thomas Vachuska

Fixed objective tracker not to do extra work so eagerly.

Added ability to see availability status as part of device events (for availability events)

Change-Id: I4a3476e203459ed72deee45f0a24e4b4373bd819
......@@ -20,7 +20,10 @@ import org.onosproject.event.AbstractEvent;
import org.onosproject.net.Device;
import org.onosproject.net.Port;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED;
/**
* Describes infrastructure device event.
......@@ -28,6 +31,7 @@ import static com.google.common.base.MoreObjects.toStringHelper;
public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> {
private final Port port;
private final boolean isAvailable;
/**
* Type of device events.
......@@ -102,6 +106,20 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> {
public DeviceEvent(Type type, Device device, Port port) {
super(type, device);
this.port = port;
this.isAvailable = false;
}
/**
* Creates an event for change of device availability for the given device
* and the current time.
*
* @param device event device subject
* @param isAvailable true if device became available; false otherwise
*/
public DeviceEvent(Device device, boolean isAvailable) {
super(DEVICE_AVAILABILITY_CHANGED, device);
this.port = null;
this.isAvailable = isAvailable;
}
/**
......@@ -115,6 +133,7 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> {
public DeviceEvent(Type type, Device device, Port port, long time) {
super(type, device, time);
this.port = port;
this.isAvailable = false;
}
/**
......@@ -126,6 +145,15 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> {
return port;
}
/**
* Indicates whether device became available or unavailable.
*
* @return if present, true indicates device came online; false if device went offline
*/
public Optional<Boolean> isAvailable() {
return type() == DEVICE_AVAILABILITY_CHANGED ? Optional.of(isAvailable) : Optional.empty();
}
@Override
public String toString() {
if (port == null) {
......@@ -137,5 +165,5 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> {
.add("subject", subject())
.add("port", port)
.toString();
}
}
}
......
......@@ -444,7 +444,7 @@ public class GossipDeviceStore
boolean wasOnline = availableDevices.contains(newDevice.id());
markOnline(newDevice.id(), newTimestamp);
if (!wasOnline) {
notifyDelegateIfNotNull(new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, newDevice, null));
notifyDelegateIfNotNull(new DeviceEvent(newDevice, true));
}
}
return event;
......@@ -487,7 +487,7 @@ public class GossipDeviceStore
}
boolean removed = availableDevices.remove(deviceId);
if (removed) {
return new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null);
return new DeviceEvent(device, false);
}
return null;
}
......