| 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 observatory; | |
| 6 | |
| 7 /// Collection of isolates which are running in the VM. Updated | |
| 8 class IsolateManager extends Observable { | |
| 9 ObservatoryApplication _application; | |
| 10 ObservatoryApplication get application => _application; | |
| 11 | |
| 12 @observable final Map<String, Isolate> isolates = | |
| 13 toObservable(new Map<String, Isolate>()); | |
| 14 | |
| 15 static bool _foundIsolateInMembers(String id, List<Map> members) { | |
| 16 return members.any((E) => E['id'] == id); | |
| 17 } | |
| 18 | |
| 19 void _responseInterceptor() { | |
| 20 _application.requestManager.responses.forEach((response) { | |
| 21 if (response['type'] == 'IsolateList') { | |
| 22 _updateIsolates(response['members']); | |
| 23 } | |
| 24 }); | |
| 25 } | |
| 26 | |
| 27 Isolate getIsolate(String id) { | |
| 28 Isolate isolate = isolates[id]; | |
| 29 if (isolate == null) { | |
| 30 isolate = new Isolate.fromId(id); | |
| 31 isolates[id] = isolate; | |
| 32 } | |
| 33 if (isolate.vmName == null) { | |
| 34 // First time we are using this isolate. | |
| 35 isolate.refresh(); | |
| 36 } | |
| 37 return isolate; | |
| 38 } | |
| 39 | |
| 40 void _updateIsolates(List<Map> members) { | |
| 41 // Find dead isolates. | |
| 42 var deadIsolates = []; | |
| 43 isolates.forEach((k, v) { | |
| 44 if (!_foundIsolateInMembers(k, members)) { | |
| 45 deadIsolates.add(k); | |
| 46 } | |
| 47 }); | |
| 48 // Remove them. | |
| 49 deadIsolates.forEach((id) { | |
| 50 isolates.remove(id); | |
| 51 }); | |
| 52 // Add new isolates. | |
| 53 members.forEach((map) { | |
| 54 var id = map['id']; | |
| 55 var isolate = isolates[id]; | |
| 56 if (isolate == null) { | |
| 57 isolate = new Isolate.fromMap(map); | |
| 58 isolates[id] = isolate; | |
| 59 } | |
| 60 isolate.refresh(); | |
| 61 }); | |
| 62 } | |
| 63 } | |
| OLD | NEW |