OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 part of vmservice; | |
6 | |
7 class RunningIsolates implements ServiceRequestRouter { | |
8 final Map<int, RunningIsolate> isolates = new Map<int, RunningIsolate>(); | |
9 | |
10 RunningIsolates(); | |
11 | |
12 | |
siva
2013/07/19 17:41:16
extra blank line?
Cutch
2013/07/19 18:15:02
Done.
| |
13 void isolateStartup(SendPort sp) { | |
14 if (isolates[sp.hashCode] != null) { | |
15 throw new StateError('Duplicate isolate startup.'); | |
16 } | |
17 RunningIsolate ri = new RunningIsolate(sp); | |
18 isolates[sp.hashCode] = ri; | |
19 ri.sendIdRequest(); | |
20 } | |
21 | |
22 | |
23 void isolateShutdown(SendPort sp) { | |
24 if (isolates[sp.hashCode] == null) { | |
25 throw new StateError('Unknown isolate.'); | |
26 } | |
27 isolates.remove(sp.hashCode); | |
28 } | |
29 | |
30 | |
31 void _isolateCollectionRequest(ServiceRequest request) { | |
32 List members = []; | |
33 Map result = {}; | |
34 isolates.forEach((sp, ri) { | |
35 members.add({ | |
36 'id': sp, | |
37 'name': ri.id | |
38 }); | |
39 }); | |
40 result['type'] = 'IsolateList'; | |
41 result['members'] = members; | |
42 request.setResponse(JSON.stringify(result)); | |
43 } | |
44 | |
45 | |
46 bool route(ServiceRequest request) { | |
47 if (request.pathSegments.length == 0) { | |
48 return false; | |
49 } | |
50 if (request.pathSegments[0] != 'isolates') { | |
51 return false; | |
52 } | |
53 if (request.pathSegments.length == 1) { | |
54 // Requesting list of running isolates. | |
55 _isolateCollectionRequest(request); | |
56 return true; | |
57 } | |
58 int isolateId; | |
59 try { | |
60 isolateId = int.parse(request.pathSegments[1]); | |
61 } catch (e) { | |
62 request.setErrorResponse('Could not parse isolate id: $e'); | |
siva
2013/07/19 17:41:16
Not sure what the guide line is with messages in c
Cutch
2013/07/19 18:15:02
Eventually, yes. But, I don't think any other erro
| |
63 return true; | |
64 } | |
65 RunningIsolate isolate = isolates[isolateId]; | |
66 if (isolate == null) { | |
67 request.setErrorResponse('Cannot find isolate id: $isolateId'); | |
68 return true; | |
69 } | |
70 // Consume '/isolates/isolateId' | |
71 request.pathSegments.removeRange(0, 2); | |
72 return isolate.route(request); | |
73 } | |
74 | |
75 } | |
76 | |
OLD | NEW |