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

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
« no previous file with comments | « runtime/bin/vmservice/running_isolate.dart ('k') | runtime/bin/vmservice/server.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7e81f7c1bfd1d42123ecf09050f2656b0bd4c4ff
--- /dev/null
+++ b/runtime/bin/vmservice/running_isolates.dart
@@ -0,0 +1,70 @@
+// 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();
+
+ void isolateStartup(SendPort sp) {
+ if (isolates[sp.hashCode] != null) {
+ throw new StateError('Duplicate isolate startup.');
+ }
+ var 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) {
+ var members = [];
+ var 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;
+ }
+ var isolateId;
+ try {
+ isolateId = int.parse(request.pathSegments[1]);
+ } catch (e) {
+ request.setErrorResponse('Could not parse isolate id: $e');
+ return true;
+ }
+ var 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);
+ }
+}
« no previous file with comments | « runtime/bin/vmservice/running_isolate.dart ('k') | runtime/bin/vmservice/server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698