[ONOS-5523]ProtectedIntentsOverlay

Change-Id: Ief409aacf7e82655881f658718ac0ca50a3c8cc9
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
index bd344db..ddf64bd 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
@@ -55,8 +55,8 @@
 import org.onosproject.net.intent.IntentListener;
 import org.onosproject.net.intent.Key;
 import org.onosproject.net.intent.MultiPointToSinglePointIntent;
-import org.onosproject.net.intent.IntentState;
 import org.onosproject.net.intent.IntentService;
+import org.onosproject.net.intent.IntentState;
 import org.onosproject.net.link.LinkEvent;
 import org.onosproject.net.link.LinkListener;
 import org.onosproject.ui.JsonUtils;
@@ -124,6 +124,10 @@
     private static final String TOPO_SELECT_OVERLAY = "topoSelectOverlay";
     private static final String TOPO_STOP = "topoStop";
 
+    //Protected Intents events
+    private static final String SEL_PROTECTED_INTENT = "selectProtectedIntent";
+    private static final String CANCEL_PROTECTED_INTENT_HIGHLIGHT = "cancelProtectedIntentHighlight";
+
     // outgoing event types
     private static final String SHOW_SUMMARY = "showSummary";
     private static final String SHOW_DETAILS = "showDetails";
@@ -186,6 +190,7 @@
 
     private TopoOverlayCache overlayCache;
     private TrafficMonitor traffic;
+    private ProtectedIntentMonitor protectedIntentMonitor;
 
     private TimerTask summaryTask = null;
     private boolean summaryRunning = false;
@@ -198,6 +203,7 @@
         super.init(connection, directory);
         appId = directory.get(CoreService.class).registerApplication(MY_APP_ID);
         traffic = new TrafficMonitor(TRAFFIC_PERIOD, servicesBundle, this);
+        protectedIntentMonitor = new ProtectedIntentMonitor(TRAFFIC_PERIOD, servicesBundle, this);
     }
 
     @Override
@@ -236,8 +242,10 @@
                 new ReqPrevIntent(),
                 new ReqSelectedIntentTraffic(),
                 new SelIntent(),
+                new SelProtectedIntent(),
 
-                new CancelTraffic()
+                new CancelTraffic(),
+                new CancelProtectedIntentHighlight()
         );
     }
 
@@ -629,6 +637,23 @@
         }
     }
 
+    private final class SelProtectedIntent extends RequestHandler {
+        private SelProtectedIntent() {
+            super(SEL_PROTECTED_INTENT);
+        }
+
+        @Override
+        public void process(ObjectNode payload) {
+            Intent intent = findIntentByPayload(payload);
+            if (intent == null) {
+                log.warn("Unable to find protected intent from payload {}", payload);
+            } else {
+                log.debug("starting to monitor protected intent {}", intent.key());
+                protectedIntentMonitor.monitor(intent);
+            }
+        }
+    }
+
     private final class CancelTraffic extends RequestHandler {
         private CancelTraffic() {
             super(CANCEL_TRAFFIC);
@@ -640,6 +665,17 @@
         }
     }
 
+    private final class CancelProtectedIntentHighlight extends RequestHandler {
+        private CancelProtectedIntentHighlight() {
+            super(CANCEL_PROTECTED_INTENT_HIGHLIGHT);
+        }
+
+        @Override
+        public void process(ObjectNode payload) {
+            protectedIntentMonitor.stopMonitoring();
+        }
+    }
+
     //=======================================================================
 
     // Converts highlights to JSON format and sends the message to the client
@@ -666,7 +702,7 @@
         nodes.sort(NODE_COMPARATOR);
         for (ControllerNode node : nodes) {
             sendMessage(instanceMessage(new ClusterEvent(INSTANCE_ADDED, node),
-                    messageType));
+                                        messageType));
         }
     }
 
@@ -916,7 +952,7 @@
             String me = this.toString();
             String miniMe = me.replaceAll("^.*@", "me@");
             log.debug("Time: {}; this: {}, processing items ({} events)",
-                    now, miniMe, items.size());
+                      now, miniMe, items.size());
             // End-of-Debugging
 
             try {