From a0ddb02bd641e54c88659cbfbeef39fa62d69c04 Mon Sep 17 00:00:00 2001 From: Simon Hunt Date: Fri, 1 May 2015 09:53:01 -0700 Subject: [PATCH] GUI -- Rename UIMessageHandlerTwo => UIMessageHandler. Also, make bindHandlers() private. Change-Id: Id36e220c1285b88b8b4db0e106ef063bd8b9bfd1 --- .../onosproject/intentperf/IntentPerfUi.java | 6 +- .../org/onosproject/ui/RequestHandler.java | 6 +- ...eHandlerTwo.java => UiMessageHandler.java} | 27 ++++---- .../ui/UiMessageHandlerFactory.java | 2 +- .../impl/ApplicationViewMessageHandler.java | 4 +- .../ui/impl/ClusterViewMessageHandler.java | 4 +- .../ui/impl/DeviceViewMessageHandler.java | 4 +- .../ui/impl/FlowViewMessageHandler.java | 4 +- .../ui/impl/HostViewMessageHandler.java | 4 +- .../ui/impl/IntentViewMessageHandler.java | 4 +- .../ui/impl/LinkViewMessageHandler.java | 4 +- .../impl/TopologyViewMessageHandlerBase.java | 68 +++++++++---------- .../org/onosproject/ui/impl/UiWebSocket.java | 6 +- 13 files changed, 70 insertions(+), 73 deletions(-) rename core/api/src/main/java/org/onosproject/ui/{UiMessageHandlerTwo.java => UiMessageHandler.java} (96%) diff --git a/apps/test/intent-perf/src/main/java/org/onosproject/intentperf/IntentPerfUi.java b/apps/test/intent-perf/src/main/java/org/onosproject/intentperf/IntentPerfUi.java index b3280c80cf..7118ee1bf7 100644 --- a/apps/test/intent-perf/src/main/java/org/onosproject/intentperf/IntentPerfUi.java +++ b/apps/test/intent-perf/src/main/java/org/onosproject/intentperf/IntentPerfUi.java @@ -31,7 +31,7 @@ import org.onosproject.ui.RequestHandler; import org.onosproject.ui.UiConnection; import org.onosproject.ui.UiExtension; import org.onosproject.ui.UiExtensionService; -import org.onosproject.ui.UiMessageHandlerTwo; +import org.onosproject.ui.UiMessageHandler; import org.onosproject.ui.UiView; import java.util.Collection; @@ -97,13 +97,13 @@ public class IntentPerfUi { } // Creates and returns session specific message handler. - private Collection newHandlers() { + private Collection newHandlers() { return ImmutableList.of(new StreamingControl()); } // UI Message handlers for turning on/off reporting to a session. - private class StreamingControl extends UiMessageHandlerTwo { + private class StreamingControl extends UiMessageHandler { private boolean streamingEnabled = false; diff --git a/core/api/src/main/java/org/onosproject/ui/RequestHandler.java b/core/api/src/main/java/org/onosproject/ui/RequestHandler.java index 7231dcf767..51a803a943 100644 --- a/core/api/src/main/java/org/onosproject/ui/RequestHandler.java +++ b/core/api/src/main/java/org/onosproject/ui/RequestHandler.java @@ -22,14 +22,14 @@ import com.fasterxml.jackson.databind.node.ObjectNode; * Abstraction of an entity that handles a specific request from the * user interface client. * - * @see UiMessageHandlerTwo + * @see UiMessageHandler */ public abstract class RequestHandler { protected static final ObjectMapper MAPPER = new ObjectMapper(); private final String eventType; - private UiMessageHandlerTwo parent; + private UiMessageHandler parent; public RequestHandler(String eventType) { @@ -37,7 +37,7 @@ public abstract class RequestHandler { } // package private - void setParent(UiMessageHandlerTwo parent) { + void setParent(UiMessageHandler parent) { this.parent = parent; } diff --git a/core/api/src/main/java/org/onosproject/ui/UiMessageHandlerTwo.java b/core/api/src/main/java/org/onosproject/ui/UiMessageHandler.java similarity index 96% rename from core/api/src/main/java/org/onosproject/ui/UiMessageHandlerTwo.java rename to core/api/src/main/java/org/onosproject/ui/UiMessageHandler.java index 915bcafa73..2f70780def 100644 --- a/core/api/src/main/java/org/onosproject/ui/UiMessageHandlerTwo.java +++ b/core/api/src/main/java/org/onosproject/ui/UiMessageHandler.java @@ -44,7 +44,7 @@ import static com.google.common.base.Preconditions.checkNotNull; * } * */ -public abstract class UiMessageHandlerTwo { +public abstract class UiMessageHandler { private final Map handlerMap = new HashMap<>(); @@ -56,20 +56,6 @@ public abstract class UiMessageHandlerTwo { */ protected final ObjectMapper mapper = new ObjectMapper(); - /** - * Binds the handlers returned from {@link #getHandlers()} to this - * instance. - */ - void bindHandlers() { - Collection handlers = getHandlers(); - checkNotNull(handlers, "Handlers cannot be null"); - checkArgument(!handlers.isEmpty(), "Handlers cannot be empty"); - - for (RequestHandler h : handlers) { - h.setParent(this); - handlerMap.put(h.eventType(), h); - } - } /** * Subclasses must return the collection of handlers for the @@ -115,6 +101,17 @@ public abstract class UiMessageHandlerTwo { } } + private void bindHandlers() { + Collection handlers = getHandlers(); + checkNotNull(handlers, "Handlers cannot be null"); + checkArgument(!handlers.isEmpty(), "Handlers cannot be empty"); + + for (RequestHandler h : handlers) { + h.setParent(this); + handlerMap.put(h.eventType(), h); + } + } + /** * Initializes the handler with the user interface connection and * service directory context. diff --git a/core/api/src/main/java/org/onosproject/ui/UiMessageHandlerFactory.java b/core/api/src/main/java/org/onosproject/ui/UiMessageHandlerFactory.java index 23bd5d4faf..522daa8f97 100644 --- a/core/api/src/main/java/org/onosproject/ui/UiMessageHandlerFactory.java +++ b/core/api/src/main/java/org/onosproject/ui/UiMessageHandlerFactory.java @@ -28,6 +28,6 @@ public interface UiMessageHandlerFactory { * * @return collection of new handlers */ - Collection newHandlers(); + Collection newHandlers(); } diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/ApplicationViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/ApplicationViewMessageHandler.java index 2924c8bab9..f7124e191d 100644 --- a/web/gui/src/main/java/org/onosproject/ui/impl/ApplicationViewMessageHandler.java +++ b/web/gui/src/main/java/org/onosproject/ui/impl/ApplicationViewMessageHandler.java @@ -23,7 +23,7 @@ import org.onosproject.app.ApplicationState; import org.onosproject.core.Application; import org.onosproject.core.ApplicationId; import org.onosproject.ui.RequestHandler; -import org.onosproject.ui.UiMessageHandlerTwo; +import org.onosproject.ui.UiMessageHandler; import org.onosproject.ui.table.AbstractTableRow; import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.TableRow; @@ -39,7 +39,7 @@ import static org.onosproject.app.ApplicationState.ACTIVE; /** * Message handler for application view related messages. */ -public class ApplicationViewMessageHandler extends UiMessageHandlerTwo { +public class ApplicationViewMessageHandler extends UiMessageHandler { private static final String APP_DATA_REQ = "appDataRequest"; private static final String APP_MGMT_REQ = "appManagementRequest"; diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/ClusterViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/ClusterViewMessageHandler.java index ee2dcd593f..209b98e041 100644 --- a/web/gui/src/main/java/org/onosproject/ui/impl/ClusterViewMessageHandler.java +++ b/web/gui/src/main/java/org/onosproject/ui/impl/ClusterViewMessageHandler.java @@ -24,7 +24,7 @@ import org.onosproject.cluster.ClusterService; import org.onosproject.cluster.ControllerNode; import org.onosproject.cluster.NodeId; import org.onosproject.ui.RequestHandler; -import org.onosproject.ui.UiMessageHandlerTwo; +import org.onosproject.ui.UiMessageHandler; import org.onosproject.ui.table.AbstractTableRow; import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.TableRow; @@ -39,7 +39,7 @@ import java.util.stream.Collectors; /** * Message handler for cluster view related messages. */ -public class ClusterViewMessageHandler extends UiMessageHandlerTwo { +public class ClusterViewMessageHandler extends UiMessageHandler { private static final String CLUSTER_DATA_REQ = "clusterDataRequest"; diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java index 302863b865..2e8336cd01 100644 --- a/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java +++ b/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java @@ -28,7 +28,7 @@ import org.onosproject.net.Port; import org.onosproject.net.device.DeviceService; import org.onosproject.net.link.LinkService; import org.onosproject.ui.RequestHandler; -import org.onosproject.ui.UiMessageHandlerTwo; +import org.onosproject.ui.UiMessageHandler; import org.onosproject.ui.table.AbstractTableRow; import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.TableRow; @@ -44,7 +44,7 @@ import java.util.Set; /** * Message handler for device view related messages. */ -public class DeviceViewMessageHandler extends UiMessageHandlerTwo { +public class DeviceViewMessageHandler extends UiMessageHandler { private static final String DEV_DATA_REQ = "deviceDataRequest"; private static final String DEV_DETAIL_REQ = "deviceDetailRequest"; diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java index 0ad1d70ce1..dc9e8989a7 100644 --- a/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java +++ b/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java @@ -27,7 +27,7 @@ import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.criteria.Criterion; import org.onosproject.net.flow.instructions.Instruction; import org.onosproject.ui.RequestHandler; -import org.onosproject.ui.UiMessageHandlerTwo; +import org.onosproject.ui.UiMessageHandler; import org.onosproject.ui.table.AbstractTableRow; import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.TableRow; @@ -43,7 +43,7 @@ import java.util.Set; /** * Message handler for flow view related messages. */ -public class FlowViewMessageHandler extends UiMessageHandlerTwo { +public class FlowViewMessageHandler extends UiMessageHandler { private static final String FLOW_DATA_REQ = "flowDataRequest"; diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/HostViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/HostViewMessageHandler.java index a4127e0564..42d7a1e8c0 100644 --- a/web/gui/src/main/java/org/onosproject/ui/impl/HostViewMessageHandler.java +++ b/web/gui/src/main/java/org/onosproject/ui/impl/HostViewMessageHandler.java @@ -22,7 +22,7 @@ import org.onosproject.net.Host; import org.onosproject.net.HostLocation; import org.onosproject.net.host.HostService; import org.onosproject.ui.RequestHandler; -import org.onosproject.ui.UiMessageHandlerTwo; +import org.onosproject.ui.UiMessageHandler; import org.onosproject.ui.table.AbstractTableRow; import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.TableRow; @@ -38,7 +38,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; /** * Message handler for host view related messages. */ -public class HostViewMessageHandler extends UiMessageHandlerTwo { +public class HostViewMessageHandler extends UiMessageHandler { private static final String HOST_DATA_REQ = "hostDataRequest"; diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/IntentViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/IntentViewMessageHandler.java index 539430a8e8..356b8b06f7 100644 --- a/web/gui/src/main/java/org/onosproject/ui/impl/IntentViewMessageHandler.java +++ b/web/gui/src/main/java/org/onosproject/ui/impl/IntentViewMessageHandler.java @@ -32,7 +32,7 @@ import org.onosproject.net.intent.PathIntent; import org.onosproject.net.intent.PointToPointIntent; import org.onosproject.net.intent.SinglePointToMultiPointIntent; import org.onosproject.ui.RequestHandler; -import org.onosproject.ui.UiMessageHandlerTwo; +import org.onosproject.ui.UiMessageHandler; import org.onosproject.ui.table.AbstractTableRow; import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.TableRow; @@ -47,7 +47,7 @@ import java.util.Set; /** * Message handler for intent view related messages. */ -public class IntentViewMessageHandler extends UiMessageHandlerTwo { +public class IntentViewMessageHandler extends UiMessageHandler { private static final String INTENT_DATA_REQ = "intentDataRequest"; diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/LinkViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/LinkViewMessageHandler.java index 55291c4927..06349b485f 100644 --- a/web/gui/src/main/java/org/onosproject/ui/impl/LinkViewMessageHandler.java +++ b/web/gui/src/main/java/org/onosproject/ui/impl/LinkViewMessageHandler.java @@ -24,7 +24,7 @@ import org.onosproject.net.Link; import org.onosproject.net.LinkKey; import org.onosproject.net.link.LinkService; import org.onosproject.ui.RequestHandler; -import org.onosproject.ui.UiMessageHandlerTwo; +import org.onosproject.ui.UiMessageHandler; import org.onosproject.ui.impl.TopologyViewMessageHandlerBase.BiLink; import org.onosproject.ui.table.AbstractTableRow; import org.onosproject.ui.table.RowComparator; @@ -42,7 +42,7 @@ import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.addLink; /** * Message handler for link view related messages. */ -public class LinkViewMessageHandler extends UiMessageHandlerTwo { +public class LinkViewMessageHandler extends UiMessageHandler { private static final String LINK_DATA_REQ = "linkDataRequest"; diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java index e0a91641cc..6f72dcb7a4 100644 --- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java +++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java @@ -65,7 +65,7 @@ import org.onosproject.net.topology.Topology; import org.onosproject.net.topology.TopologyService; import org.onosproject.ui.JsonUtils; import org.onosproject.ui.UiConnection; -import org.onosproject.ui.UiMessageHandlerTwo; +import org.onosproject.ui.UiMessageHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,7 +101,7 @@ import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED; /** * Facility for creating messages bound for the topology viewer. */ -public abstract class TopologyViewMessageHandlerBase extends UiMessageHandlerTwo { +public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { protected static final Logger log = LoggerFactory.getLogger(TopologyViewMessageHandlerBase.class); @@ -420,15 +420,15 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandlerTwo protected ObjectNode summmaryMessage(long sid) { Topology topology = topologyService.currentTopology(); return JsonUtils.envelope("showSummary", sid, - json("ONOS Summary", "node", - new Prop("Devices", format(topology.deviceCount())), - new Prop("Links", format(topology.linkCount())), - new Prop("Hosts", format(hostService.getHostCount())), - new Prop("Topology SCCs", format(topology.clusterCount())), - new Separator(), - new Prop("Intents", format(intentService.getIntentCount())), - new Prop("Flows", format(flowService.getFlowRuleCount())), - new Prop("Version", version))); + json("ONOS Summary", "node", + new Prop("Devices", format(topology.deviceCount())), + new Prop("Links", format(topology.linkCount())), + new Prop("Hosts", format(hostService.getHostCount())), + new Prop("Topology SCCs", format(topology.clusterCount())), + new Separator(), + new Prop("Intents", format(intentService.getIntentCount())), + new Prop("Flows", format(flowService.getFlowRuleCount())), + new Prop("Version", version))); } // Returns device details response. @@ -439,21 +439,21 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandlerTwo int portCount = deviceService.getPorts(deviceId).size(); int flowCount = getFlowCount(deviceId); return JsonUtils.envelope("showDetails", sid, - json(isNullOrEmpty(name) ? deviceId.toString() : name, - device.type().toString().toLowerCase(), - new Prop("URI", deviceId.toString()), - new Prop("Vendor", device.manufacturer()), - new Prop("H/W Version", device.hwVersion()), - new Prop("S/W Version", device.swVersion()), - new Prop("Serial Number", device.serialNumber()), - new Prop("Protocol", annot.value(AnnotationKeys.PROTOCOL)), - new Separator(), - new Prop("Master", master(deviceId)), - new Prop("Latitude", annot.value(AnnotationKeys.LATITUDE)), - new Prop("Longitude", annot.value(AnnotationKeys.LONGITUDE)), - new Separator(), - new Prop("Ports", Integer.toString(portCount)), - new Prop("Flows", Integer.toString(flowCount)))); + json(isNullOrEmpty(name) ? deviceId.toString() : name, + device.type().toString().toLowerCase(), + new Prop("URI", deviceId.toString()), + new Prop("Vendor", device.manufacturer()), + new Prop("H/W Version", device.hwVersion()), + new Prop("S/W Version", device.swVersion()), + new Prop("Serial Number", device.serialNumber()), + new Prop("Protocol", annot.value(AnnotationKeys.PROTOCOL)), + new Separator(), + new Prop("Master", master(deviceId)), + new Prop("Latitude", annot.value(AnnotationKeys.LATITUDE)), + new Prop("Longitude", annot.value(AnnotationKeys.LONGITUDE)), + new Separator(), + new Prop("Ports", Integer.toString(portCount)), + new Prop("Flows", Integer.toString(flowCount)))); } protected int getFlowCount(DeviceId deviceId) { @@ -517,14 +517,14 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandlerTwo String name = annot.value(AnnotationKeys.NAME); String vlan = host.vlan().toString(); return JsonUtils.envelope("showDetails", sid, - json(isNullOrEmpty(name) ? hostId.toString() : name, - isNullOrEmpty(type) ? "endstation" : type, - new Prop("MAC", host.mac().toString()), - new Prop("IP", host.ipAddresses().toString().replaceAll("[\\[\\]]", "")), - new Prop("VLAN", vlan.equals("-1") ? "none" : vlan), - new Separator(), - new Prop("Latitude", annot.value(AnnotationKeys.LATITUDE)), - new Prop("Longitude", annot.value(AnnotationKeys.LONGITUDE)))); + json(isNullOrEmpty(name) ? hostId.toString() : name, + isNullOrEmpty(type) ? "endstation" : type, + new Prop("MAC", host.mac().toString()), + new Prop("IP", host.ipAddresses().toString().replaceAll("[\\[\\]]", "")), + new Prop("VLAN", vlan.equals("-1") ? "none" : vlan), + new Separator(), + new Prop("Latitude", annot.value(AnnotationKeys.LATITUDE)), + new Prop("Longitude", annot.value(AnnotationKeys.LONGITUDE)))); } diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java b/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java index d756da094f..3295b9ec85 100644 --- a/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java +++ b/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java @@ -25,7 +25,7 @@ import org.onosproject.cluster.ControllerNode; import org.onosproject.ui.UiConnection; import org.onosproject.ui.UiExtensionService; import org.onosproject.ui.UiMessageHandlerFactory; -import org.onosproject.ui.UiMessageHandlerTwo; +import org.onosproject.ui.UiMessageHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,7 +56,7 @@ public class UiWebSocket private long lastActive = System.currentTimeMillis(); - private Map handlers; + private Map handlers; /** * Creates a new web-socket for serving data to GUI. @@ -123,7 +123,7 @@ public class UiWebSocket try { ObjectNode message = (ObjectNode) mapper.reader().readTree(data); String type = message.path("event").asText("unknown"); - UiMessageHandlerTwo handler = handlers.get(type); + UiMessageHandler handler = handlers.get(type); if (handler != null) { handler.process(message); } else {