GUI -- Further work on refactoring Topology View server side code.
- includes some cleanup of UiMessageHandler and subclasses thereof.
Change-Id: Ie48d830447a4abe1b3accda41a934530a4d55d0e
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopoUiModelManager.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopoUiModelManager.java
index 7cb0e40..3a3bf68 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopoUiModelManager.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopoUiModelManager.java
@@ -50,6 +50,8 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
import static org.onosproject.cluster.ClusterEvent.Type.INSTANCE_ADDED;
import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED;
@@ -67,6 +69,9 @@
@Service
public class TopoUiModelManager implements TopoUiModelService {
+ // TODO: put back to 30,000 ms for production
+ private static final long SUMMARY_PERIOD = 15_000;
+
private final Logger log = LoggerFactory.getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -105,6 +110,11 @@
private final TopoMessageFactory messageFactory = new TopoMessageFactory();
private final MetaDb metaDb = new MetaDb();
+ private final Timer timer = new Timer("topology-view");
+
+ private TimerTask summaryTask = null;
+ private boolean summaryRunning = false;
+
@Activate
public void activate() {
@@ -135,7 +145,8 @@
// causes the listener (for an AltTopoViewMessageHandler instance) to
// be removed.
// ==== Somehow need to tie this in to the GUI-disconnected event.
-
+ // This probably requires client-generated heartbeat messages to
+ // Keep the connection alive.
@Override
@@ -159,16 +170,32 @@
}
@Override
- public void startSummaryMonitoring() {
- // TODO: set up periodic monitoring task
- // send a summary now, and periodically...
- post(new TopoUiEvent(SUMMARY_UPDATE, null));
+ public synchronized void startSummaryMonitoring() {
+ // first, cancel previous task if not canceled already
+ stopSummaryMonitoring();
+
+ // create and start a summary task, to execute with no delay, and
+ // every SUMMARY_PERIOD milliseconds thereafter.
+ summaryTask = new TimerTask() {
+ @Override
+ public void run() {
+ if (summaryRunning) {
+ post(new TopoUiEvent(SUMMARY_UPDATE, null));
+ }
+ }
+ };
+
+ timer.schedule(summaryTask, 0, SUMMARY_PERIOD);
+ summaryRunning = true;
}
@Override
- public void stopSummaryMonitoring() {
- // TODO: cancel monitoring task
-
+ public synchronized void stopSummaryMonitoring() {
+ if (summaryTask != null) {
+ summaryTask.cancel();
+ summaryTask = null;
+ }
+ summaryRunning = false;
}
@Override