ONOS-3539 Insert optional delay for showing highlights
Change-Id: I289d54fc2b401da397fa97e912e98177d108df23
diff --git a/core/api/src/main/java/org/onosproject/ui/topo/Highlights.java b/core/api/src/main/java/org/onosproject/ui/topo/Highlights.java
index 12d3b62..909bbbb 100644
--- a/core/api/src/main/java/org/onosproject/ui/topo/Highlights.java
+++ b/core/api/src/main/java/org/onosproject/ui/topo/Highlights.java
@@ -16,6 +16,8 @@
package org.onosproject.ui.topo;
+import com.google.common.base.Preconditions;
+
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -34,6 +36,7 @@
private static final String MIN = "min";
private static final String MAX = "max";
+
/**
* A notion of amount.
*/
@@ -43,6 +46,7 @@
MAXIMALLY(MAX);
private final String s;
+
Amount(String str) {
s = str;
}
@@ -58,7 +62,30 @@
private final Map<String, LinkHighlight> links = new HashMap<>();
private Amount subdueLevel = Amount.ZERO;
+ private int delayMs = 0;
+ //TODO: Think of a better solution for topology events race conditions
+ /**
+ * Sets the number of milliseconds to delay processing of highlights
+ * events on the client side.
+ *
+ * @param ms milliseconds to delay
+ * @return self, for chaining
+ */
+ public Highlights delay(int ms) {
+ Preconditions.checkArgument(ms >= 0, "Delay cannot be lower than 0");
+ delayMs = ms;
+ return this;
+ }
+
+ /**
+ * Return the delay for the highlight event.
+ *
+ * @return delay in milliseconds
+ */
+ public int delayMs() {
+ return delayMs;
+ }
/**
* Adds highlighting information for a device.
@@ -186,4 +213,5 @@
public LinkHighlight getLink(String id) {
return links.get(id);
}
+
}
diff --git a/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java b/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java
index efe69f5..bd07d6c 100644
--- a/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java
+++ b/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java
@@ -33,6 +33,7 @@
static final String HOSTS = "hosts";
static final String LINKS = "links";
static final String SUBDUE = "subdue";
+ static final String DELAY = "delay";
static final String ID = "id";
static final String LABEL = "label";
@@ -99,6 +100,10 @@
if (!toSubdue.equals(Highlights.Amount.ZERO)) {
payload.put(SUBDUE, toSubdue.toString());
}
+ int delay = highlights.delayMs();
+ if (delay > 0) {
+ payload.put(DELAY, delay);
+ }
return payload;
}
diff --git a/web/gui/src/main/webapp/app/view/topo/topoOverlay.js b/web/gui/src/main/webapp/app/view/topo/topoOverlay.js
index fb7921a..d8a0454 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoOverlay.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoOverlay.js
@@ -30,7 +30,7 @@
var tos = 'TopoOverlayService: ';
// injected refs
- var $log, fs, gs, wss, ns, tss, tps, api;
+ var $log, $timeout, fs, gs, wss, ns, tss, tps, api;
// internal state
var overlays = {},
@@ -280,7 +280,20 @@
tss = _tss_;
}
+ //process highlight event with optional delay
function showHighlights(data) {
+ function doHighlight() {
+ _showHighlights(data);
+ }
+
+ if (data.delay) {
+ $timeout(doHighlight, data.delay);
+ } else {
+ doHighlight();
+ }
+ }
+
+ function _showHighlights(data) {
var less;
/*
@@ -341,7 +354,6 @@
var ldata = api.findLinkById(link.id),
lab = link.label,
units, portcls, magnitude;
-
if (ldata && !ldata.el.empty()) {
if (!link.subdue) {
api.unsupLink(ldata.key, less);
@@ -375,11 +387,12 @@
angular.module('ovTopo')
.factory('TopoOverlayService',
- ['$log', 'FnService', 'GlyphService', 'WebSocketService', 'NavService',
- 'TopoPanelService',
+ ['$log', '$timeout', 'FnService', 'GlyphService', 'WebSocketService',
+ 'NavService', 'TopoPanelService',
- function (_$log_, _fs_, _gs_, _wss_, _ns_, _tps_) {
+ function (_$log_, _$timeout_, _fs_, _gs_, _wss_, _ns_, _tps_) {
$log = _$log_;
+ $timeout = _$timeout_;
fs = _fs_;
gs = _gs_;
wss = _wss_;