Simon Hunt

GUI -- Huge Refactoring of server-side message handlers (Part Two).

--- Well, it compiles, and seems to work, with the cursory testing I've done...

Change-Id: I0e59657c134e109850e4770766083370dfd9fdc2
...@@ -27,10 +27,11 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -27,10 +27,11 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
27 import org.apache.felix.scr.annotations.Service; 27 import org.apache.felix.scr.annotations.Service;
28 import org.onlab.osgi.ServiceDirectory; 28 import org.onlab.osgi.ServiceDirectory;
29 import org.onosproject.intentperf.IntentPerfCollector.Sample; 29 import org.onosproject.intentperf.IntentPerfCollector.Sample;
30 +import org.onosproject.ui.RequestHandler;
30 import org.onosproject.ui.UiConnection; 31 import org.onosproject.ui.UiConnection;
31 import org.onosproject.ui.UiExtension; 32 import org.onosproject.ui.UiExtension;
32 import org.onosproject.ui.UiExtensionService; 33 import org.onosproject.ui.UiExtensionService;
33 -import org.onosproject.ui.UiMessageHandler; 34 +import org.onosproject.ui.UiMessageHandlerTwo;
34 import org.onosproject.ui.UiView; 35 import org.onosproject.ui.UiView;
35 36
36 import java.util.Collection; 37 import java.util.Collection;
...@@ -48,14 +49,20 @@ import static org.onosproject.ui.UiView.Category.OTHER; ...@@ -48,14 +49,20 @@ import static org.onosproject.ui.UiView.Category.OTHER;
48 @Service(value = IntentPerfUi.class) 49 @Service(value = IntentPerfUi.class)
49 public class IntentPerfUi { 50 public class IntentPerfUi {
50 51
52 + private static final String INTENT_PERF_START = "intentPerfStart";
53 + private static final String INTENT_PERF_STOP = "intentPerfStop";
54 +
51 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 55 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
52 protected UiExtensionService uiExtensionService; 56 protected UiExtensionService uiExtensionService;
53 57
54 private final Set<StreamingControl> handlers = synchronizedSet(new HashSet<>()); 58 private final Set<StreamingControl> handlers = synchronizedSet(new HashSet<>());
55 59
56 - private List<UiView> views = ImmutableList.of(new UiView(OTHER, "intentPerf", "Intent Performance")); 60 + private List<UiView> views = ImmutableList.of(
57 - private UiExtension uiExtension = new UiExtension(views, this::newHandlers, 61 + new UiView(OTHER, "intentPerf", "Intent Performance")
58 - getClass().getClassLoader()); 62 + );
63 +
64 + private UiExtension uiExtension =
65 + new UiExtension(views, this::newHandlers, getClass().getClassLoader());
59 66
60 private IntentPerfCollector collector; 67 private IntentPerfCollector collector;
61 68
...@@ -90,25 +97,22 @@ public class IntentPerfUi { ...@@ -90,25 +97,22 @@ public class IntentPerfUi {
90 } 97 }
91 98
92 // Creates and returns session specific message handler. 99 // Creates and returns session specific message handler.
93 - private Collection<UiMessageHandler> newHandlers() { 100 + private Collection<UiMessageHandlerTwo> newHandlers() {
94 return ImmutableList.of(new StreamingControl()); 101 return ImmutableList.of(new StreamingControl());
95 } 102 }
96 103
104 +
97 // UI Message handlers for turning on/off reporting to a session. 105 // UI Message handlers for turning on/off reporting to a session.
98 - private class StreamingControl extends UiMessageHandler { 106 + private class StreamingControl extends UiMessageHandlerTwo {
99 107
100 private boolean streamingEnabled = false; 108 private boolean streamingEnabled = false;
101 109
102 - protected StreamingControl() {
103 - super(ImmutableSet.of("intentPerfStart", "intentPerfStop"));
104 - }
105 -
106 @Override 110 @Override
107 - public void process(ObjectNode message) { 111 + protected Collection<RequestHandler> getHandlers() {
108 - streamingEnabled = message.path("event").asText("unknown").equals("intentPerfStart"); 112 + return ImmutableSet.of(
109 - if (streamingEnabled) { 113 + new IntentPerfStart(),
110 - sendInitData(); 114 + new IntentPerfStop()
111 - } 115 + );
112 } 116 }
113 117
114 @Override 118 @Override
...@@ -129,17 +133,6 @@ public class IntentPerfUi { ...@@ -129,17 +133,6 @@ public class IntentPerfUi {
129 } 133 }
130 } 134 }
131 135
132 - private void sendInitData() {
133 - ObjectNode rootNode = mapper.createObjectNode();
134 - ArrayNode an = mapper.createArrayNode();
135 - ArrayNode sn = mapper.createArrayNode();
136 - rootNode.set("headers", an);
137 - rootNode.set("samples", sn);
138 -
139 - collector.getSampleHeaders().forEach(an::add);
140 - collector.getSamples().forEach(s -> sn.add(sampleNode(s)));
141 - connection().sendMessage("intentPerfInit", 0, rootNode);
142 - }
143 136
144 private ObjectNode sampleNode(Sample sample) { 137 private ObjectNode sampleNode(Sample sample) {
145 ObjectNode sampleNode = mapper.createObjectNode(); 138 ObjectNode sampleNode = mapper.createObjectNode();
...@@ -153,6 +146,47 @@ public class IntentPerfUi { ...@@ -153,6 +146,47 @@ public class IntentPerfUi {
153 return sampleNode; 146 return sampleNode;
154 } 147 }
155 148
149 + // ======================================================================
150 +
151 + private final class IntentPerfStart extends RequestHandler {
152 +
153 + private IntentPerfStart() {
154 + super(INTENT_PERF_START);
155 + }
156 +
157 + @Override
158 + public void process(long sid, ObjectNode payload) {
159 + streamingEnabled = true;
160 + sendInitData();
161 + }
162 +
163 + private void sendInitData() {
164 + ObjectNode rootNode = MAPPER.createObjectNode();
165 + ArrayNode an = MAPPER.createArrayNode();
166 + ArrayNode sn = MAPPER.createArrayNode();
167 + rootNode.set("headers", an);
168 + rootNode.set("samples", sn);
169 +
170 + collector.getSampleHeaders().forEach(an::add);
171 + collector.getSamples().forEach(s -> sn.add(sampleNode(s)));
172 + sendMessage("intentPerfInit", 0, rootNode);
173 + }
174 + }
175 +
176 + // ======================================================================
177 +
178 + private final class IntentPerfStop extends RequestHandler {
179 +
180 + private IntentPerfStop() {
181 + super(INTENT_PERF_STOP);
182 + }
183 +
184 + @Override
185 + public void process(long sid, ObjectNode payload) {
186 + streamingEnabled = false;
187 + }
188 + }
189 +
156 } 190 }
157 191
158 } 192 }
......
...@@ -61,6 +61,17 @@ public final class JsonUtils { ...@@ -61,6 +61,17 @@ public final class JsonUtils {
61 } 61 }
62 62
63 /** 63 /**
64 + * Returns the sequence identifier from the specified event, or 0 (zero)
65 + * if the "sid" property does not exist.
66 + *
67 + * @param event message event
68 + * @return extracted sequence identifier
69 + */
70 + public static long sid(ObjectNode event) {
71 + return number(event, "sid");
72 + }
73 +
74 + /**
64 * Returns the payload from the specified event. 75 * Returns the payload from the specified event.
65 * 76 *
66 * @param event message event 77 * @param event message event
...@@ -95,7 +106,7 @@ public final class JsonUtils { ...@@ -95,7 +106,7 @@ public final class JsonUtils {
95 /** 106 /**
96 * Returns the specified node property as a string, with a default fallback. 107 * Returns the specified node property as a string, with a default fallback.
97 * 108 *
98 - * @param node message event 109 + * @param node object node
99 * @param name property name 110 * @param name property name
100 * @param defaultValue fallback value if property is absent 111 * @param defaultValue fallback value if property is absent
101 * @return property as a string 112 * @return property as a string
...@@ -104,4 +115,15 @@ public final class JsonUtils { ...@@ -104,4 +115,15 @@ public final class JsonUtils {
104 return node.path(name).asText(defaultValue); 115 return node.path(name).asText(defaultValue);
105 } 116 }
106 117
118 + /**
119 + * Returns the specified node property as an object node.
120 + *
121 + * @param node object node
122 + * @param name property name
123 + * @return property as a node
124 + */
125 + public static ObjectNode node(ObjectNode node, String name) {
126 + return (ObjectNode) node.path(name);
127 + }
128 +
107 } 129 }
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ui;
17 +
18 +import com.fasterxml.jackson.databind.ObjectMapper;
19 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 +
21 +/**
22 + * Abstraction of an entity that handles a specific request from the
23 + * user interface client.
24 + *
25 + * @see UiMessageHandlerTwo
26 + */
27 +public abstract class RequestHandler {
28 +
29 + protected static final ObjectMapper MAPPER = new ObjectMapper();
30 +
31 + private final String eventType;
32 + private UiMessageHandlerTwo parent;
33 +
34 +
35 + public RequestHandler(String eventType) {
36 + this.eventType = eventType;
37 + }
38 +
39 + // package private
40 + void setParent(UiMessageHandlerTwo parent) {
41 + this.parent = parent;
42 + }
43 +
44 + /**
45 + * Returns the event type that this handler handles.
46 + *
47 + * @return event type
48 + */
49 + public String eventType() {
50 + return eventType;
51 + }
52 +
53 + /**
54 + * Processes the incoming message payload from the client.
55 + *
56 + * @param sid message sequence identifier
57 + * @param payload request message payload
58 + */
59 + public abstract void process(long sid, ObjectNode payload);
60 +
61 +
62 +
63 + // ===================================================================
64 + // === Convenience methods...
65 +
66 + /**
67 + * Returns implementation of the specified service class.
68 + *
69 + * @param serviceClass service class
70 + * @param <T> type of service
71 + * @return implementation class
72 + * @throws org.onlab.osgi.ServiceNotFoundException if no implementation found
73 + */
74 + protected <T> T get(Class<T> serviceClass) {
75 + return parent.directory().get(serviceClass);
76 + }
77 +
78 + /**
79 + * Sends a message back to the client.
80 + *
81 + * @param eventType message event type
82 + * @param sid message sequence identifier
83 + * @param payload message payload
84 + */
85 + protected void sendMessage(String eventType, long sid, ObjectNode payload) {
86 + parent.connection().sendMessage(eventType, sid, payload);
87 + }
88 +
89 + /**
90 + * Sends a message back to the client.
91 + * Here, the message is preformatted; the assumption is it has its
92 + * eventType, sid and payload attributes already filled in.
93 + *
94 + * @param message the message to send
95 + */
96 + protected void sendMessage(ObjectNode message) {
97 + parent.connection().sendMessage(message);
98 + }
99 +
100 + /**
101 + * Allows one request handler to pass the event on to another for
102 + * further processing.
103 + * Note that the message handlers must be defined in the same parent.
104 + *
105 + * @param eventType event type
106 + * @param sid sequence identifier
107 + * @param payload message payload
108 + */
109 + protected void chain(String eventType, long sid, ObjectNode payload) {
110 + parent.exec(eventType, sid, payload);
111 + }
112 +
113 + // ===================================================================
114 +
115 +
116 + // FIXME : Javadocs
117 + protected String string(ObjectNode node, String key) {
118 + return JsonUtils.string(node, key);
119 + }
120 +
121 + protected String string(ObjectNode node, String key, String defValue) {
122 + return JsonUtils.string(node, key, defValue);
123 + }
124 +
125 +}
...@@ -40,6 +40,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -40,6 +40,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
40 * } 40 * }
41 * </pre> 41 * </pre>
42 */ 42 */
43 +@Deprecated
43 public abstract class UiMessageHandler { 44 public abstract class UiMessageHandler {
44 45
45 private final Set<String> messageTypes; 46 private final Set<String> messageTypes;
......
...@@ -28,6 +28,6 @@ public interface UiMessageHandlerFactory { ...@@ -28,6 +28,6 @@ public interface UiMessageHandlerFactory {
28 * 28 *
29 * @return collection of new handlers 29 * @return collection of new handlers
30 */ 30 */
31 - Collection<UiMessageHandler> newHandlers(); 31 + Collection<UiMessageHandlerTwo> newHandlers();
32 32
33 } 33 }
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.ui;
17 +
18 +import com.fasterxml.jackson.databind.ObjectMapper;
19 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 +import org.onlab.osgi.ServiceDirectory;
21 +
22 +import java.util.Collection;
23 +import java.util.Collections;
24 +import java.util.HashMap;
25 +import java.util.Map;
26 +import java.util.Set;
27 +
28 +import static com.google.common.base.Preconditions.checkArgument;
29 +import static com.google.common.base.Preconditions.checkNotNull;
30 +
31 +/**
32 + * Abstraction of an entity capable of processing a JSON message from the user
33 + * interface client.
34 + * <p>
35 + * The message is a JSON object with the following structure:
36 + * </p>
37 + * <pre>
38 + * {
39 + * "type": "<em>event-type</em>",
40 + * "sid": "<em>sequence-number</em>",
41 + * "payload": {
42 + * <em>arbitrary JSON object structure</em>
43 + * }
44 + * }
45 + * </pre>
46 + */
47 +public abstract class UiMessageHandlerTwo {
48 +
49 + private final Map<String, RequestHandler> handlerMap = new HashMap<>();
50 +
51 + private UiConnection connection;
52 + private ServiceDirectory directory;
53 +
54 + /**
55 + * Mapper for creating ObjectNodes and ArrayNodes etc.
56 + */
57 + protected final ObjectMapper mapper = new ObjectMapper();
58 +
59 + /**
60 + * Binds the handlers returned from {@link #getHandlers()} to this
61 + * instance.
62 + */
63 + void bindHandlers() {
64 + Collection<RequestHandler> handlers = getHandlers();
65 + checkNotNull(handlers, "Handlers cannot be null");
66 + checkArgument(!handlers.isEmpty(), "Handlers cannot be empty");
67 +
68 + for (RequestHandler h : handlers) {
69 + h.setParent(this);
70 + handlerMap.put(h.eventType(), h);
71 + }
72 + }
73 +
74 + /**
75 + * Subclasses must return the collection of handlers for the
76 + * message types they handle.
77 + *
78 + * @return the message handler instances
79 + */
80 + protected abstract Collection<RequestHandler> getHandlers();
81 +
82 + /**
83 + * Returns the set of message types which this handler is capable of
84 + * processing.
85 + *
86 + * @return set of message types
87 + */
88 + public Set<String> messageTypes() {
89 + return Collections.unmodifiableSet(handlerMap.keySet());
90 + }
91 +
92 + /**
93 + * Processes a JSON message from the user interface client.
94 + *
95 + * @param message JSON message
96 + */
97 + public void process(ObjectNode message) {
98 + String type = JsonUtils.eventType(message);
99 + long sid = JsonUtils.sid(message);
100 + ObjectNode payload = JsonUtils.payload(message);
101 + exec(type, sid, payload);
102 + }
103 +
104 + /**
105 + * Finds the appropriate handler and executes the process method.
106 + *
107 + * @param eventType event type
108 + * @param sid sequence identifier
109 + * @param payload message payload
110 + */
111 + void exec(String eventType, long sid, ObjectNode payload) {
112 + RequestHandler handler = handlerMap.get(eventType);
113 + if (handler != null) {
114 + handler.process(sid, payload);
115 + }
116 + }
117 +
118 + /**
119 + * Initializes the handler with the user interface connection and
120 + * service directory context.
121 + *
122 + * @param connection user interface connection
123 + * @param directory service directory
124 + */
125 + public void init(UiConnection connection, ServiceDirectory directory) {
126 + this.connection = connection;
127 + this.directory = directory;
128 + bindHandlers();
129 + }
130 +
131 + /**
132 + * Destroys the message handler context.
133 + */
134 + public void destroy() {
135 + this.connection = null;
136 + this.directory = null;
137 + }
138 +
139 + /**
140 + * Returns the user interface connection with which this handler was primed.
141 + *
142 + * @return user interface connection
143 + */
144 + public UiConnection connection() {
145 + return connection;
146 + }
147 +
148 + /**
149 + * Returns the user interface connection with which this handler was primed.
150 + *
151 + * @return user interface connection
152 + */
153 + public ServiceDirectory directory() {
154 + return directory;
155 + }
156 +
157 + /**
158 + * Returns implementation of the specified service class.
159 + *
160 + * @param serviceClass service class
161 + * @param <T> type of service
162 + * @return implementation class
163 + * @throws org.onlab.osgi.ServiceNotFoundException if no implementation found
164 + */
165 + protected <T> T get(Class<T> serviceClass) {
166 + return directory.get(serviceClass);
167 + }
168 +
169 +}
...@@ -73,4 +73,19 @@ public abstract class AbstractTableRow implements TableRow { ...@@ -73,4 +73,19 @@ public abstract class AbstractTableRow implements TableRow {
73 protected void add(String id, Object value) { 73 protected void add(String id, Object value) {
74 cells.put(id, value.toString()); 74 cells.put(id, value.toString());
75 } 75 }
76 +
77 + /**
78 + * Concatenates an arbitrary number of objects, using their
79 + * toString() methods.
80 + *
81 + * @param items the items to concatenate
82 + * @return a concatenated string
83 + */
84 + protected static String concat(Object... items) {
85 + StringBuilder sb = new StringBuilder();
86 + for (Object o : items) {
87 + sb.append(o);
88 + }
89 + return sb.toString();
90 + }
76 } 91 }
......
...@@ -22,13 +22,15 @@ import org.onosproject.app.ApplicationService; ...@@ -22,13 +22,15 @@ import org.onosproject.app.ApplicationService;
22 import org.onosproject.app.ApplicationState; 22 import org.onosproject.app.ApplicationState;
23 import org.onosproject.core.Application; 23 import org.onosproject.core.Application;
24 import org.onosproject.core.ApplicationId; 24 import org.onosproject.core.ApplicationId;
25 -import org.onosproject.ui.UiMessageHandler; 25 +import org.onosproject.ui.RequestHandler;
26 +import org.onosproject.ui.UiMessageHandlerTwo;
26 import org.onosproject.ui.table.AbstractTableRow; 27 import org.onosproject.ui.table.AbstractTableRow;
27 import org.onosproject.ui.table.RowComparator; 28 import org.onosproject.ui.table.RowComparator;
28 import org.onosproject.ui.table.TableRow; 29 import org.onosproject.ui.table.TableRow;
29 import org.onosproject.ui.table.TableUtils; 30 import org.onosproject.ui.table.TableUtils;
30 31
31 import java.util.Arrays; 32 import java.util.Arrays;
33 +import java.util.Collection;
32 import java.util.List; 34 import java.util.List;
33 import java.util.stream.Collectors; 35 import java.util.stream.Collectors;
34 36
...@@ -37,40 +39,57 @@ import static org.onosproject.app.ApplicationState.ACTIVE; ...@@ -37,40 +39,57 @@ import static org.onosproject.app.ApplicationState.ACTIVE;
37 /** 39 /**
38 * Message handler for application view related messages. 40 * Message handler for application view related messages.
39 */ 41 */
40 -public class ApplicationViewMessageHandler extends UiMessageHandler { 42 +public class ApplicationViewMessageHandler extends UiMessageHandlerTwo {
41 43
42 - /** 44 + private static final String APP_DATA_REQ = "appDataRequest";
43 - * Creates a new message handler for the application messages. 45 + private static final String APP_MGMT_REQ = "appManagementRequest";
44 - */
45 - protected ApplicationViewMessageHandler() {
46 - super(ImmutableSet.of("appDataRequest", "appManagementRequest"));
47 - }
48 46
49 @Override 47 @Override
50 - public void process(ObjectNode message) { 48 + protected Collection<RequestHandler> getHandlers() {
51 - String type = eventType(message); 49 + return ImmutableSet.of(
52 - if (type.equals("appDataRequest")) { 50 + new AppDataRequest(),
53 - sendAppList(message); 51 + new AppMgmtRequest()
54 - } else if (type.equals("appManagementRequest")) { 52 + );
55 - processManagementCommand(message);
56 } 53 }
54 +
55 + // ======================================================================
56 +
57 + private final class AppDataRequest extends RequestHandler {
58 +
59 + private AppDataRequest() {
60 + super(APP_DATA_REQ);
57 } 61 }
58 62
59 - private void sendAppList(ObjectNode message) { 63 + @Override
60 - ObjectNode payload = payload(message); 64 + public void process(long sid, ObjectNode payload) {
61 RowComparator rc = TableUtils.createRowComparator(payload); 65 RowComparator rc = TableUtils.createRowComparator(payload);
62 66
63 ApplicationService service = get(ApplicationService.class); 67 ApplicationService service = get(ApplicationService.class);
64 TableRow[] rows = generateTableRows(service); 68 TableRow[] rows = generateTableRows(service);
65 Arrays.sort(rows, rc); 69 Arrays.sort(rows, rc);
66 - ObjectNode rootNode = mapper.createObjectNode(); 70 + ObjectNode rootNode = MAPPER.createObjectNode();
67 rootNode.set("apps", TableUtils.generateArrayNode(rows)); 71 rootNode.set("apps", TableUtils.generateArrayNode(rows));
68 72
69 - connection().sendMessage("appDataResponse", 0, rootNode); 73 + sendMessage("appDataResponse", 0, rootNode);
70 } 74 }
71 75
72 - private void processManagementCommand(ObjectNode message) { 76 + private TableRow[] generateTableRows(ApplicationService service) {
73 - ObjectNode payload = payload(message); 77 + List<TableRow> list = service.getApplications().stream()
78 + .map(application -> new ApplicationTableRow(service, application))
79 + .collect(Collectors.toList());
80 + return list.toArray(new TableRow[list.size()]);
81 + }
82 + }
83 + // ======================================================================
84 +
85 + private final class AppMgmtRequest extends RequestHandler {
86 +
87 + private AppMgmtRequest() {
88 + super(APP_MGMT_REQ);
89 + }
90 +
91 + @Override
92 + public void process(long sid, ObjectNode payload) {
74 String action = string(payload, "action"); 93 String action = string(payload, "action");
75 String name = string(payload, "name"); 94 String name = string(payload, "name");
76 if (action != null && name != null) { 95 if (action != null && name != null) {
...@@ -83,16 +102,11 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { ...@@ -83,16 +102,11 @@ public class ApplicationViewMessageHandler extends UiMessageHandler {
83 } else if (action.equals("uninstall")) { 102 } else if (action.equals("uninstall")) {
84 service.uninstall(appId); 103 service.uninstall(appId);
85 } 104 }
86 - sendAppList(message); 105 + chain(APP_DATA_REQ, sid, payload);
87 } 106 }
88 } 107 }
89 -
90 - private TableRow[] generateTableRows(ApplicationService service) {
91 - List<TableRow> list = service.getApplications().stream()
92 - .map(application -> new ApplicationTableRow(service, application))
93 - .collect(Collectors.toList());
94 - return list.toArray(new TableRow[list.size()]);
95 } 108 }
109 + // ======================================================================
96 110
97 /** 111 /**
98 * TableRow implementation for 112 * TableRow implementation for
......
...@@ -23,57 +23,61 @@ import org.joda.time.format.DateTimeFormat; ...@@ -23,57 +23,61 @@ import org.joda.time.format.DateTimeFormat;
23 import org.onosproject.cluster.ClusterService; 23 import org.onosproject.cluster.ClusterService;
24 import org.onosproject.cluster.ControllerNode; 24 import org.onosproject.cluster.ControllerNode;
25 import org.onosproject.cluster.NodeId; 25 import org.onosproject.cluster.NodeId;
26 -import org.onosproject.ui.UiMessageHandler; 26 +import org.onosproject.ui.RequestHandler;
27 +import org.onosproject.ui.UiMessageHandlerTwo;
27 import org.onosproject.ui.table.AbstractTableRow; 28 import org.onosproject.ui.table.AbstractTableRow;
28 import org.onosproject.ui.table.RowComparator; 29 import org.onosproject.ui.table.RowComparator;
29 import org.onosproject.ui.table.TableRow; 30 import org.onosproject.ui.table.TableRow;
30 import org.onosproject.ui.table.TableUtils; 31 import org.onosproject.ui.table.TableUtils;
31 32
32 -import java.util.ArrayList;
33 import java.util.Arrays; 33 import java.util.Arrays;
34 +import java.util.Collection;
34 import java.util.List; 35 import java.util.List;
36 +import java.util.stream.Collectors;
35 37
36 38
37 /** 39 /**
38 * Message handler for cluster view related messages. 40 * Message handler for cluster view related messages.
39 */ 41 */
40 -public class ClusterViewMessageHandler extends UiMessageHandler { 42 +public class ClusterViewMessageHandler extends UiMessageHandlerTwo {
41 43
42 - /** 44 + private static final String CLUSTER_DATA_REQ = "clusterDataRequest";
43 - * Creates a new message handler for the cluster messages.
44 - */
45 - protected ClusterViewMessageHandler() {
46 - super(ImmutableSet.of("clusterDataRequest"));
47 - }
48 45
49 @Override 46 @Override
50 - public void process(ObjectNode message) { 47 + protected Collection<RequestHandler> getHandlers() {
51 - String type = eventType(message); 48 + return ImmutableSet.of(new ClusterDataRequest());
52 - if (type.equals("clusterDataRequest")) {
53 - sendClusterList(message);
54 } 49 }
50 +
51 + // ======================================================================
52 +
53 + private final class ClusterDataRequest extends RequestHandler {
54 +
55 + private ClusterDataRequest() {
56 + super(CLUSTER_DATA_REQ);
55 } 57 }
56 58
57 - private void sendClusterList(ObjectNode message) { 59 + @Override
58 - ObjectNode payload = payload(message); 60 + public void process(long sid, ObjectNode payload) {
59 RowComparator rc = TableUtils.createRowComparator(payload); 61 RowComparator rc = TableUtils.createRowComparator(payload);
60 62
61 ClusterService service = get(ClusterService.class); 63 ClusterService service = get(ClusterService.class);
62 TableRow[] rows = generateTableRows(service); 64 TableRow[] rows = generateTableRows(service);
63 Arrays.sort(rows, rc); 65 Arrays.sort(rows, rc);
64 - ObjectNode rootNode = mapper.createObjectNode(); 66 + ObjectNode rootNode = MAPPER.createObjectNode();
65 rootNode.set("clusters", TableUtils.generateArrayNode(rows)); 67 rootNode.set("clusters", TableUtils.generateArrayNode(rows));
66 68
67 - connection().sendMessage("clusterDataResponse", 0, rootNode); 69 + sendMessage("clusterDataResponse", 0, rootNode);
68 } 70 }
69 71
70 private TableRow[] generateTableRows(ClusterService service) { 72 private TableRow[] generateTableRows(ClusterService service) {
71 - List<TableRow> list = new ArrayList<>(); 73 + List<TableRow> list = service.getNodes().stream()
72 - for (ControllerNode node : service.getNodes()) { 74 + .map(node -> new ControllerNodeTableRow(service, node))
73 - list.add(new ControllerNodeTableRow(service, node)); 75 + .collect(Collectors.toList());
74 - }
75 return list.toArray(new TableRow[list.size()]); 76 return list.toArray(new TableRow[list.size()]);
76 } 77 }
78 + }
79 +
80 + // ======================================================================
77 81
78 /** 82 /**
79 * TableRow implementation for {@link ControllerNode controller nodes}. 83 * TableRow implementation for {@link ControllerNode controller nodes}.
......
...@@ -27,7 +27,8 @@ import org.onosproject.net.Link; ...@@ -27,7 +27,8 @@ import org.onosproject.net.Link;
27 import org.onosproject.net.Port; 27 import org.onosproject.net.Port;
28 import org.onosproject.net.device.DeviceService; 28 import org.onosproject.net.device.DeviceService;
29 import org.onosproject.net.link.LinkService; 29 import org.onosproject.net.link.LinkService;
30 -import org.onosproject.ui.UiMessageHandler; 30 +import org.onosproject.ui.RequestHandler;
31 +import org.onosproject.ui.UiMessageHandlerTwo;
31 import org.onosproject.ui.table.AbstractTableRow; 32 import org.onosproject.ui.table.AbstractTableRow;
32 import org.onosproject.ui.table.RowComparator; 33 import org.onosproject.ui.table.RowComparator;
33 import org.onosproject.ui.table.TableRow; 34 import org.onosproject.ui.table.TableRow;
...@@ -35,6 +36,7 @@ import org.onosproject.ui.table.TableUtils; ...@@ -35,6 +36,7 @@ import org.onosproject.ui.table.TableUtils;
35 36
36 import java.util.ArrayList; 37 import java.util.ArrayList;
37 import java.util.Arrays; 38 import java.util.Arrays;
39 +import java.util.Collection;
38 import java.util.Collections; 40 import java.util.Collections;
39 import java.util.List; 41 import java.util.List;
40 import java.util.Set; 42 import java.util.Set;
...@@ -42,7 +44,10 @@ import java.util.Set; ...@@ -42,7 +44,10 @@ import java.util.Set;
42 /** 44 /**
43 * Message handler for device view related messages. 45 * Message handler for device view related messages.
44 */ 46 */
45 -public class DeviceViewMessageHandler extends UiMessageHandler { 47 +public class DeviceViewMessageHandler extends UiMessageHandlerTwo {
48 +
49 + private static final String DEV_DATA_REQ = "deviceDataRequest";
50 + private static final String DEV_DETAIL_REQ = "deviceDetailRequest";
46 51
47 private static final String ID = "id"; 52 private static final String ID = "id";
48 private static final String TYPE = "type"; 53 private static final String TYPE = "type";
...@@ -65,46 +70,62 @@ public class DeviceViewMessageHandler extends UiMessageHandler { ...@@ -65,46 +70,62 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
65 private static final String NAME = "name"; 70 private static final String NAME = "name";
66 71
67 72
68 - /**
69 - * Creates a new message handler for the device messages.
70 - */
71 - protected DeviceViewMessageHandler() {
72 - super(ImmutableSet.of("deviceDataRequest", "deviceDetailsRequest"));
73 - }
74 -
75 @Override 73 @Override
76 - public void process(ObjectNode message) { 74 + protected Collection<RequestHandler> getHandlers() {
77 - String type = eventType(message); 75 + return ImmutableSet.of(
78 - if (type.equals("deviceDataRequest")) { 76 + new DataRequestHandler(),
79 - dataRequest(message); 77 + new DetailRequestHandler()
80 - } else if (type.equals("deviceDetailsRequest")) { 78 + );
81 - detailsRequest(message);
82 } 79 }
80 +
81 + // ======================================================================
82 +
83 + private final class DataRequestHandler extends RequestHandler {
84 +
85 + private DataRequestHandler() {
86 + super(DEV_DATA_REQ);
83 } 87 }
84 88
85 - private void dataRequest(ObjectNode message) { 89 + @Override
86 - ObjectNode payload = payload(message); 90 + public void process(long sid, ObjectNode payload) {
87 RowComparator rc = TableUtils.createRowComparator(payload); 91 RowComparator rc = TableUtils.createRowComparator(payload);
88 92
89 DeviceService service = get(DeviceService.class); 93 DeviceService service = get(DeviceService.class);
90 MastershipService mastershipService = get(MastershipService.class); 94 MastershipService mastershipService = get(MastershipService.class);
91 TableRow[] rows = generateTableRows(service, mastershipService); 95 TableRow[] rows = generateTableRows(service, mastershipService);
92 Arrays.sort(rows, rc); 96 Arrays.sort(rows, rc);
93 - ObjectNode rootNode = mapper.createObjectNode(); 97 + ObjectNode rootNode = MAPPER.createObjectNode();
94 rootNode.set("devices", TableUtils.generateArrayNode(rows)); 98 rootNode.set("devices", TableUtils.generateArrayNode(rows));
95 99
96 - connection().sendMessage("deviceDataResponse", 0, rootNode); 100 + sendMessage("deviceDataResponse", 0, rootNode);
97 } 101 }
98 102
99 - private void detailsRequest(ObjectNode message) { 103 + private TableRow[] generateTableRows(DeviceService service,
100 - ObjectNode payload = payload(message); 104 + MastershipService mastershipService) {
105 + List<TableRow> list = new ArrayList<>();
106 + for (Device dev : service.getDevices()) {
107 + list.add(new DeviceTableRow(service, mastershipService, dev));
108 + }
109 + return list.toArray(new TableRow[list.size()]);
110 + }
111 + }
112 +
113 + // ======================================================================
114 +
115 + private final class DetailRequestHandler extends RequestHandler {
116 + private DetailRequestHandler() {
117 + super(DEV_DETAIL_REQ);
118 + }
119 +
120 + @Override
121 + public void process(long sid, ObjectNode payload) {
101 String id = string(payload, "id", "of:0000000000000000"); 122 String id = string(payload, "id", "of:0000000000000000");
102 123
103 DeviceId deviceId = DeviceId.deviceId(id); 124 DeviceId deviceId = DeviceId.deviceId(id);
104 DeviceService service = get(DeviceService.class); 125 DeviceService service = get(DeviceService.class);
105 MastershipService ms = get(MastershipService.class); 126 MastershipService ms = get(MastershipService.class);
106 Device device = service.getDevice(deviceId); 127 Device device = service.getDevice(deviceId);
107 - ObjectNode data = mapper.createObjectNode(); 128 + ObjectNode data = MAPPER.createObjectNode();
108 129
109 data.put(ID, deviceId.toString()); 130 data.put(ID, deviceId.toString());
110 data.put(TYPE, device.type().toString()); 131 data.put(TYPE, device.type().toString());
...@@ -117,7 +138,7 @@ public class DeviceViewMessageHandler extends UiMessageHandler { ...@@ -117,7 +138,7 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
117 data.put(MASTER_ID, ms.getMasterFor(deviceId).toString()); 138 data.put(MASTER_ID, ms.getMasterFor(deviceId).toString());
118 data.put(PROTOCOL, device.annotations().value(PROTOCOL)); 139 data.put(PROTOCOL, device.annotations().value(PROTOCOL));
119 140
120 - ArrayNode ports = mapper.createArrayNode(); 141 + ArrayNode ports = MAPPER.createArrayNode();
121 142
122 List<Port> portList = new ArrayList<>(service.getPorts(deviceId)); 143 List<Port> portList = new ArrayList<>(service.getPorts(deviceId));
123 Collections.sort(portList, (p1, p2) -> { 144 Collections.sort(portList, (p1, p2) -> {
...@@ -130,22 +151,13 @@ public class DeviceViewMessageHandler extends UiMessageHandler { ...@@ -130,22 +151,13 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
130 } 151 }
131 data.set(PORTS, ports); 152 data.set(PORTS, ports);
132 153
133 - ObjectNode rootNode = mapper.createObjectNode(); 154 + ObjectNode rootNode = MAPPER.createObjectNode();
134 rootNode.set("details", data); 155 rootNode.set("details", data);
135 - connection().sendMessage("deviceDetailsResponse", 0, rootNode); 156 + sendMessage("deviceDetailsResponse", 0, rootNode);
136 - }
137 -
138 - private TableRow[] generateTableRows(DeviceService service,
139 - MastershipService mastershipService) {
140 - List<TableRow> list = new ArrayList<>();
141 - for (Device dev : service.getDevices()) {
142 - list.add(new DeviceTableRow(service, mastershipService, dev));
143 - }
144 - return list.toArray(new TableRow[list.size()]);
145 } 157 }
146 158
147 private ObjectNode portData(Port p, DeviceId id) { 159 private ObjectNode portData(Port p, DeviceId id) {
148 - ObjectNode port = mapper.createObjectNode(); 160 + ObjectNode port = MAPPER.createObjectNode();
149 LinkService ls = get(LinkService.class); 161 LinkService ls = get(LinkService.class);
150 String name = p.annotations().value(AnnotationKeys.PORT_NAME); 162 String name = p.annotations().value(AnnotationKeys.PORT_NAME);
151 163
...@@ -169,6 +181,9 @@ public class DeviceViewMessageHandler extends UiMessageHandler { ...@@ -169,6 +181,9 @@ public class DeviceViewMessageHandler extends UiMessageHandler {
169 return port; 181 return port;
170 } 182 }
171 183
184 + }
185 +
186 +
172 private static String getTypeIconId(Device d) { 187 private static String getTypeIconId(Device d) {
173 return DEV_ICON_PREFIX + d.type().toString(); 188 return DEV_ICON_PREFIX + d.type().toString();
174 } 189 }
......
...@@ -26,7 +26,8 @@ import org.onosproject.net.flow.TrafficSelector; ...@@ -26,7 +26,8 @@ import org.onosproject.net.flow.TrafficSelector;
26 import org.onosproject.net.flow.TrafficTreatment; 26 import org.onosproject.net.flow.TrafficTreatment;
27 import org.onosproject.net.flow.criteria.Criterion; 27 import org.onosproject.net.flow.criteria.Criterion;
28 import org.onosproject.net.flow.instructions.Instruction; 28 import org.onosproject.net.flow.instructions.Instruction;
29 -import org.onosproject.ui.UiMessageHandler; 29 +import org.onosproject.ui.RequestHandler;
30 +import org.onosproject.ui.UiMessageHandlerTwo;
30 import org.onosproject.ui.table.AbstractTableRow; 31 import org.onosproject.ui.table.AbstractTableRow;
31 import org.onosproject.ui.table.RowComparator; 32 import org.onosproject.ui.table.RowComparator;
32 import org.onosproject.ui.table.TableRow; 33 import org.onosproject.ui.table.TableRow;
...@@ -34,6 +35,7 @@ import org.onosproject.ui.table.TableUtils; ...@@ -34,6 +35,7 @@ import org.onosproject.ui.table.TableUtils;
34 35
35 import java.util.ArrayList; 36 import java.util.ArrayList;
36 import java.util.Arrays; 37 import java.util.Arrays;
38 +import java.util.Collection;
37 import java.util.List; 39 import java.util.List;
38 import java.util.Set; 40 import java.util.Set;
39 41
...@@ -41,44 +43,44 @@ import java.util.Set; ...@@ -41,44 +43,44 @@ import java.util.Set;
41 /** 43 /**
42 * Message handler for flow view related messages. 44 * Message handler for flow view related messages.
43 */ 45 */
44 -public class FlowViewMessageHandler extends UiMessageHandler { 46 +public class FlowViewMessageHandler extends UiMessageHandlerTwo {
45 47
46 - private static final String NO_DEV = "none"; 48 + private static final String FLOW_DATA_REQ = "flowDataRequest";
47 49
48 - /** 50 + private static final String NO_DEV = "none";
49 - * Creates a new message handler for the flow messages.
50 - */
51 - protected FlowViewMessageHandler() {
52 - super(ImmutableSet.of("flowDataRequest"));
53 - }
54 51
55 @Override 52 @Override
56 - public void process(ObjectNode message) { 53 + protected Collection<RequestHandler> getHandlers() {
57 - String type = eventType(message); 54 + return ImmutableSet.of(new FlowDataRequest());
58 - if (type.equals("flowDataRequest")) {
59 - sendFlowList(message);
60 } 55 }
56 +
57 + // ======================================================================
58 +
59 + private final class FlowDataRequest extends RequestHandler {
60 +
61 + private FlowDataRequest() {
62 + super(FLOW_DATA_REQ);
61 } 63 }
62 64
63 - private void sendFlowList(ObjectNode message) { 65 + @Override
64 - ObjectNode payload = payload(message); 66 + public void process(long sid, ObjectNode payload) {
65 RowComparator rc = TableUtils.createRowComparator(payload); 67 RowComparator rc = TableUtils.createRowComparator(payload);
66 String uri = string(payload, "devId", NO_DEV); 68 String uri = string(payload, "devId", NO_DEV);
67 69
68 ObjectNode rootNode; 70 ObjectNode rootNode;
69 if (uri.equals(NO_DEV)) { 71 if (uri.equals(NO_DEV)) {
70 - rootNode = mapper.createObjectNode(); 72 + rootNode = MAPPER.createObjectNode();
71 - rootNode.set("flows", mapper.createArrayNode()); 73 + rootNode.set("flows", MAPPER.createArrayNode());
72 } else { 74 } else {
73 DeviceId deviceId = DeviceId.deviceId(uri); 75 DeviceId deviceId = DeviceId.deviceId(uri);
74 FlowRuleService service = get(FlowRuleService.class); 76 FlowRuleService service = get(FlowRuleService.class);
75 TableRow[] rows = generateTableRows(service, deviceId); 77 TableRow[] rows = generateTableRows(service, deviceId);
76 Arrays.sort(rows, rc); 78 Arrays.sort(rows, rc);
77 - rootNode = mapper.createObjectNode(); 79 + rootNode = MAPPER.createObjectNode();
78 rootNode.set("flows", TableUtils.generateArrayNode(rows)); 80 rootNode.set("flows", TableUtils.generateArrayNode(rows));
79 } 81 }
80 82
81 - connection().sendMessage("flowDataResponse", 0, rootNode); 83 + sendMessage("flowDataResponse", 0, rootNode);
82 } 84 }
83 85
84 private TableRow[] generateTableRows(FlowRuleService service, 86 private TableRow[] generateTableRows(FlowRuleService service,
...@@ -89,6 +91,9 @@ public class FlowViewMessageHandler extends UiMessageHandler { ...@@ -89,6 +91,9 @@ public class FlowViewMessageHandler extends UiMessageHandler {
89 } 91 }
90 return list.toArray(new TableRow[list.size()]); 92 return list.toArray(new TableRow[list.size()]);
91 } 93 }
94 + }
95 +
96 + // ======================================================================
92 97
93 /** 98 /**
94 * TableRow implementation for {@link org.onosproject.net.flow.FlowRule flows}. 99 * TableRow implementation for {@link org.onosproject.net.flow.FlowRule flows}.
......
...@@ -21,7 +21,8 @@ import org.onosproject.net.AnnotationKeys; ...@@ -21,7 +21,8 @@ import org.onosproject.net.AnnotationKeys;
21 import org.onosproject.net.Host; 21 import org.onosproject.net.Host;
22 import org.onosproject.net.HostLocation; 22 import org.onosproject.net.HostLocation;
23 import org.onosproject.net.host.HostService; 23 import org.onosproject.net.host.HostService;
24 -import org.onosproject.ui.UiMessageHandler; 24 +import org.onosproject.ui.RequestHandler;
25 +import org.onosproject.ui.UiMessageHandlerTwo;
25 import org.onosproject.ui.table.AbstractTableRow; 26 import org.onosproject.ui.table.AbstractTableRow;
26 import org.onosproject.ui.table.RowComparator; 27 import org.onosproject.ui.table.RowComparator;
27 import org.onosproject.ui.table.TableRow; 28 import org.onosproject.ui.table.TableRow;
...@@ -29,6 +30,7 @@ import org.onosproject.ui.table.TableUtils; ...@@ -29,6 +30,7 @@ import org.onosproject.ui.table.TableUtils;
29 30
30 import java.util.ArrayList; 31 import java.util.ArrayList;
31 import java.util.Arrays; 32 import java.util.Arrays;
33 +import java.util.Collection;
32 import java.util.List; 34 import java.util.List;
33 35
34 import static com.google.common.base.Strings.isNullOrEmpty; 36 import static com.google.common.base.Strings.isNullOrEmpty;
...@@ -36,34 +38,35 @@ import static com.google.common.base.Strings.isNullOrEmpty; ...@@ -36,34 +38,35 @@ import static com.google.common.base.Strings.isNullOrEmpty;
36 /** 38 /**
37 * Message handler for host view related messages. 39 * Message handler for host view related messages.
38 */ 40 */
39 -public class HostViewMessageHandler extends UiMessageHandler { 41 +public class HostViewMessageHandler extends UiMessageHandlerTwo {
42 +
43 + private static final String HOST_DATA_REQ = "hostDataRequest";
40 44
41 - /**
42 - * Creates a new message handler for the host messages.
43 - */
44 - protected HostViewMessageHandler() {
45 - super(ImmutableSet.of("hostDataRequest"));
46 - }
47 45
48 @Override 46 @Override
49 - public void process(ObjectNode message) { 47 + protected Collection<RequestHandler> getHandlers() {
50 - String type = eventType(message); 48 + return ImmutableSet.of(new HostDataRequest());
51 - if (type.equals("hostDataRequest")) {
52 - sendHostList(message);
53 } 49 }
50 +
51 + // ======================================================================
52 +
53 + private final class HostDataRequest extends RequestHandler {
54 +
55 + private HostDataRequest() {
56 + super(HOST_DATA_REQ);
54 } 57 }
55 58
56 - private void sendHostList(ObjectNode message) { 59 + @Override
57 - ObjectNode payload = payload(message); 60 + public void process(long sid, ObjectNode payload) {
58 RowComparator rc = TableUtils.createRowComparator(payload); 61 RowComparator rc = TableUtils.createRowComparator(payload);
59 62
60 HostService service = get(HostService.class); 63 HostService service = get(HostService.class);
61 TableRow[] rows = generateTableRows(service); 64 TableRow[] rows = generateTableRows(service);
62 Arrays.sort(rows, rc); 65 Arrays.sort(rows, rc);
63 - ObjectNode rootNode = mapper.createObjectNode(); 66 + ObjectNode rootNode = MAPPER.createObjectNode();
64 rootNode.set("hosts", TableUtils.generateArrayNode(rows)); 67 rootNode.set("hosts", TableUtils.generateArrayNode(rows));
65 68
66 - connection().sendMessage("hostDataResponse", 0, rootNode); 69 + sendMessage("hostDataResponse", 0, rootNode);
67 } 70 }
68 71
69 private TableRow[] generateTableRows(HostService service) { 72 private TableRow[] generateTableRows(HostService service) {
...@@ -73,6 +76,9 @@ public class HostViewMessageHandler extends UiMessageHandler { ...@@ -73,6 +76,9 @@ public class HostViewMessageHandler extends UiMessageHandler {
73 } 76 }
74 return list.toArray(new TableRow[list.size()]); 77 return list.toArray(new TableRow[list.size()]);
75 } 78 }
79 + }
80 +
81 + // ======================================================================
76 82
77 /** 83 /**
78 * TableRow implementation for {@link Host hosts}. 84 * TableRow implementation for {@link Host hosts}.
......
...@@ -31,7 +31,8 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent; ...@@ -31,7 +31,8 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent;
31 import org.onosproject.net.intent.PathIntent; 31 import org.onosproject.net.intent.PathIntent;
32 import org.onosproject.net.intent.PointToPointIntent; 32 import org.onosproject.net.intent.PointToPointIntent;
33 import org.onosproject.net.intent.SinglePointToMultiPointIntent; 33 import org.onosproject.net.intent.SinglePointToMultiPointIntent;
34 -import org.onosproject.ui.UiMessageHandler; 34 +import org.onosproject.ui.RequestHandler;
35 +import org.onosproject.ui.UiMessageHandlerTwo;
35 import org.onosproject.ui.table.AbstractTableRow; 36 import org.onosproject.ui.table.AbstractTableRow;
36 import org.onosproject.ui.table.RowComparator; 37 import org.onosproject.ui.table.RowComparator;
37 import org.onosproject.ui.table.TableRow; 38 import org.onosproject.ui.table.TableRow;
...@@ -39,40 +40,42 @@ import org.onosproject.ui.table.TableUtils; ...@@ -39,40 +40,42 @@ import org.onosproject.ui.table.TableUtils;
39 40
40 import java.util.ArrayList; 41 import java.util.ArrayList;
41 import java.util.Arrays; 42 import java.util.Arrays;
43 +import java.util.Collection;
42 import java.util.List; 44 import java.util.List;
43 import java.util.Set; 45 import java.util.Set;
44 46
45 /** 47 /**
46 * Message handler for intent view related messages. 48 * Message handler for intent view related messages.
47 */ 49 */
48 -public class IntentViewMessageHandler extends UiMessageHandler { 50 +public class IntentViewMessageHandler extends UiMessageHandlerTwo {
51 +
52 + private static final String INTENT_DATA_REQ = "intentDataRequest";
49 53
50 - /**
51 - * Creates a new message handler for the intent messages.
52 - */
53 - protected IntentViewMessageHandler() {
54 - super(ImmutableSet.of("intentDataRequest"));
55 - }
56 54
57 @Override 55 @Override
58 - public void process(ObjectNode message) { 56 + protected Collection<RequestHandler> getHandlers() {
59 - String type = eventType(message); 57 + return ImmutableSet.of(new IntentDataRequest());
60 - if (type.equals("intentDataRequest")) {
61 - sendIntentList(message);
62 } 58 }
59 +
60 + // ======================================================================
61 +
62 + private final class IntentDataRequest extends RequestHandler {
63 +
64 + private IntentDataRequest() {
65 + super(INTENT_DATA_REQ);
63 } 66 }
64 67
65 - private void sendIntentList(ObjectNode message) { 68 + @Override
66 - ObjectNode payload = payload(message); 69 + public void process(long sid, ObjectNode payload) {
67 RowComparator rc = TableUtils.createRowComparator(payload); 70 RowComparator rc = TableUtils.createRowComparator(payload);
68 71
69 IntentService service = get(IntentService.class); 72 IntentService service = get(IntentService.class);
70 TableRow[] rows = generateTableRows(service); 73 TableRow[] rows = generateTableRows(service);
71 Arrays.sort(rows, rc); 74 Arrays.sort(rows, rc);
72 - ObjectNode rootNode = mapper.createObjectNode(); 75 + ObjectNode rootNode = MAPPER.createObjectNode();
73 rootNode.set("intents", TableUtils.generateArrayNode(rows)); 76 rootNode.set("intents", TableUtils.generateArrayNode(rows));
74 77
75 - connection().sendMessage("intentDataResponse", 0, rootNode); 78 + sendMessage("intentDataResponse", 0, rootNode);
76 } 79 }
77 80
78 private TableRow[] generateTableRows(IntentService service) { 81 private TableRow[] generateTableRows(IntentService service) {
...@@ -82,6 +85,9 @@ public class IntentViewMessageHandler extends UiMessageHandler { ...@@ -82,6 +85,9 @@ public class IntentViewMessageHandler extends UiMessageHandler {
82 } 85 }
83 return list.toArray(new TableRow[list.size()]); 86 return list.toArray(new TableRow[list.size()]);
84 } 87 }
88 + }
89 +
90 + // ======================================================================
85 91
86 /** 92 /**
87 * TableRow implementation for {@link Intent intents}. 93 * TableRow implementation for {@link Intent intents}.
......
...@@ -23,7 +23,8 @@ import org.onosproject.net.ConnectPoint; ...@@ -23,7 +23,8 @@ import org.onosproject.net.ConnectPoint;
23 import org.onosproject.net.Link; 23 import org.onosproject.net.Link;
24 import org.onosproject.net.LinkKey; 24 import org.onosproject.net.LinkKey;
25 import org.onosproject.net.link.LinkService; 25 import org.onosproject.net.link.LinkService;
26 -import org.onosproject.ui.UiMessageHandler; 26 +import org.onosproject.ui.RequestHandler;
27 +import org.onosproject.ui.UiMessageHandlerTwo;
27 import org.onosproject.ui.impl.TopologyViewMessageHandlerBase.BiLink; 28 import org.onosproject.ui.impl.TopologyViewMessageHandlerBase.BiLink;
28 import org.onosproject.ui.table.AbstractTableRow; 29 import org.onosproject.ui.table.AbstractTableRow;
29 import org.onosproject.ui.table.RowComparator; 30 import org.onosproject.ui.table.RowComparator;
...@@ -32,6 +33,7 @@ import org.onosproject.ui.table.TableUtils; ...@@ -32,6 +33,7 @@ import org.onosproject.ui.table.TableUtils;
32 33
33 import java.util.ArrayList; 34 import java.util.ArrayList;
34 import java.util.Arrays; 35 import java.util.Arrays;
36 +import java.util.Collection;
35 import java.util.List; 37 import java.util.List;
36 import java.util.Map; 38 import java.util.Map;
37 39
...@@ -40,34 +42,35 @@ import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.addLink; ...@@ -40,34 +42,35 @@ import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.addLink;
40 /** 42 /**
41 * Message handler for link view related messages. 43 * Message handler for link view related messages.
42 */ 44 */
43 -public class LinkViewMessageHandler extends UiMessageHandler { 45 +public class LinkViewMessageHandler extends UiMessageHandlerTwo {
46 +
47 + private static final String LINK_DATA_REQ = "linkDataRequest";
44 48
45 - /**
46 - * Creates a new message handler for the link messages.
47 - */
48 - protected LinkViewMessageHandler() {
49 - super(ImmutableSet.of("linkDataRequest"));
50 - }
51 49
52 @Override 50 @Override
53 - public void process(ObjectNode message) { 51 + protected Collection<RequestHandler> getHandlers() {
54 - String type = eventType(message); 52 + return ImmutableSet.of(new LinkDataRequest());
55 - if (type.equals("linkDataRequest")) {
56 - sendLinkList(message);
57 } 53 }
54 +
55 + // ======================================================================
56 +
57 + private final class LinkDataRequest extends RequestHandler {
58 +
59 + private LinkDataRequest() {
60 + super(LINK_DATA_REQ);
58 } 61 }
59 62
60 - private void sendLinkList(ObjectNode message) { 63 + @Override
61 - ObjectNode payload = payload(message); 64 + public void process(long sid, ObjectNode payload) {
62 RowComparator rc = TableUtils.createRowComparator(payload, "one"); 65 RowComparator rc = TableUtils.createRowComparator(payload, "one");
63 66
64 LinkService service = get(LinkService.class); 67 LinkService service = get(LinkService.class);
65 TableRow[] rows = generateTableRows(service); 68 TableRow[] rows = generateTableRows(service);
66 Arrays.sort(rows, rc); 69 Arrays.sort(rows, rc);
67 - ObjectNode rootNode = mapper.createObjectNode(); 70 + ObjectNode rootNode = MAPPER.createObjectNode();
68 rootNode.set("links", TableUtils.generateArrayNode(rows)); 71 rootNode.set("links", TableUtils.generateArrayNode(rows));
69 72
70 - connection().sendMessage("linkDataResponse", 0, rootNode); 73 + sendMessage("linkDataResponse", 0, rootNode);
71 } 74 }
72 75
73 private TableRow[] generateTableRows(LinkService service) { 76 private TableRow[] generateTableRows(LinkService service) {
...@@ -81,6 +84,9 @@ public class LinkViewMessageHandler extends UiMessageHandler { ...@@ -81,6 +84,9 @@ public class LinkViewMessageHandler extends UiMessageHandler {
81 biLinks.values().forEach(biLink -> list.add(new LinkTableRow(biLink))); 84 biLinks.values().forEach(biLink -> list.add(new LinkTableRow(biLink)));
82 return list.toArray(new TableRow[list.size()]); 85 return list.toArray(new TableRow[list.size()]);
83 } 86 }
87 + }
88 +
89 + // ======================================================================
84 90
85 /** 91 /**
86 * TableRow implementation for {@link org.onosproject.net.Link links}. 92 * TableRow implementation for {@link org.onosproject.net.Link links}.
......
...@@ -63,8 +63,9 @@ import org.onosproject.net.statistic.Load; ...@@ -63,8 +63,9 @@ import org.onosproject.net.statistic.Load;
63 import org.onosproject.net.statistic.StatisticService; 63 import org.onosproject.net.statistic.StatisticService;
64 import org.onosproject.net.topology.Topology; 64 import org.onosproject.net.topology.Topology;
65 import org.onosproject.net.topology.TopologyService; 65 import org.onosproject.net.topology.TopologyService;
66 +import org.onosproject.ui.JsonUtils;
66 import org.onosproject.ui.UiConnection; 67 import org.onosproject.ui.UiConnection;
67 -import org.onosproject.ui.UiMessageHandler; 68 +import org.onosproject.ui.UiMessageHandlerTwo;
68 import org.slf4j.Logger; 69 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory; 70 import org.slf4j.LoggerFactory;
70 71
...@@ -100,11 +101,13 @@ import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED; ...@@ -100,11 +101,13 @@ import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED;
100 /** 101 /**
101 * Facility for creating messages bound for the topology viewer. 102 * Facility for creating messages bound for the topology viewer.
102 */ 103 */
103 -public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { 104 +public abstract class TopologyViewMessageHandlerBase extends UiMessageHandlerTwo {
104 105
105 - protected static final Logger log = LoggerFactory.getLogger(TopologyViewMessageHandlerBase.class); 106 + protected static final Logger log =
107 + LoggerFactory.getLogger(TopologyViewMessageHandlerBase.class);
106 108
107 - private static final ProviderId PID = new ProviderId("core", "org.onosproject.core", true); 109 + private static final ProviderId PID =
110 + new ProviderId("core", "org.onosproject.core", true);
108 private static final String COMPACT = "%s/%s-%s/%s"; 111 private static final String COMPACT = "%s/%s-%s/%s";
109 112
110 private static final double KB = 1024; 113 private static final double KB = 1024;
...@@ -133,15 +136,6 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -133,15 +136,6 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
133 private static Map<String, ObjectNode> metaUi = new ConcurrentHashMap<>(); 136 private static Map<String, ObjectNode> metaUi = new ConcurrentHashMap<>();
134 137
135 /** 138 /**
136 - * Creates a new message handler for the specified set of message types.
137 - *
138 - * @param messageTypes set of message types
139 - */
140 - protected TopologyViewMessageHandlerBase(Set<String> messageTypes) {
141 - super(messageTypes);
142 - }
143 -
144 - /**
145 * Returns read-only view of the meta-ui information. 139 * Returns read-only view of the meta-ui information.
146 * 140 *
147 * @return map of id to meta-ui mementos 141 * @return map of id to meta-ui mementos
...@@ -168,26 +162,6 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -168,26 +162,6 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
168 version = ver.replace(".SNAPSHOT", "*").replaceFirst("~.*$", ""); 162 version = ver.replace(".SNAPSHOT", "*").replaceFirst("~.*$", "");
169 } 163 }
170 164
171 - // Retrieves the payload from the specified event.
172 - protected ObjectNode payload(ObjectNode event) {
173 - return (ObjectNode) event.path("payload");
174 - }
175 -
176 - // Returns the specified node property as a number
177 - protected long number(ObjectNode node, String name) {
178 - return node.path(name).asLong();
179 - }
180 -
181 - // Returns the specified node property as a string.
182 - protected String string(ObjectNode node, String name) {
183 - return node.path(name).asText();
184 - }
185 -
186 - // Returns the specified node property as a string.
187 - protected String string(ObjectNode node, String name, String defaultValue) {
188 - return node.path(name).asText(defaultValue);
189 - }
190 -
191 // Returns the specified set of IP addresses as a string. 165 // Returns the specified set of IP addresses as a string.
192 private String ip(Set<IpAddress> ipAddresses) { 166 private String ip(Set<IpAddress> ipAddresses) {
193 Iterator<IpAddress> it = ipAddresses.iterator(); 167 Iterator<IpAddress> it = ipAddresses.iterator();
...@@ -222,21 +196,11 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -222,21 +196,11 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
222 196
223 // Produces a log message event bound to the client. 197 // Produces a log message event bound to the client.
224 private ObjectNode message(String severity, long id, String message) { 198 private ObjectNode message(String severity, long id, String message) {
225 - return envelope("message", id, 199 + ObjectNode payload = mapper.createObjectNode()
226 - mapper.createObjectNode()
227 .put("severity", severity) 200 .put("severity", severity)
228 - .put("message", message)); 201 + .put("message", message);
229 - }
230 202
231 - // Puts the payload into an envelope and returns it. 203 + return JsonUtils.envelope("message", id, payload);
232 - protected ObjectNode envelope(String type, long sid, ObjectNode payload) {
233 - ObjectNode event = mapper.createObjectNode();
234 - event.put("event", type);
235 - if (sid > 0) {
236 - event.put("sid", sid);
237 - }
238 - event.set("payload", payload);
239 - return event;
240 } 204 }
241 205
242 // Produces a set of all hosts listed in the specified JSON array. 206 // Produces a set of all hosts listed in the specified JSON array.
...@@ -320,7 +284,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -320,7 +284,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
320 ((event.type() == INSTANCE_ADDED) ? "addInstance" : 284 ((event.type() == INSTANCE_ADDED) ? "addInstance" :
321 ((event.type() == INSTANCE_REMOVED ? "removeInstance" : 285 ((event.type() == INSTANCE_REMOVED ? "removeInstance" :
322 "addInstance"))); 286 "addInstance")));
323 - return envelope(type, 0, payload); 287 + return JsonUtils.envelope(type, 0, payload);
324 } 288 }
325 289
326 // Produces a device event message to the client. 290 // Produces a device event message to the client.
...@@ -347,7 +311,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -347,7 +311,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
347 311
348 String type = (event.type() == DEVICE_ADDED) ? "addDevice" : 312 String type = (event.type() == DEVICE_ADDED) ? "addDevice" :
349 ((event.type() == DEVICE_REMOVED) ? "removeDevice" : "updateDevice"); 313 ((event.type() == DEVICE_REMOVED) ? "removeDevice" : "updateDevice");
350 - return envelope(type, 0, payload); 314 + return JsonUtils.envelope(type, 0, payload);
351 } 315 }
352 316
353 // Produces a link event message to the client. 317 // Produces a link event message to the client.
...@@ -364,7 +328,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -364,7 +328,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
364 .put("dstPort", link.dst().port().toString()); 328 .put("dstPort", link.dst().port().toString());
365 String type = (event.type() == LINK_ADDED) ? "addLink" : 329 String type = (event.type() == LINK_ADDED) ? "addLink" :
366 ((event.type() == LINK_REMOVED) ? "removeLink" : "updateLink"); 330 ((event.type() == LINK_REMOVED) ? "removeLink" : "updateLink");
367 - return envelope(type, 0, payload); 331 + return JsonUtils.envelope(type, 0, payload);
368 } 332 }
369 333
370 // Produces a host event message to the client. 334 // Produces a host event message to the client.
...@@ -385,7 +349,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -385,7 +349,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
385 349
386 String type = (event.type() == HOST_ADDED) ? "addHost" : 350 String type = (event.type() == HOST_ADDED) ? "addHost" :
387 ((event.type() == HOST_REMOVED) ? "removeHost" : "updateHost"); 351 ((event.type() == HOST_REMOVED) ? "removeHost" : "updateHost");
388 - return envelope(type, 0, payload); 352 + return JsonUtils.envelope(type, 0, payload);
389 } 353 }
390 354
391 // Encodes the specified host location into a JSON object. 355 // Encodes the specified host location into a JSON object.
...@@ -447,15 +411,15 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -447,15 +411,15 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
447 } 411 }
448 412
449 // Updates meta UI information for the specified object. 413 // Updates meta UI information for the specified object.
450 - protected void updateMetaUi(ObjectNode event) { 414 + protected void updateMetaUi(ObjectNode payload) {
451 - ObjectNode payload = payload(event); 415 + metaUi.put(JsonUtils.string(payload, "id"),
452 - metaUi.put(string(payload, "id"), (ObjectNode) payload.path("memento")); 416 + JsonUtils.node(payload, "memento"));
453 } 417 }
454 418
455 // Returns summary response. 419 // Returns summary response.
456 protected ObjectNode summmaryMessage(long sid) { 420 protected ObjectNode summmaryMessage(long sid) {
457 Topology topology = topologyService.currentTopology(); 421 Topology topology = topologyService.currentTopology();
458 - return envelope("showSummary", sid, 422 + return JsonUtils.envelope("showSummary", sid,
459 json("ONOS Summary", "node", 423 json("ONOS Summary", "node",
460 new Prop("Devices", format(topology.deviceCount())), 424 new Prop("Devices", format(topology.deviceCount())),
461 new Prop("Links", format(topology.linkCount())), 425 new Prop("Links", format(topology.linkCount())),
...@@ -474,7 +438,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -474,7 +438,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
474 String name = annot.value(AnnotationKeys.NAME); 438 String name = annot.value(AnnotationKeys.NAME);
475 int portCount = deviceService.getPorts(deviceId).size(); 439 int portCount = deviceService.getPorts(deviceId).size();
476 int flowCount = getFlowCount(deviceId); 440 int flowCount = getFlowCount(deviceId);
477 - return envelope("showDetails", sid, 441 + return JsonUtils.envelope("showDetails", sid,
478 json(isNullOrEmpty(name) ? deviceId.toString() : name, 442 json(isNullOrEmpty(name) ? deviceId.toString() : name,
479 device.type().toString().toLowerCase(), 443 device.type().toString().toLowerCase(),
480 new Prop("URI", deviceId.toString()), 444 new Prop("URI", deviceId.toString()),
...@@ -552,7 +516,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -552,7 +516,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
552 String type = annot.value(AnnotationKeys.TYPE); 516 String type = annot.value(AnnotationKeys.TYPE);
553 String name = annot.value(AnnotationKeys.NAME); 517 String name = annot.value(AnnotationKeys.NAME);
554 String vlan = host.vlan().toString(); 518 String vlan = host.vlan().toString();
555 - return envelope("showDetails", sid, 519 + return JsonUtils.envelope("showDetails", sid,
556 json(isNullOrEmpty(name) ? hostId.toString() : name, 520 json(isNullOrEmpty(name) ? hostId.toString() : name,
557 isNullOrEmpty(type) ? "endstation" : type, 521 isNullOrEmpty(type) ? "endstation" : type,
558 new Prop("MAC", host.mac().toString()), 522 new Prop("MAC", host.mac().toString()),
...@@ -565,7 +529,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -565,7 +529,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
565 529
566 530
567 // Produces JSON message to trigger traffic overview visualization 531 // Produces JSON message to trigger traffic overview visualization
568 - protected ObjectNode trafficSummaryMessage(long sid) { 532 + protected ObjectNode trafficSummaryMessage() {
569 ObjectNode payload = mapper.createObjectNode(); 533 ObjectNode payload = mapper.createObjectNode();
570 ArrayNode paths = mapper.createArrayNode(); 534 ArrayNode paths = mapper.createArrayNode();
571 payload.set("paths", paths); 535 payload.set("paths", paths);
...@@ -603,7 +567,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -603,7 +567,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
603 } 567 }
604 } 568 }
605 } 569 }
606 - return envelope("showTraffic", sid, payload); 570 + return JsonUtils.envelope("showTraffic", 0, payload);
607 } 571 }
608 572
609 private Collection<BiLink> consolidateLinks(Iterable<Link> links) { 573 private Collection<BiLink> consolidateLinks(Iterable<Link> links) {
...@@ -615,7 +579,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -615,7 +579,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
615 } 579 }
616 580
617 // Produces JSON message to trigger flow overview visualization 581 // Produces JSON message to trigger flow overview visualization
618 - protected ObjectNode flowSummaryMessage(long sid, Set<Device> devices) { 582 + protected ObjectNode flowSummaryMessage(Set<Device> devices) {
619 ObjectNode payload = mapper.createObjectNode(); 583 ObjectNode payload = mapper.createObjectNode();
620 ArrayNode paths = mapper.createArrayNode(); 584 ArrayNode paths = mapper.createArrayNode();
621 payload.set("paths", paths); 585 payload.set("paths", paths);
...@@ -626,7 +590,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -626,7 +590,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
626 addLinkFlows(link, paths, counts.get(link)); 590 addLinkFlows(link, paths, counts.get(link));
627 } 591 }
628 } 592 }
629 - return envelope("showTraffic", sid, payload); 593 + return JsonUtils.envelope("showTraffic", 0, payload);
630 } 594 }
631 595
632 private void addLinkFlows(Link link, ArrayNode paths, Integer count) { 596 private void addLinkFlows(Link link, ArrayNode paths, Integer count) {
...@@ -644,7 +608,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -644,7 +608,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
644 608
645 609
646 // Produces JSON message to trigger traffic visualization 610 // Produces JSON message to trigger traffic visualization
647 - protected ObjectNode trafficMessage(long sid, TrafficClass... trafficClasses) { 611 + protected ObjectNode trafficMessage(TrafficClass... trafficClasses) {
648 ObjectNode payload = mapper.createObjectNode(); 612 ObjectNode payload = mapper.createObjectNode();
649 ArrayNode paths = mapper.createArrayNode(); 613 ArrayNode paths = mapper.createArrayNode();
650 payload.set("paths", paths); 614 payload.set("paths", paths);
...@@ -670,7 +634,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -670,7 +634,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
670 ((ArrayNode) pathNode.path("labels")).add(hasTraffic ? formatBytes(biLink.bytes) : ""); 634 ((ArrayNode) pathNode.path("labels")).add(hasTraffic ? formatBytes(biLink.bytes) : "");
671 } 635 }
672 636
673 - return envelope("showTraffic", sid, payload); 637 + return JsonUtils.envelope("showTraffic", 0, payload);
674 } 638 }
675 639
676 // Classifies the link traffic according to the specified classes. 640 // Classifies the link traffic according to the specified classes.
......
...@@ -24,8 +24,8 @@ import org.onosproject.cluster.ClusterService; ...@@ -24,8 +24,8 @@ import org.onosproject.cluster.ClusterService;
24 import org.onosproject.cluster.ControllerNode; 24 import org.onosproject.cluster.ControllerNode;
25 import org.onosproject.ui.UiConnection; 25 import org.onosproject.ui.UiConnection;
26 import org.onosproject.ui.UiExtensionService; 26 import org.onosproject.ui.UiExtensionService;
27 -import org.onosproject.ui.UiMessageHandler;
28 import org.onosproject.ui.UiMessageHandlerFactory; 27 import org.onosproject.ui.UiMessageHandlerFactory;
28 +import org.onosproject.ui.UiMessageHandlerTwo;
29 import org.slf4j.Logger; 29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory; 30 import org.slf4j.LoggerFactory;
31 31
...@@ -56,7 +56,7 @@ public class UiWebSocket ...@@ -56,7 +56,7 @@ public class UiWebSocket
56 56
57 private long lastActive = System.currentTimeMillis(); 57 private long lastActive = System.currentTimeMillis();
58 58
59 - private Map<String, UiMessageHandler> handlers; 59 + private Map<String, UiMessageHandlerTwo> handlers;
60 60
61 /** 61 /**
62 * Creates a new web-socket for serving data to GUI. 62 * Creates a new web-socket for serving data to GUI.
...@@ -123,7 +123,7 @@ public class UiWebSocket ...@@ -123,7 +123,7 @@ public class UiWebSocket
123 try { 123 try {
124 ObjectNode message = (ObjectNode) mapper.reader().readTree(data); 124 ObjectNode message = (ObjectNode) mapper.reader().readTree(data);
125 String type = message.path("event").asText("unknown"); 125 String type = message.path("event").asText("unknown");
126 - UiMessageHandler handler = handlers.get(type); 126 + UiMessageHandlerTwo handler = handlers.get(type);
127 if (handler != null) { 127 if (handler != null) {
128 handler.process(message); 128 handler.process(message);
129 } else { 129 } else {
......