Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.calendar; |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 17 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 18 | import org.onlab.packet.Ethernet; |
| 19 | import org.onlab.rest.BaseResource; |
| 20 | import org.onlab.util.Tools; |
| 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.core.CoreService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.net.ConnectPoint; |
| 24 | import org.onosproject.net.DeviceId; |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 25 | import org.onosproject.net.HostId; |
| 26 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 27 | import org.onosproject.net.flow.TrafficSelector; |
| 28 | import org.onosproject.net.flow.TrafficTreatment; |
| 29 | import org.onosproject.net.intent.ConnectivityIntent; |
| 30 | import org.onosproject.net.intent.Constraint; |
| 31 | import org.onosproject.net.intent.HostToHostIntent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 32 | import org.onosproject.net.intent.Intent; |
| 33 | import org.onosproject.net.intent.IntentEvent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.net.intent.IntentListener; |
| 35 | import org.onosproject.net.intent.IntentService; |
| 36 | import org.onosproject.net.intent.IntentState; |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 37 | import org.onosproject.net.intent.Key; |
| 38 | import org.onosproject.net.intent.TwoWayP2PIntent; |
| 39 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
| 40 | import org.onosproject.net.intent.constraint.LatencyConstraint; |
| 41 | import org.onosproject.net.resource.Bandwidth; |
| 42 | import org.slf4j.Logger; |
Thomas Vachuska | 56d1a70 | 2014-11-11 19:14:57 -0800 | [diff] [blame] | 43 | |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 44 | import javax.ws.rs.DELETE; |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 45 | import javax.ws.rs.POST; |
| 46 | import javax.ws.rs.PUT; |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 47 | import javax.ws.rs.PathParam; |
| 48 | import javax.ws.rs.core.Response; |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 49 | import java.net.URI; |
| 50 | import java.time.Duration; |
| 51 | import java.time.temporal.ChronoUnit; |
| 52 | import java.util.LinkedList; |
| 53 | import java.util.List; |
| 54 | import java.util.concurrent.CountDownLatch; |
| 55 | import java.util.concurrent.TimeUnit; |
Thomas Vachuska | 56d1a70 | 2014-11-11 19:14:57 -0800 | [diff] [blame] | 56 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 57 | import static org.onosproject.net.PortNumber.portNumber; |
| 58 | import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 59 | import static org.onosproject.net.intent.IntentState.*; |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 60 | import static org.slf4j.LoggerFactory.getLogger; |
Thomas Vachuska | 56d1a70 | 2014-11-11 19:14:57 -0800 | [diff] [blame] | 61 | |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 62 | /** |
| 63 | * Web resource for triggering calendared intents. |
| 64 | */ |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 65 | @javax.ws.rs.Path("intent") |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 66 | public class BandwidthCalendarResource extends BaseResource { |
| 67 | |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 68 | private static final Logger log = getLogger(BandwidthCalendarResource.class); |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 69 | private static final long TIMEOUT = 10; // seconds |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 70 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 71 | private static final String INVALID_PARAMETER = "INVALID_PARAMETER\n"; |
| 72 | private static final String OPERATION_INSTALLED = "INSTALLED\n"; |
| 73 | private static final String OPERATION_FAILED = "FAILED\n"; |
| 74 | private static final String OPERATION_WITHDRAWN = "WITHDRAWN\n"; |
| 75 | |
| 76 | /** |
| 77 | * Setup a bi-directional path with constraints between switch to switch. |
| 78 | * Switch is identified by DPID. |
| 79 | * |
| 80 | * @param src the path source (DPID or hostID) |
| 81 | * @param dst the path destination (DPID or hostID) |
| 82 | * @param srcPort the source port (-1 if src/dest is a host) |
| 83 | * @param dstPort the destination port (-1 if src/dest is a host) |
| 84 | * @param bandwidth the bandwidth (mbps) requirement for the path |
| 85 | * @param latency the latency (micro sec) requirement for the path |
| 86 | * @return intent key if successful, |
| 87 | * server error message or "FAILED" if failed to create or submit intent |
| 88 | */ |
| 89 | @javax.ws.rs.Path("/{src}/{dst}/{srcPort}/{dstPort}/{bandwidth}/{latency}") |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 90 | @POST |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 91 | // TODO could allow applications to provide optional key |
| 92 | // ... if you do, you will need to change from LongKeys to StringKeys |
| 93 | public Response setupPath(@PathParam("src") String src, |
| 94 | @PathParam("dst") String dst, |
| 95 | @PathParam("srcPort") String srcPort, |
| 96 | @PathParam("dstPort") String dstPort, |
| 97 | @PathParam("bandwidth") String bandwidth, |
| 98 | @PathParam("latency") String latency) { |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 99 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 100 | log.info("Path Constraints: Src = {} SrcPort = {} Dest = {} DestPort = {} " + |
| 101 | "BW = {} latency = {}", |
| 102 | src, srcPort, dst, dstPort, bandwidth, latency); |
| 103 | |
| 104 | if (src == null || dst == null || srcPort == null || dstPort == null) { |
| 105 | return Response.ok(INVALID_PARAMETER).build(); |
| 106 | } |
| 107 | |
| 108 | Long bandwidthL = 0L; |
| 109 | Long latencyL = 0L; |
| 110 | try { |
| 111 | bandwidthL = Long.parseLong(bandwidth, 10); |
| 112 | latencyL = Long.parseLong(latency, 10); |
| 113 | } catch (Exception e) { |
| 114 | return Response.ok(INVALID_PARAMETER).build(); |
| 115 | } |
| 116 | |
| 117 | Intent intent = createIntent(null, src, dst, srcPort, dstPort, bandwidthL, latencyL); |
| 118 | try { |
| 119 | if (submitIntent(intent)) { |
| 120 | return Response.ok(intent.key() + "\n").build(); |
| 121 | } else { |
| 122 | return Response.ok(OPERATION_FAILED).build(); |
| 123 | } |
| 124 | } catch (Exception e) { |
| 125 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Modify a bi-directional path's bandwidth. |
| 131 | * |
| 132 | * @param intentKey the path intent key |
| 133 | * @param src the path source (DPID or hostID) |
| 134 | * @param dst the path destination (DPID or hostID) |
| 135 | * @param srcPort the source port (-1 if src/dest is a host) |
| 136 | * @param dstPort the destination port (-1 if src/dest is a host) |
| 137 | * @param bandwidth the bandwidth (mbps) requirement for the path |
| 138 | * @return @return Intent state, "INSTALLED", if successful, |
| 139 | * server error message or "FAILED" if failed to modify any direction intent |
| 140 | */ |
| 141 | @javax.ws.rs.Path("/{intentKey}/{src}/{dst}/{srcPort}/{dstPort}/{bandwidth}") |
| 142 | @PUT |
| 143 | public Response modifyBandwidth(@PathParam("intentKey") String intentKey, |
| 144 | @PathParam("src") String src, |
| 145 | @PathParam("dst") String dst, |
| 146 | @PathParam("srcPort") String srcPort, |
| 147 | @PathParam("dstPort") String dstPort, |
| 148 | @PathParam("bandwidth") String bandwidth) { |
| 149 | |
| 150 | log.info("Modify bw for intentKey = {}; src = {}; dst = {};" + |
| 151 | "srcPort = {}; dstPort = {}; with new bandwidth = {}", |
| 152 | intentKey, src, dst, srcPort, dstPort, bandwidth); |
| 153 | |
| 154 | if (src == null || dst == null || srcPort == null || dstPort == null) { |
| 155 | return Response.ok(INVALID_PARAMETER).build(); |
| 156 | } |
| 157 | |
| 158 | Long bandwidthL = 0L; |
| 159 | try { |
| 160 | bandwidthL = Long.parseLong(bandwidth, 10); |
| 161 | } catch (Exception e) { |
| 162 | return Response.ok(INVALID_PARAMETER).build(); |
| 163 | } |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 164 | |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 165 | IntentService service = get(IntentService.class); |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 166 | Intent originalIntent |
| 167 | = service.getIntent(Key.of(Tools.fromHex(intentKey.replace("0x", "")), appId())); |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 168 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 169 | if (originalIntent == null) { |
| 170 | return Response.status(Response.Status.NOT_FOUND).build(); |
| 171 | } |
| 172 | |
| 173 | // get the latency constraint from the original intent |
| 174 | Long latencyL = 0L; |
| 175 | if (originalIntent instanceof ConnectivityIntent) { |
| 176 | ConnectivityIntent connectivityIntent = (ConnectivityIntent) originalIntent; |
| 177 | for (Constraint constraint : connectivityIntent.constraints()) { |
| 178 | if (constraint instanceof LatencyConstraint) { |
| 179 | latencyL = ((LatencyConstraint) constraint).latency().get(ChronoUnit.MICROS); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | Intent newIntent = createIntent(originalIntent.key(), src, dst, |
| 185 | srcPort, dstPort, bandwidthL, latencyL); |
| 186 | try { |
| 187 | if (submitIntent(newIntent)) { |
| 188 | return Response.ok(OPERATION_INSTALLED).build(); |
| 189 | } else { |
| 190 | return Response.ok(OPERATION_FAILED).build(); |
| 191 | } |
| 192 | } catch (Exception e) { |
| 193 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | |
| 198 | /** |
| 199 | * Create an Intent for a bidirectional path with constraints. |
| 200 | * |
| 201 | * @param key optional intent key |
| 202 | * @param src the path source (DPID or hostID) |
| 203 | * @param dst the path destination (DPID or hostID) |
| 204 | * @param srcPort the source port (-1 if src/dest is a host) |
| 205 | * @param dstPort the destination port (-1 if src/dest is a host) |
| 206 | * @param bandwidth the bandwidth (mbps) requirement for the path |
| 207 | * @param latency the latency (micro sec) requirement for the path |
| 208 | * @return the appropriate intent |
| 209 | */ |
| 210 | private Intent createIntent(Key key, |
| 211 | String src, |
| 212 | String dst, |
| 213 | String srcPort, |
| 214 | String dstPort, |
| 215 | Long bandwidth, |
| 216 | Long latency) { |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 217 | |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 218 | TrafficSelector selector = buildTrafficSelector(); |
| 219 | TrafficTreatment treatment = builder().build(); |
| 220 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 221 | final Constraint constraintBandwidth = |
| 222 | new BandwidthConstraint(Bandwidth.mbps(bandwidth)); |
| 223 | final Constraint constraintLatency = |
| 224 | new LatencyConstraint(Duration.of(latency, ChronoUnit.MICROS)); |
| 225 | final List<Constraint> constraints = new LinkedList<>(); |
| 226 | |
| 227 | constraints.add(constraintBandwidth); |
| 228 | constraints.add(constraintLatency); |
| 229 | |
| 230 | if (srcPort.equals("-1")) { |
| 231 | HostId srcPoint = HostId.hostId(src); |
| 232 | HostId dstPoint = HostId.hostId(dst); |
| 233 | return new HostToHostIntent(appId(), key, srcPoint, dstPoint, |
| 234 | selector, treatment, constraints); |
| 235 | } else { |
| 236 | ConnectPoint srcPoint = new ConnectPoint(deviceId(src), portNumber(srcPort)); |
| 237 | ConnectPoint dstPoint = new ConnectPoint(deviceId(dst), portNumber(dstPort)); |
| 238 | return new TwoWayP2PIntent(appId(), key, srcPoint, dstPoint, |
| 239 | selector, treatment, constraints); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | |
| 244 | /** |
| 245 | * Synchronously submits an intent to the Intent Service. |
| 246 | * |
| 247 | * @param intent intent to submit |
| 248 | * @return true if operation succeed, false otherwise |
| 249 | */ |
| 250 | private boolean submitIntent(Intent intent) |
| 251 | throws InterruptedException { |
| 252 | IntentService service = get(IntentService.class); |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 253 | |
Thomas Vachuska | 56d1a70 | 2014-11-11 19:14:57 -0800 | [diff] [blame] | 254 | CountDownLatch latch = new CountDownLatch(1); |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 255 | InternalIntentListener listener = new InternalIntentListener(intent, service, latch); |
Thomas Vachuska | 56d1a70 | 2014-11-11 19:14:57 -0800 | [diff] [blame] | 256 | service.addListener(listener); |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 257 | service.submit(intent); |
| 258 | log.info("Submitted Calendar App intent and waiting: {}", intent); |
| 259 | if (latch.await(TIMEOUT, TimeUnit.SECONDS) && |
| 260 | listener.getState() == INSTALLED) { |
| 261 | return true; |
Thomas Vachuska | 56d1a70 | 2014-11-11 19:14:57 -0800 | [diff] [blame] | 262 | } |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 263 | return false; |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 266 | /** |
| 267 | * Remove a bi-directional path with created intent key. |
| 268 | * |
| 269 | * @param intentKey the string key for the intent to remove |
| 270 | * @return Intent state, "WITHDRAWN", if successful, |
| 271 | * server error message or FAILED" if any direction intent remove failed |
| 272 | */ |
| 273 | @javax.ws.rs.Path("/{intentKey}") |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 274 | @DELETE |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 275 | public Response removePath(@PathParam("intentKey") String intentKey) { |
| 276 | |
| 277 | log.info("Receiving tear down request for {}", intentKey); |
| 278 | |
| 279 | if (intentKey == null) { |
| 280 | return Response.ok(INVALID_PARAMETER).build(); |
Thomas Vachuska | 56d1a70 | 2014-11-11 19:14:57 -0800 | [diff] [blame] | 281 | } |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 282 | |
| 283 | IntentService service = get(IntentService.class); |
| 284 | Intent intent = service.getIntent(Key.of(Tools.fromHex(intentKey.replace("0x", "")), appId())); |
| 285 | |
| 286 | if (intent == null) { |
| 287 | return Response.status(Response.Status.NOT_FOUND).build(); |
| 288 | } |
| 289 | |
| 290 | try { |
| 291 | if (withdrawIntent(intent)) { |
| 292 | return Response.ok(OPERATION_WITHDRAWN).build(); |
| 293 | } else { |
| 294 | return Response.ok(OPERATION_FAILED).build(); |
| 295 | } |
| 296 | } catch (Exception e) { |
| 297 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); |
| 298 | } |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 301 | /** |
| 302 | * Synchronously withdraws an intent to the Intent Service. |
| 303 | * |
| 304 | * @param intent intent to submit |
| 305 | * @return true if operation succeed, false otherwise |
| 306 | */ |
| 307 | private boolean withdrawIntent(Intent intent) |
| 308 | throws InterruptedException { |
| 309 | IntentService service = get(IntentService.class); |
Hongtao Yin | 621c57a | 2014-10-30 14:28:03 -0700 | [diff] [blame] | 310 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 311 | CountDownLatch latch = new CountDownLatch(1); |
| 312 | InternalIntentListener listener = new InternalIntentListener(intent, service, latch); |
| 313 | service.addListener(listener); |
| 314 | service.withdraw(intent); |
| 315 | log.info("Withdrawing intent and waiting: {}", intent); |
| 316 | if (latch.await(TIMEOUT, TimeUnit.SECONDS) && |
| 317 | listener.getState() == WITHDRAWN) { |
| 318 | return true; |
| 319 | } |
| 320 | return false; |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 323 | |
| 324 | private static TrafficSelector buildTrafficSelector() { |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 325 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
| 326 | Short ethType = Ethernet.TYPE_IPV4; |
| 327 | |
| 328 | selectorBuilder.matchEthType(ethType); |
| 329 | |
| 330 | return selectorBuilder.build(); |
| 331 | } |
| 332 | |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 333 | private static DeviceId deviceId(String dpid) { |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 334 | return DeviceId.deviceId(URI.create("of:" + dpid)); |
| 335 | } |
| 336 | |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 337 | protected ApplicationId appId() { |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 338 | return get(CoreService.class).registerApplication("org.onosproject.calendar"); |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 339 | } |
Thomas Vachuska | 56d1a70 | 2014-11-11 19:14:57 -0800 | [diff] [blame] | 340 | |
| 341 | // Auxiliary listener to wait until the given intent reaches the installed or failed states. |
| 342 | private final class InternalIntentListener implements IntentListener { |
| 343 | private final Intent intent; |
| 344 | private final IntentService service; |
| 345 | private final CountDownLatch latch; |
| 346 | private IntentState state; |
| 347 | |
| 348 | private InternalIntentListener(Intent intent, IntentService service, |
| 349 | CountDownLatch latch) { |
| 350 | this.intent = intent; |
| 351 | this.service = service; |
| 352 | this.latch = latch; |
| 353 | } |
| 354 | |
| 355 | @Override |
| 356 | public void event(IntentEvent event) { |
| 357 | if (event.subject().equals(intent)) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 358 | state = service.getIntentState(intent.key()); |
Thomas Vachuska | 56d1a70 | 2014-11-11 19:14:57 -0800 | [diff] [blame] | 359 | if (state == INSTALLED || state == FAILED || state == WITHDRAWN) { |
| 360 | latch.countDown(); |
Hongtao Yin | 36f79aa | 2015-02-14 03:51:39 -0800 | [diff] [blame^] | 361 | service.removeListener(this); |
Thomas Vachuska | 56d1a70 | 2014-11-11 19:14:57 -0800 | [diff] [blame] | 362 | } |
Thomas Vachuska | 56d1a70 | 2014-11-11 19:14:57 -0800 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | public IntentState getState() { |
| 367 | return state; |
| 368 | } |
| 369 | } |
Thomas Vachuska | 140d585 | 2014-10-16 12:17:45 -0700 | [diff] [blame] | 370 | } |