Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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.onlab.onos.gui; |
| 17 | |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 19 | import org.eclipse.jetty.websocket.WebSocket; |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 20 | import org.onlab.onos.cluster.ClusterEvent; |
| 21 | import org.onlab.onos.cluster.ClusterEventListener; |
| 22 | import org.onlab.onos.cluster.ControllerNode; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 23 | import org.onlab.onos.core.ApplicationId; |
| 24 | import org.onlab.onos.core.CoreService; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 25 | import org.onlab.onos.mastership.MastershipEvent; |
| 26 | import org.onlab.onos.mastership.MastershipListener; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 27 | import org.onlab.onos.net.Device; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 28 | import org.onlab.onos.net.Host; |
| 29 | import org.onlab.onos.net.HostId; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 30 | import org.onlab.onos.net.Link; |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 31 | import org.onlab.onos.net.Path; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 32 | import org.onlab.onos.net.device.DeviceEvent; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 33 | import org.onlab.onos.net.device.DeviceListener; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 34 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
| 35 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 36 | import org.onlab.onos.net.host.HostEvent; |
| 37 | import org.onlab.onos.net.host.HostListener; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 38 | import org.onlab.onos.net.intent.HostToHostIntent; |
| 39 | import org.onlab.onos.net.intent.Intent; |
| 40 | import org.onlab.onos.net.intent.IntentEvent; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 41 | import org.onlab.onos.net.intent.IntentId; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 42 | import org.onlab.onos.net.intent.IntentListener; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 43 | import org.onlab.onos.net.intent.PathIntent; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 44 | import org.onlab.onos.net.link.LinkEvent; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 45 | import org.onlab.onos.net.link.LinkListener; |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 46 | import org.onlab.osgi.ServiceDirectory; |
| 47 | |
| 48 | import java.io.IOException; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 49 | import java.util.List; |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 50 | import java.util.Map; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 51 | import java.util.concurrent.ConcurrentHashMap; |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 52 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 53 | import static org.onlab.onos.cluster.ClusterEvent.Type.INSTANCE_ADDED; |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 54 | import static org.onlab.onos.net.DeviceId.deviceId; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 55 | import static org.onlab.onos.net.HostId.hostId; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 56 | import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_ADDED; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 57 | import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 58 | import static org.onlab.onos.net.link.LinkEvent.Type.LINK_ADDED; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 59 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 60 | /** |
| 61 | * Web socket capable of interacting with the GUI topology view. |
| 62 | */ |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 63 | public class TopologyWebSocket |
| 64 | extends TopologyMessages implements WebSocket.OnTextMessage { |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 65 | |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 66 | private static final String APP_ID = "org.onlab.onos.gui"; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 67 | |
| 68 | private final ApplicationId appId; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 69 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 70 | private Connection connection; |
| 71 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 72 | private final ClusterEventListener clusterListener = new InternalClusterListener(); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 73 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 74 | private final LinkListener linkListener = new InternalLinkListener(); |
| 75 | private final HostListener hostListener = new InternalHostListener(); |
| 76 | private final MastershipListener mastershipListener = new InternalMastershipListener(); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 77 | private final IntentListener intentListener = new InternalIntentListener(); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 78 | |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 79 | // Intents that are being monitored for the GUI |
| 80 | private static Map<IntentId, Long> intentsToMonitor = new ConcurrentHashMap<>(); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 81 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 82 | /** |
| 83 | * Creates a new web-socket for serving data to GUI topology view. |
| 84 | * |
| 85 | * @param directory service directory |
| 86 | */ |
| 87 | public TopologyWebSocket(ServiceDirectory directory) { |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 88 | super(directory); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 89 | appId = directory.get(CoreService.class).registerApplication(APP_ID); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public void onOpen(Connection connection) { |
| 94 | this.connection = connection; |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 95 | addListeners(); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 96 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 97 | sendAllInstances(); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 98 | sendAllDevices(); |
| 99 | sendAllLinks(); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 100 | sendAllHosts(); |
| 101 | } |
| 102 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 103 | @Override |
| 104 | public void onClose(int closeCode, String message) { |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 105 | removeListeners(); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public void onMessage(String data) { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 110 | try { |
| 111 | ObjectNode event = (ObjectNode) mapper.reader().readTree(data); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 112 | String type = string(event, "event", "unknown"); |
Thomas Vachuska | f1fae00 | 2014-11-11 18:22:02 -0800 | [diff] [blame] | 113 | if (type.equals("requestDetails")) { |
| 114 | requestDetails(event); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 115 | } else if (type.equals("updateMeta")) { |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 116 | updateMetaUi(event); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 117 | } else if (type.equals("requestPath")) { |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 118 | createHostIntent(event); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 119 | } else if (type.equals("requestTraffic")) { |
| 120 | sendTraffic(event); |
| 121 | } else if (type.equals("cancelTraffic")) { |
| 122 | cancelTraffic(event); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 123 | } |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 124 | } catch (Exception e) { |
Thomas Vachuska | 0f6baee | 2014-11-11 15:02:32 -0800 | [diff] [blame] | 125 | log.warn("Unable to parse GUI request {} due to {}", data, e); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 126 | e.printStackTrace(); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 127 | } |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 130 | // Sends the specified data to the client. |
| 131 | private void sendMessage(ObjectNode data) { |
| 132 | try { |
| 133 | connection.sendMessage(data.toString()); |
| 134 | } catch (IOException e) { |
| 135 | e.printStackTrace(); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 136 | } |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 139 | // Sends all controller nodes to the client as node-added messages. |
| 140 | private void sendAllInstances() { |
| 141 | for (ControllerNode node : clusterService.getNodes()) { |
| 142 | sendMessage(instanceMessage(new ClusterEvent(INSTANCE_ADDED, node))); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 143 | } |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 146 | // Sends all devices to the client as device-added messages. |
| 147 | private void sendAllDevices() { |
| 148 | for (Device device : deviceService.getDevices()) { |
| 149 | sendMessage(deviceMessage(new DeviceEvent(DEVICE_ADDED, device))); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 150 | } |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 153 | // Sends all links to the client as link-added messages. |
| 154 | private void sendAllLinks() { |
| 155 | for (Link link : linkService.getLinks()) { |
| 156 | sendMessage(linkMessage(new LinkEvent(LINK_ADDED, link))); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 157 | } |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | // Sends all hosts to the client as host-added messages. |
| 161 | private void sendAllHosts() { |
| 162 | for (Host host : hostService.getHosts()) { |
| 163 | sendMessage(hostMessage(new HostEvent(HOST_ADDED, host))); |
| 164 | } |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | // Sends back device or host details. |
Thomas Vachuska | f1fae00 | 2014-11-11 18:22:02 -0800 | [diff] [blame] | 168 | private void requestDetails(ObjectNode event) { |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 169 | ObjectNode payload = payload(event); |
Thomas Vachuska | f1fae00 | 2014-11-11 18:22:02 -0800 | [diff] [blame] | 170 | String type = string(payload, "class", "unknown"); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 171 | if (type.equals("device")) { |
| 172 | sendMessage(deviceDetails(deviceId(string(payload, "id")), |
| 173 | number(event, "sid"))); |
| 174 | } else if (type.equals("host")) { |
| 175 | sendMessage(hostDetails(hostId(string(payload, "id")), |
| 176 | number(event, "sid"))); |
| 177 | } |
| 178 | } |
| 179 | |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 180 | // Creates host-to-host intent. |
| 181 | private void createHostIntent(ObjectNode event) { |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 182 | ObjectNode payload = payload(event); |
| 183 | long id = number(event, "sid"); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 184 | // TODO: add protection against device ids and non-existent hosts. |
| 185 | HostId one = hostId(string(payload, "one")); |
| 186 | HostId two = hostId(string(payload, "two")); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 187 | |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 188 | HostToHostIntent hostIntent = new HostToHostIntent(appId, one, two, |
| 189 | DefaultTrafficSelector.builder().build(), |
| 190 | DefaultTrafficTreatment.builder().build()); |
| 191 | intentsToMonitor.put(hostIntent.id(), number(event, "sid")); |
| 192 | intentService.submit(hostIntent); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | // Sends traffic message. |
| 196 | private void sendTraffic(ObjectNode event) { |
| 197 | ObjectNode payload = payload(event); |
| 198 | long id = number(event, "sid"); |
| 199 | IntentId intentId = IntentId.valueOf(payload.path("intentId").asLong()); |
| 200 | |
| 201 | if (payload != null) { |
| 202 | payload.put("traffic", true); |
| 203 | sendMessage(envelope("showPath", id, payload)); |
| 204 | } else { |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 205 | sendMessage(warning(id, "No path found")); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
| 209 | // Cancels sending traffic messages. |
| 210 | private void cancelTraffic(ObjectNode event) { |
| 211 | // TODO: implement this |
| 212 | } |
| 213 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 214 | |
| 215 | // Adds all internal listeners. |
| 216 | private void addListeners() { |
| 217 | clusterService.addListener(clusterListener); |
| 218 | deviceService.addListener(deviceListener); |
| 219 | linkService.addListener(linkListener); |
| 220 | hostService.addListener(hostListener); |
| 221 | mastershipService.addListener(mastershipListener); |
| 222 | intentService.addListener(intentListener); |
| 223 | } |
| 224 | |
| 225 | // Removes all internal listeners. |
| 226 | private void removeListeners() { |
| 227 | clusterService.removeListener(clusterListener); |
| 228 | deviceService.removeListener(deviceListener); |
| 229 | linkService.removeListener(linkListener); |
| 230 | hostService.removeListener(hostListener); |
| 231 | mastershipService.removeListener(mastershipListener); |
| 232 | } |
| 233 | |
| 234 | // Cluster event listener. |
| 235 | private class InternalClusterListener implements ClusterEventListener { |
| 236 | @Override |
| 237 | public void event(ClusterEvent event) { |
| 238 | sendMessage(instanceMessage(event)); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 242 | // Device event listener. |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 243 | private class InternalDeviceListener implements DeviceListener { |
| 244 | @Override |
| 245 | public void event(DeviceEvent event) { |
| 246 | sendMessage(deviceMessage(event)); |
| 247 | } |
| 248 | } |
| 249 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 250 | // Link event listener. |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 251 | private class InternalLinkListener implements LinkListener { |
| 252 | @Override |
| 253 | public void event(LinkEvent event) { |
| 254 | sendMessage(linkMessage(event)); |
| 255 | } |
| 256 | } |
| 257 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 258 | // Host event listener. |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 259 | private class InternalHostListener implements HostListener { |
| 260 | @Override |
| 261 | public void event(HostEvent event) { |
| 262 | sendMessage(hostMessage(event)); |
| 263 | } |
| 264 | } |
| 265 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 266 | // Mastership event listener. |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 267 | private class InternalMastershipListener implements MastershipListener { |
| 268 | @Override |
| 269 | public void event(MastershipEvent event) { |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 270 | // TODO: Is DeviceEvent.Type.DEVICE_MASTERSHIP_CHANGED the same? |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 271 | } |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 272 | } |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 273 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 274 | // Intent event listener. |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 275 | private class InternalIntentListener implements IntentListener { |
| 276 | @Override |
| 277 | public void event(IntentEvent event) { |
| 278 | Intent intent = event.subject(); |
| 279 | Long sid = intentsToMonitor.get(intent.id()); |
| 280 | if (sid != null) { |
| 281 | List<Intent> installable = intentService.getInstallableIntents(intent.id()); |
| 282 | if (installable != null && !installable.isEmpty()) { |
| 283 | PathIntent pathIntent = (PathIntent) installable.iterator().next(); |
| 284 | Path path = pathIntent.path(); |
Thomas Vachuska | 0f6baee | 2014-11-11 15:02:32 -0800 | [diff] [blame] | 285 | ObjectNode payload = pathMessage(path, "host") |
| 286 | .put("intentId", intent.id().toString()); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 287 | sendMessage(envelope("showPath", sid, payload)); |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | } |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 292 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 293 | } |
| 294 | |