Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of vmservice; | 5 part of vmservice; |
| 6 | 6 |
| 7 class RunningIsolates implements ServiceRequestRouter { | 7 class RunningIsolates implements MessageRouter { |
| 8 final Map<int, RunningIsolate> isolates = new Map<int, RunningIsolate>(); | 8 final Map<int, RunningIsolate> isolates = new Map<int, RunningIsolate>(); |
| 9 | 9 |
| 10 RunningIsolates(); | 10 RunningIsolates(); |
| 11 | 11 |
| 12 void isolateStartup(int portId, SendPort sp, String name) { | 12 void isolateStartup(int portId, SendPort sp, String name) { |
| 13 if (isolates[portId] != null) { | 13 if (isolates[portId] != null) { |
| 14 throw new StateError('Duplicate isolate startup.'); | 14 throw new StateError('Duplicate isolate startup.'); |
| 15 } | 15 } |
| 16 var ri = new RunningIsolate(portId, sp, name); | 16 var ri = new RunningIsolate(portId, sp, name); |
| 17 isolates[portId] = ri; | 17 isolates[portId] = ri; |
| 18 } | 18 } |
| 19 | 19 |
| 20 void isolateShutdown(int portId, SendPort sp) { | 20 void isolateShutdown(int portId, SendPort sp) { |
| 21 if (isolates[portId] == null) { | 21 if (isolates[portId] == null) { |
| 22 throw new StateError('Unknown isolate.'); | 22 throw new StateError('Unknown isolate.'); |
| 23 } | 23 } |
| 24 isolates.remove(portId); | 24 isolates.remove(portId); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void _isolateCollectionRequest(ServiceRequest request) { | 27 void _isolateCollectionRequest(Message message) { |
| 28 var members = []; | 28 var members = []; |
| 29 var result = {}; | 29 var result = {}; |
| 30 isolates.forEach((portId, runningIsolate) { | 30 isolates.forEach((portId, runningIsolate) { |
| 31 members.add({ | 31 members.add({ |
| 32 'id': portId, | 32 'id': portId, |
| 33 'name': runningIsolate.name | 33 'name': runningIsolate.name |
| 34 }); | 34 }); |
| 35 }); | 35 }); |
| 36 result['type'] = 'IsolateList'; | 36 result['type'] = 'IsolateList'; |
| 37 result['members'] = members; | 37 result['members'] = members; |
| 38 request.setResponse(JSON.encode(result)); | 38 message.setResponse(JSON.encode(result)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 Future route(ServiceRequest request) { | 41 Future route(Message message) { |
| 42 if (request.pathSegments.length == 0) { | 42 if (message.path.length == 0) { |
| 43 request.setErrorResponse('No path.'); | 43 message.setErrorResponse('No path.'); |
| 44 return new Future.value(request); | 44 return message.future; |
| 45 } | 45 } |
| 46 if (request.pathSegments[0] != 'isolates') { | 46 if (message.path[0] != 'isolates') { |
| 47 request.setErrorResponse('Path must begin with /isolates/.'); | 47 message.setErrorResponse('Path must begin with /isolates/.'); |
| 48 return new Future.value(request); | 48 return message.future; |
| 49 } | 49 } |
| 50 if (request.pathSegments.length == 1) { | 50 if (message.path.length == 1) { |
| 51 // Requesting list of running isolates. | 51 // Requesting list of running isolates. |
| 52 _isolateCollectionRequest(request); | 52 _isolateCollectionRequest(message); |
| 53 return new Future.value(request); | 53 return message.future; |
| 54 } | 54 } |
| 55 var isolateId; | 55 var isolateId; |
| 56 try { | 56 try { |
| 57 isolateId = int.parse(request.pathSegments[1]); | 57 isolateId = int.parse(message.path[1]); |
| 58 } catch (e) { | 58 } catch (e) { |
| 59 request.setErrorResponse('Could not parse isolate id: $e'); | 59 message.setErrorResponse('Could not parse isolate id: $e'); |
| 60 return new Future.value(request); | 60 return message.future; |
| 61 } | 61 } |
| 62 var isolate = isolates[isolateId]; | 62 var isolate = isolates[isolateId]; |
| 63 if (isolate == null) { | 63 if (isolate == null) { |
| 64 request.setErrorResponse('Cannot find isolate id: $isolateId'); | 64 message.setErrorResponse('Cannot find isolate id: $isolateId'); |
| 65 return new Future.value(request); | 65 return message.future; |
| 66 } | 66 } |
| 67 // Consume '/isolates/isolateId' | 67 // Consume '/isolates/isolateId' |
| 68 request.pathSegments.removeRange(0, 2); | 68 message.path.removeRange(0, 2); |
| 69 if (request.pathSegments.length == 0) { | 69 if (message.path.length == 0) { |
| 70 // The request is now empty. | 70 // The message now has an empty path. |
| 71 request.setErrorResponse('No request for isolate: /isolates/$isolateId'); | 71 message.setErrorResponse('Empty path for isolate: /isolates/$isolateId'); |
|
turnidge
2013/12/11 17:56:07
btw, I think we should have an <isolate-view> page
Cutch
2013/12/12 22:37:42
There is an <isolate-summary> which sounds similar
| |
| 72 return new Future.value(request); | 72 return message.future; |
| 73 } | 73 } |
| 74 return isolate.route(request); | 74 return isolate.route(message); |
| 75 } | 75 } |
| 76 } | 76 } |
| OLD | NEW |