| 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 observatory; | 5 part of observatory; |
| 6 | 6 |
| 7 /// Collection of isolates which are running in the VM. Updated | 7 /// Collection of isolates which are running in the VM. Updated |
| 8 class IsolateManager extends ObservableMixin { | 8 class IsolateManager extends Observable { |
| 9 ObservatoryApplication _application; | 9 ObservatoryApplication _application; |
| 10 ObservatoryApplication get application => _application; | 10 ObservatoryApplication get application => _application; |
| 11 | 11 |
| 12 @observable final Map<int, Isolate> isolates = | 12 @observable final Map<int, Isolate> isolates = |
| 13 toObservable(new Map<int, Isolate>()); | 13 toObservable(new Map<int, Isolate>()); |
| 14 | 14 |
| 15 static bool _foundIsolateInMembers(int id, List<Map> members) { | 15 static bool _foundIsolateInMembers(int id, List<Map> members) { |
| 16 return members.any((E) => E['id'] == id); | 16 return members.any((E) => E['id'] == id); |
| 17 } | 17 } |
| 18 | 18 |
| 19 void _responseInterceptor() { | 19 void _responseInterceptor() { |
| 20 _application.requestManager.responses.forEach((response) { | 20 _application.requestManager.responses.forEach((response) { |
| 21 if (response['type'] == 'IsolateList') { | 21 if (response['type'] == 'IsolateList') { |
| 22 _updateIsolates(response['members']); | 22 _updateIsolates(response['members']); |
| 23 } | 23 } |
| 24 }); | 24 }); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void _updateIsolates(List<Map> members) { | 27 void _updateIsolates(List<Map> members) { |
| 28 // Find dead isolates. | 28 // Find dead isolates. |
| 29 var deadIsolates = []; | 29 var deadIsolates = []; |
| 30 isolates.forEach((k, v) { | 30 isolates.forEach((k, v) { |
| 31 if (!_foundIsolateInMembers(k, members)) { | 31 if (!_foundIsolateInMembers(k, members)) { |
| 32 deadIsolates.add(k); | 32 deadIsolates.add(k); |
| 33 } | 33 } |
| 34 }); | 34 }); |
| 35 // Remove them. | 35 // Remove them. |
| 36 deadIsolates.forEach((k) { | 36 deadIsolates.forEach((k) { |
| 37 print('Removing ${isolates[k]}'); | |
| 38 isolates.remove(k); | 37 isolates.remove(k); |
| 39 }); | 38 }); |
| 40 // Add new isolates. | 39 // Add new isolates. |
| 41 members.forEach((k) { | 40 members.forEach((k) { |
| 42 var id = k['id']; | 41 var id = k['id']; |
| 43 var name = k['name']; | 42 var name = k['name']; |
| 44 if (isolates[id] == null) { | 43 if (isolates[id] == null) { |
| 45 var isolate = new Isolate(id, name); | 44 var isolate = new Isolate(id, name); |
| 46 print('Adding $isolate'); | |
| 47 isolates[id] = isolate; | 45 isolates[id] = isolate; |
| 48 } | 46 } |
| 49 }); | 47 }); |
| 50 } | 48 } |
| 51 } | 49 } |
| OLD | NEW |