Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Unified Diff: runtime/bin/vmservice/running_isolates.dart

Issue 19622003: VM Service isolate listing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/vmservice/running_isolates.dart
diff --git a/runtime/bin/vmservice/running_isolates.dart b/runtime/bin/vmservice/running_isolates.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f43d754e6b70da505c98eea1b641cca044998cce
--- /dev/null
+++ b/runtime/bin/vmservice/running_isolates.dart
@@ -0,0 +1,76 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of vmservice;
+
+class RunningIsolates implements ServiceRequestRouter {
+ final Map<int, RunningIsolate> isolates = new Map<int, RunningIsolate>();
+
+ RunningIsolates();
+
+
siva 2013/07/19 17:41:16 extra blank line?
Cutch 2013/07/19 18:15:02 Done.
+ void isolateStartup(SendPort sp) {
+ if (isolates[sp.hashCode] != null) {
+ throw new StateError('Duplicate isolate startup.');
+ }
+ RunningIsolate ri = new RunningIsolate(sp);
+ isolates[sp.hashCode] = ri;
+ ri.sendIdRequest();
+ }
+
+
+ void isolateShutdown(SendPort sp) {
+ if (isolates[sp.hashCode] == null) {
+ throw new StateError('Unknown isolate.');
+ }
+ isolates.remove(sp.hashCode);
+ }
+
+
+ void _isolateCollectionRequest(ServiceRequest request) {
+ List members = [];
+ Map result = {};
+ isolates.forEach((sp, ri) {
+ members.add({
+ 'id': sp,
+ 'name': ri.id
+ });
+ });
+ result['type'] = 'IsolateList';
+ result['members'] = members;
+ request.setResponse(JSON.stringify(result));
+ }
+
+
+ bool route(ServiceRequest request) {
+ if (request.pathSegments.length == 0) {
+ return false;
+ }
+ if (request.pathSegments[0] != 'isolates') {
+ return false;
+ }
+ if (request.pathSegments.length == 1) {
+ // Requesting list of running isolates.
+ _isolateCollectionRequest(request);
+ return true;
+ }
+ int isolateId;
+ try {
+ isolateId = int.parse(request.pathSegments[1]);
+ } catch (e) {
+ 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
+ return true;
+ }
+ RunningIsolate isolate = isolates[isolateId];
+ if (isolate == null) {
+ request.setErrorResponse('Cannot find isolate id: $isolateId');
+ return true;
+ }
+ // Consume '/isolates/isolateId'
+ request.pathSegments.removeRange(0, 2);
+ return isolate.route(request);
+ }
+
+}
+

Powered by Google App Engine
This is Rietveld 408576698