GUI -- Rename UIMessageHandlerTwo => UIMessageHandler. Also, make bindHandlers() private.

Change-Id: Id36e220c1285b88b8b4db0e106ef063bd8b9bfd1
This commit is contained in:
Simon Hunt 2015-05-01 09:53:01 -07:00
parent 8ea1f51324
commit a0ddb02bd6
13 changed files with 70 additions and 73 deletions

View File

@ -31,7 +31,7 @@ import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiConnection; import org.onosproject.ui.UiConnection;
import org.onosproject.ui.UiExtension; import org.onosproject.ui.UiExtension;
import org.onosproject.ui.UiExtensionService; import org.onosproject.ui.UiExtensionService;
import org.onosproject.ui.UiMessageHandlerTwo; import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.UiView; import org.onosproject.ui.UiView;
import java.util.Collection; import java.util.Collection;
@ -97,13 +97,13 @@ public class IntentPerfUi {
} }
// Creates and returns session specific message handler. // Creates and returns session specific message handler.
private Collection<UiMessageHandlerTwo> newHandlers() { private Collection<UiMessageHandler> newHandlers() {
return ImmutableList.of(new StreamingControl()); return ImmutableList.of(new StreamingControl());
} }
// UI Message handlers for turning on/off reporting to a session. // 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; private boolean streamingEnabled = false;

View File

@ -22,14 +22,14 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
* Abstraction of an entity that handles a specific request from the * Abstraction of an entity that handles a specific request from the
* user interface client. * user interface client.
* *
* @see UiMessageHandlerTwo * @see UiMessageHandler
*/ */
public abstract class RequestHandler { public abstract class RequestHandler {
protected static final ObjectMapper MAPPER = new ObjectMapper(); protected static final ObjectMapper MAPPER = new ObjectMapper();
private final String eventType; private final String eventType;
private UiMessageHandlerTwo parent; private UiMessageHandler parent;
public RequestHandler(String eventType) { public RequestHandler(String eventType) {
@ -37,7 +37,7 @@ public abstract class RequestHandler {
} }
// package private // package private
void setParent(UiMessageHandlerTwo parent) { void setParent(UiMessageHandler parent) {
this.parent = parent; this.parent = parent;
} }

View File

@ -44,7 +44,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* } * }
* </pre> * </pre>
*/ */
public abstract class UiMessageHandlerTwo { public abstract class UiMessageHandler {
private final Map<String, RequestHandler> handlerMap = new HashMap<>(); private final Map<String, RequestHandler> handlerMap = new HashMap<>();
@ -56,20 +56,6 @@ public abstract class UiMessageHandlerTwo {
*/ */
protected final ObjectMapper mapper = new ObjectMapper(); protected final ObjectMapper mapper = new ObjectMapper();
/**
* Binds the handlers returned from {@link #getHandlers()} to this
* instance.
*/
void bindHandlers() {
Collection<RequestHandler> 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 * Subclasses must return the collection of handlers for the
@ -115,6 +101,17 @@ public abstract class UiMessageHandlerTwo {
} }
} }
private void bindHandlers() {
Collection<RequestHandler> 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 * Initializes the handler with the user interface connection and
* service directory context. * service directory context.

View File

@ -28,6 +28,6 @@ public interface UiMessageHandlerFactory {
* *
* @return collection of new handlers * @return collection of new handlers
*/ */
Collection<UiMessageHandlerTwo> newHandlers(); Collection<UiMessageHandler> newHandlers();
} }

View File

@ -23,7 +23,7 @@ import org.onosproject.app.ApplicationState;
import org.onosproject.core.Application; import org.onosproject.core.Application;
import org.onosproject.core.ApplicationId; import org.onosproject.core.ApplicationId;
import org.onosproject.ui.RequestHandler; 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.AbstractTableRow;
import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.RowComparator;
import org.onosproject.ui.table.TableRow; import org.onosproject.ui.table.TableRow;
@ -39,7 +39,7 @@ import static org.onosproject.app.ApplicationState.ACTIVE;
/** /**
* Message handler for application view related messages. * 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_DATA_REQ = "appDataRequest";
private static final String APP_MGMT_REQ = "appManagementRequest"; private static final String APP_MGMT_REQ = "appManagementRequest";

View File

@ -24,7 +24,7 @@ import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.ControllerNode; import org.onosproject.cluster.ControllerNode;
import org.onosproject.cluster.NodeId; import org.onosproject.cluster.NodeId;
import org.onosproject.ui.RequestHandler; 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.AbstractTableRow;
import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.RowComparator;
import org.onosproject.ui.table.TableRow; import org.onosproject.ui.table.TableRow;
@ -39,7 +39,7 @@ import java.util.stream.Collectors;
/** /**
* Message handler for cluster view related messages. * 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"; private static final String CLUSTER_DATA_REQ = "clusterDataRequest";

View File

@ -28,7 +28,7 @@ import org.onosproject.net.Port;
import org.onosproject.net.device.DeviceService; import org.onosproject.net.device.DeviceService;
import org.onosproject.net.link.LinkService; import org.onosproject.net.link.LinkService;
import org.onosproject.ui.RequestHandler; 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.AbstractTableRow;
import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.RowComparator;
import org.onosproject.ui.table.TableRow; import org.onosproject.ui.table.TableRow;
@ -44,7 +44,7 @@ import java.util.Set;
/** /**
* Message handler for device view related messages. * 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_DATA_REQ = "deviceDataRequest";
private static final String DEV_DETAIL_REQ = "deviceDetailRequest"; private static final String DEV_DETAIL_REQ = "deviceDetailRequest";

View File

@ -27,7 +27,7 @@ import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.Criterion; import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.instructions.Instruction; import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.ui.RequestHandler; 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.AbstractTableRow;
import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.RowComparator;
import org.onosproject.ui.table.TableRow; import org.onosproject.ui.table.TableRow;
@ -43,7 +43,7 @@ import java.util.Set;
/** /**
* Message handler for flow view related messages. * 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"; private static final String FLOW_DATA_REQ = "flowDataRequest";

View File

@ -22,7 +22,7 @@ import org.onosproject.net.Host;
import org.onosproject.net.HostLocation; import org.onosproject.net.HostLocation;
import org.onosproject.net.host.HostService; import org.onosproject.net.host.HostService;
import org.onosproject.ui.RequestHandler; 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.AbstractTableRow;
import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.RowComparator;
import org.onosproject.ui.table.TableRow; 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. * 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"; private static final String HOST_DATA_REQ = "hostDataRequest";

View File

@ -32,7 +32,7 @@ import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.PointToPointIntent; import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.SinglePointToMultiPointIntent; import org.onosproject.net.intent.SinglePointToMultiPointIntent;
import org.onosproject.ui.RequestHandler; 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.AbstractTableRow;
import org.onosproject.ui.table.RowComparator; import org.onosproject.ui.table.RowComparator;
import org.onosproject.ui.table.TableRow; import org.onosproject.ui.table.TableRow;
@ -47,7 +47,7 @@ import java.util.Set;
/** /**
* Message handler for intent view related messages. * 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"; private static final String INTENT_DATA_REQ = "intentDataRequest";

View File

@ -24,7 +24,7 @@ import org.onosproject.net.Link;
import org.onosproject.net.LinkKey; import org.onosproject.net.LinkKey;
import org.onosproject.net.link.LinkService; import org.onosproject.net.link.LinkService;
import org.onosproject.ui.RequestHandler; 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.impl.TopologyViewMessageHandlerBase.BiLink;
import org.onosproject.ui.table.AbstractTableRow; import org.onosproject.ui.table.AbstractTableRow;
import org.onosproject.ui.table.RowComparator; 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. * 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"; private static final String LINK_DATA_REQ = "linkDataRequest";

View File

@ -65,7 +65,7 @@ import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyService; import org.onosproject.net.topology.TopologyService;
import org.onosproject.ui.JsonUtils; import org.onosproject.ui.JsonUtils;
import org.onosproject.ui.UiConnection; import org.onosproject.ui.UiConnection;
import org.onosproject.ui.UiMessageHandlerTwo; import org.onosproject.ui.UiMessageHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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. * 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 = protected static final Logger log =
LoggerFactory.getLogger(TopologyViewMessageHandlerBase.class); LoggerFactory.getLogger(TopologyViewMessageHandlerBase.class);
@ -420,15 +420,15 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandlerTwo
protected ObjectNode summmaryMessage(long sid) { protected ObjectNode summmaryMessage(long sid) {
Topology topology = topologyService.currentTopology(); Topology topology = topologyService.currentTopology();
return JsonUtils.envelope("showSummary", sid, return JsonUtils.envelope("showSummary", sid,
json("ONOS Summary", "node", json("ONOS Summary", "node",
new Prop("Devices", format(topology.deviceCount())), new Prop("Devices", format(topology.deviceCount())),
new Prop("Links", format(topology.linkCount())), new Prop("Links", format(topology.linkCount())),
new Prop("Hosts", format(hostService.getHostCount())), new Prop("Hosts", format(hostService.getHostCount())),
new Prop("Topology SCCs", format(topology.clusterCount())), new Prop("Topology SCCs", format(topology.clusterCount())),
new Separator(), new Separator(),
new Prop("Intents", format(intentService.getIntentCount())), new Prop("Intents", format(intentService.getIntentCount())),
new Prop("Flows", format(flowService.getFlowRuleCount())), new Prop("Flows", format(flowService.getFlowRuleCount())),
new Prop("Version", version))); new Prop("Version", version)));
} }
// Returns device details response. // Returns device details response.
@ -439,21 +439,21 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandlerTwo
int portCount = deviceService.getPorts(deviceId).size(); int portCount = deviceService.getPorts(deviceId).size();
int flowCount = getFlowCount(deviceId); int flowCount = getFlowCount(deviceId);
return JsonUtils.envelope("showDetails", sid, return JsonUtils.envelope("showDetails", sid,
json(isNullOrEmpty(name) ? deviceId.toString() : name, json(isNullOrEmpty(name) ? deviceId.toString() : name,
device.type().toString().toLowerCase(), device.type().toString().toLowerCase(),
new Prop("URI", deviceId.toString()), new Prop("URI", deviceId.toString()),
new Prop("Vendor", device.manufacturer()), new Prop("Vendor", device.manufacturer()),
new Prop("H/W Version", device.hwVersion()), new Prop("H/W Version", device.hwVersion()),
new Prop("S/W Version", device.swVersion()), new Prop("S/W Version", device.swVersion()),
new Prop("Serial Number", device.serialNumber()), new Prop("Serial Number", device.serialNumber()),
new Prop("Protocol", annot.value(AnnotationKeys.PROTOCOL)), new Prop("Protocol", annot.value(AnnotationKeys.PROTOCOL)),
new Separator(), new Separator(),
new Prop("Master", master(deviceId)), new Prop("Master", master(deviceId)),
new Prop("Latitude", annot.value(AnnotationKeys.LATITUDE)), new Prop("Latitude", annot.value(AnnotationKeys.LATITUDE)),
new Prop("Longitude", annot.value(AnnotationKeys.LONGITUDE)), new Prop("Longitude", annot.value(AnnotationKeys.LONGITUDE)),
new Separator(), new Separator(),
new Prop("Ports", Integer.toString(portCount)), new Prop("Ports", Integer.toString(portCount)),
new Prop("Flows", Integer.toString(flowCount)))); new Prop("Flows", Integer.toString(flowCount))));
} }
protected int getFlowCount(DeviceId deviceId) { protected int getFlowCount(DeviceId deviceId) {
@ -517,14 +517,14 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandlerTwo
String name = annot.value(AnnotationKeys.NAME); String name = annot.value(AnnotationKeys.NAME);
String vlan = host.vlan().toString(); String vlan = host.vlan().toString();
return JsonUtils.envelope("showDetails", sid, return JsonUtils.envelope("showDetails", sid,
json(isNullOrEmpty(name) ? hostId.toString() : name, json(isNullOrEmpty(name) ? hostId.toString() : name,
isNullOrEmpty(type) ? "endstation" : type, isNullOrEmpty(type) ? "endstation" : type,
new Prop("MAC", host.mac().toString()), new Prop("MAC", host.mac().toString()),
new Prop("IP", host.ipAddresses().toString().replaceAll("[\\[\\]]", "")), new Prop("IP", host.ipAddresses().toString().replaceAll("[\\[\\]]", "")),
new Prop("VLAN", vlan.equals("-1") ? "none" : vlan), new Prop("VLAN", vlan.equals("-1") ? "none" : vlan),
new Separator(), new Separator(),
new Prop("Latitude", annot.value(AnnotationKeys.LATITUDE)), new Prop("Latitude", annot.value(AnnotationKeys.LATITUDE)),
new Prop("Longitude", annot.value(AnnotationKeys.LONGITUDE)))); new Prop("Longitude", annot.value(AnnotationKeys.LONGITUDE))));
} }

View File

@ -25,7 +25,7 @@ import org.onosproject.cluster.ControllerNode;
import org.onosproject.ui.UiConnection; import org.onosproject.ui.UiConnection;
import org.onosproject.ui.UiExtensionService; import org.onosproject.ui.UiExtensionService;
import org.onosproject.ui.UiMessageHandlerFactory; import org.onosproject.ui.UiMessageHandlerFactory;
import org.onosproject.ui.UiMessageHandlerTwo; import org.onosproject.ui.UiMessageHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -56,7 +56,7 @@ public class UiWebSocket
private long lastActive = System.currentTimeMillis(); private long lastActive = System.currentTimeMillis();
private Map<String, UiMessageHandlerTwo> handlers; private Map<String, UiMessageHandler> handlers;
/** /**
* Creates a new web-socket for serving data to GUI. * Creates a new web-socket for serving data to GUI.
@ -123,7 +123,7 @@ public class UiWebSocket
try { try {
ObjectNode message = (ObjectNode) mapper.reader().readTree(data); ObjectNode message = (ObjectNode) mapper.reader().readTree(data);
String type = message.path("event").asText("unknown"); String type = message.path("event").asText("unknown");
UiMessageHandlerTwo handler = handlers.get(type); UiMessageHandler handler = handlers.get(type);
if (handler != null) { if (handler != null) {
handler.process(message); handler.process(message);
} else { } else {