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
Showing
4 changed files
with
31 additions
and
3 deletions
| ... | @@ -20,7 +20,10 @@ import org.onosproject.event.AbstractEvent; | ... | @@ -20,7 +20,10 @@ import org.onosproject.event.AbstractEvent; |
| 20 | import org.onosproject.net.Device; | 20 | import org.onosproject.net.Device; |
| 21 | import org.onosproject.net.Port; | 21 | import org.onosproject.net.Port; |
| 22 | 22 | ||
| 23 | +import java.util.Optional; | ||
| 24 | + | ||
| 23 | import static com.google.common.base.MoreObjects.toStringHelper; | 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED; | ||
| 24 | 27 | ||
| 25 | /** | 28 | /** |
| 26 | * Describes infrastructure device event. | 29 | * Describes infrastructure device event. |
| ... | @@ -28,6 +31,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -28,6 +31,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
| 28 | public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { | 31 | public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { |
| 29 | 32 | ||
| 30 | private final Port port; | 33 | private final Port port; |
| 34 | + private final boolean isAvailable; | ||
| 31 | 35 | ||
| 32 | /** | 36 | /** |
| 33 | * Type of device events. | 37 | * Type of device events. |
| ... | @@ -102,6 +106,20 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { | ... | @@ -102,6 +106,20 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { |
| 102 | public DeviceEvent(Type type, Device device, Port port) { | 106 | public DeviceEvent(Type type, Device device, Port port) { |
| 103 | super(type, device); | 107 | super(type, device); |
| 104 | this.port = port; | 108 | this.port = port; |
| 109 | + this.isAvailable = false; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + /** | ||
| 113 | + * Creates an event for change of device availability for the given device | ||
| 114 | + * and the current time. | ||
| 115 | + * | ||
| 116 | + * @param device event device subject | ||
| 117 | + * @param isAvailable true if device became available; false otherwise | ||
| 118 | + */ | ||
| 119 | + public DeviceEvent(Device device, boolean isAvailable) { | ||
| 120 | + super(DEVICE_AVAILABILITY_CHANGED, device); | ||
| 121 | + this.port = null; | ||
| 122 | + this.isAvailable = isAvailable; | ||
| 105 | } | 123 | } |
| 106 | 124 | ||
| 107 | /** | 125 | /** |
| ... | @@ -115,6 +133,7 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { | ... | @@ -115,6 +133,7 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { |
| 115 | public DeviceEvent(Type type, Device device, Port port, long time) { | 133 | public DeviceEvent(Type type, Device device, Port port, long time) { |
| 116 | super(type, device, time); | 134 | super(type, device, time); |
| 117 | this.port = port; | 135 | this.port = port; |
| 136 | + this.isAvailable = false; | ||
| 118 | } | 137 | } |
| 119 | 138 | ||
| 120 | /** | 139 | /** |
| ... | @@ -126,6 +145,15 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { | ... | @@ -126,6 +145,15 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { |
| 126 | return port; | 145 | return port; |
| 127 | } | 146 | } |
| 128 | 147 | ||
| 148 | + /** | ||
| 149 | + * Indicates whether device became available or unavailable. | ||
| 150 | + * | ||
| 151 | + * @return if present, true indicates device came online; false if device went offline | ||
| 152 | + */ | ||
| 153 | + public Optional<Boolean> isAvailable() { | ||
| 154 | + return type() == DEVICE_AVAILABILITY_CHANGED ? Optional.of(isAvailable) : Optional.empty(); | ||
| 155 | + } | ||
| 156 | + | ||
| 129 | @Override | 157 | @Override |
| 130 | public String toString() { | 158 | public String toString() { |
| 131 | if (port == null) { | 159 | if (port == null) { |
| ... | @@ -137,5 +165,5 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { | ... | @@ -137,5 +165,5 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { |
| 137 | .add("subject", subject()) | 165 | .add("subject", subject()) |
| 138 | .add("port", port) | 166 | .add("port", port) |
| 139 | .toString(); | 167 | .toString(); |
| 140 | - } | 168 | + } |
| 141 | } | 169 | } | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
| ... | @@ -444,7 +444,7 @@ public class GossipDeviceStore | ... | @@ -444,7 +444,7 @@ public class GossipDeviceStore |
| 444 | boolean wasOnline = availableDevices.contains(newDevice.id()); | 444 | boolean wasOnline = availableDevices.contains(newDevice.id()); |
| 445 | markOnline(newDevice.id(), newTimestamp); | 445 | markOnline(newDevice.id(), newTimestamp); |
| 446 | if (!wasOnline) { | 446 | if (!wasOnline) { |
| 447 | - notifyDelegateIfNotNull(new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, newDevice, null)); | 447 | + notifyDelegateIfNotNull(new DeviceEvent(newDevice, true)); |
| 448 | } | 448 | } |
| 449 | } | 449 | } |
| 450 | return event; | 450 | return event; |
| ... | @@ -487,7 +487,7 @@ public class GossipDeviceStore | ... | @@ -487,7 +487,7 @@ public class GossipDeviceStore |
| 487 | } | 487 | } |
| 488 | boolean removed = availableDevices.remove(deviceId); | 488 | boolean removed = availableDevices.remove(deviceId); |
| 489 | if (removed) { | 489 | if (removed) { |
| 490 | - return new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null); | 490 | + return new DeviceEvent(device, false); |
| 491 | } | 491 | } |
| 492 | return null; | 492 | return null; |
| 493 | } | 493 | } | ... | ... |
-
Please register or login to post a comment