| 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 Observable { | 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<String, Isolate> isolates = | 12 @observable final Map<String, Isolate> isolates = |
| 13 toObservable(new Map<String, Isolate>()); | 13 toObservable(new Map<String, Isolate>()); |
| 14 | 14 |
| 15 static bool _foundIsolateInMembers(String id, List<Map> members) { | 15 static bool _foundIsolateInMembers(String 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 Isolate getIsolate(String id) { | 27 Isolate getIsolate(String id) { |
| 28 Isolate isolate = isolates[id]; | 28 Isolate isolate = isolates[id]; |
| 29 if (isolate == null) { | 29 if (isolate == null) { |
| 30 isolate = new Isolate(id, id); | 30 isolate = new Isolate.fromId(id); |
| 31 isolates[id] = isolate; | 31 isolates[id] = isolate; |
| 32 return isolate; | 32 return isolate; |
| 33 } | 33 } |
| 34 return isolate; | 34 return isolate; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void _updateIsolates(List<Map> members) { | 37 void _updateIsolates(List<Map> members) { |
| 38 // Find dead isolates. | 38 // Find dead isolates. |
| 39 var deadIsolates = []; | 39 var deadIsolates = []; |
| 40 isolates.forEach((k, v) { | 40 isolates.forEach((k, v) { |
| 41 if (!_foundIsolateInMembers(k, members)) { | 41 if (!_foundIsolateInMembers(k, members)) { |
| 42 deadIsolates.add(k); | 42 deadIsolates.add(k); |
| 43 } | 43 } |
| 44 }); | 44 }); |
| 45 // Remove them. | 45 // Remove them. |
| 46 deadIsolates.forEach((k) { | 46 deadIsolates.forEach((id) { |
| 47 isolates.remove(k); | 47 isolates.remove(id); |
| 48 }); | 48 }); |
| 49 // Add new isolates. | 49 // Add new isolates. |
| 50 members.forEach((k) { | 50 members.forEach((map) { |
| 51 var id = k['id']; | 51 var id = map['id']; |
| 52 var name = k['name']; | 52 var isolate = isolates[id]; |
| 53 if (isolates[id] == null) { | 53 if (isolate == null) { |
| 54 var isolate = new Isolate(id, name); | 54 isolate = new Isolate.fromMap(map); |
| 55 isolates[id] = isolate; | 55 isolates[id] = isolate; |
| 56 } else { | |
| 57 isolates[id].name = name; | |
| 58 } | 56 } |
| 57 isolate.refresh(); |
| 59 }); | 58 }); |
| 60 } | 59 } |
| 61 } | 60 } |
| OLD | NEW |