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

Side by Side Diff: runtime/observatory/lib/src/service/object.dart

Issue 1143783003: Add the streamListen and streamCancel rpcs to the vm service. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanups pre-review Created 5 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 service; 5 part of service;
6 6
7 /// An RpcException represents an exceptional event that happened 7 /// An RpcException represents an exceptional event that happened
8 /// while invoking an rpc. 8 /// while invoking an rpc.
9 abstract class RpcException implements Exception { 9 abstract class RpcException implements Exception {
10 RpcException(this.message); 10 RpcException(this.message);
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 @observable Duration get upTime => 422 @observable Duration get upTime =>
423 (new DateTime.now().difference(startTime)); 423 (new DateTime.now().difference(startTime));
424 424
425 VM() : super._empty(null) { 425 VM() : super._empty(null) {
426 name = 'vm'; 426 name = 'vm';
427 vmName = 'vm'; 427 vmName = 'vm';
428 _cache['vm'] = this; 428 _cache['vm'] = this;
429 update(toObservable({'id':'vm', 'type':'@VM'})); 429 update(toObservable({'id':'vm', 'type':'@VM'}));
430 } 430 }
431 431
432 final StreamController<ServiceEvent> events = 432 Future streamListen(String streamId) {
433 new StreamController.broadcast(); 433 return invokeRpc('streamListen', {'streamId': streamId});
434 }
434 435
435 void postServiceEvent(Map response, ByteData data) { 436 Future streamCancel(String streamId) {
437 return invokeRpc('streamCancel', {'streamId': streamId});
438 }
439
440 static const kIsolateEventStreamId = 'Isolate';
441 static const kDebugEventStreamId = 'Debug';
442 static const kGCEventStreamId = 'GC';
443
444 Map<String,StreamController> _streamControllers = {};
445
446 void _streamListenHandleError(String streamId) {
447 streamListen(streamId).catchError((e, st) {
448 _getEventStreamController(streamId).addError(e, st);
449 });
450 }
451
452 void _streamCancelHandleError(String streamId) {
453 // TODO(turnidge): Consider removing the controller from the map here.
454 streamCancel(streamId).catchError((e, st) {
455 _getEventStreamController(streamId).addError(e, st);
456 });
457 }
458
459 StreamController _getEventStreamController(String streamId) {
460 var controller = _streamControllers.putIfAbsent(
461 streamId, () {
462 return new StreamController.broadcast(
463 onListen: () => _streamListenHandleError(streamId),
464 onCancel: () => _streamCancelHandleError(streamId));
465 });
466 return controller;
467 }
468
469 Stream getEventStream(String streamId) {
470 return _getEventStreamController(streamId).stream;
471 }
472
473 Stream get isolateEvents => getEventStream(kIsolateEventStreamId);
474 Stream get debugEvents => getEventStream(kDebugEventStreamId);
475 Stream get gcEvents => getEventStream(kGCEventStreamId);
476
477 void postServiceEvent(String streamId, Map response, ByteData data) {
478 assert(streamId != null);
436 var map = toObservable(response); 479 var map = toObservable(response);
437 assert(!map.containsKey('_data')); 480 assert(!map.containsKey('_data'));
438 if (data != null) { 481 if (data != null) {
439 map['_data'] = data; 482 map['_data'] = data;
440 } 483 }
441 if (map['type'] != 'ServiceEvent') { 484 if (map['type'] != 'ServiceEvent') {
442 Logger.root.severe( 485 Logger.root.severe(
443 "Expected 'ServiceEvent' but found '${map['type']}'"); 486 "Expected 'ServiceEvent' but found '${map['type']}'");
444 return; 487 return;
445 } 488 }
446 489
447 var eventIsolate = map['isolate']; 490 var eventIsolate = map['isolate'];
491 var event;
448 if (eventIsolate == null) { 492 if (eventIsolate == null) {
449 var event = new ServiceObject._fromMap(vm, map); 493 event = new ServiceObject._fromMap(vm, map);
450 events.add(event);
451 } else { 494 } else {
452 // getFromMap creates the Isolate if it hasn't been seen already. 495 // getFromMap creates the Isolate if it hasn't been seen already.
453 var isolate = getFromMap(map['isolate']); 496 var isolate = getFromMap(map['isolate']);
454 var event = new ServiceObject._fromMap(isolate, map); 497 event = new ServiceObject._fromMap(isolate, map);
455 if (event.eventType == ServiceEvent.kIsolateExit) { 498 if (event.eventType == ServiceEvent.kIsolateExit) {
456 _removeIsolate(isolate.id); 499 _removeIsolate(isolate.id);
457 } 500 }
501 // Give the isolate a chance to process the event first before
502 // dispatching it to others.
458 isolate._onEvent(event); 503 isolate._onEvent(event);
459 events.add(event);
460 } 504 }
505 _getEventStreamController(streamId).add(event);
461 } 506 }
462 507
463 void _removeIsolate(String isolateId) { 508 void _removeIsolate(String isolateId) {
464 assert(_isolateCache.containsKey(isolateId)); 509 assert(_isolateCache.containsKey(isolateId));
465 _isolateCache.remove(isolateId); 510 _isolateCache.remove(isolateId);
466 notifyPropertyChange(#isolates, true, false); 511 notifyPropertyChange(#isolates, true, false);
467 } 512 }
468 513
469 void _removeDeadIsolates(List newIsolates) { 514 void _removeDeadIsolates(List newIsolates) {
470 // Build a set of new isolates. 515 // Build a set of new isolates.
(...skipping 2639 matching lines...) Expand 10 before | Expand all | Expand 10 after
3110 var v = list[i]; 3155 var v = list[i];
3111 if ((v is ObservableMap) && _isServiceMap(v)) { 3156 if ((v is ObservableMap) && _isServiceMap(v)) {
3112 list[i] = owner.getFromMap(v); 3157 list[i] = owner.getFromMap(v);
3113 } else if (v is ObservableList) { 3158 } else if (v is ObservableList) {
3114 _upgradeObservableList(v, owner); 3159 _upgradeObservableList(v, owner);
3115 } else if (v is ObservableMap) { 3160 } else if (v is ObservableMap) {
3116 _upgradeObservableMap(v, owner); 3161 _upgradeObservableMap(v, owner);
3117 } 3162 }
3118 } 3163 }
3119 } 3164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698