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

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: before commit Created 5 years, 6 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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 @observable Duration get upTime => 425 @observable Duration get upTime =>
426 (new DateTime.now().difference(startTime)); 426 (new DateTime.now().difference(startTime));
427 427
428 VM() : super._empty(null) { 428 VM() : super._empty(null) {
429 name = 'vm'; 429 name = 'vm';
430 vmName = 'vm'; 430 vmName = 'vm';
431 _cache['vm'] = this; 431 _cache['vm'] = this;
432 update(toObservable({'id':'vm', 'type':'@VM'})); 432 update(toObservable({'id':'vm', 'type':'@VM'}));
433 } 433 }
434 434
435 final StreamController<ServiceEvent> events = 435 Future streamListen(String streamId) {
436 new StreamController.broadcast(); 436 return invokeRpc('streamListen', {'streamId': streamId});
437 }
437 438
438 void postServiceEvent(Map response, ByteData data) { 439 Future streamCancel(String streamId) {
440 return invokeRpc('streamCancel', {'streamId': streamId});
441 }
442
443 static const kIsolateEventStreamId = 'Isolate';
444 static const kDebugEventStreamId = 'Debug';
445 static const kGCEventStreamId = 'GC';
446
447 Map<String,StreamController> _streamControllers = {};
448
449 void _streamListenHandleError(String streamId) {
450 streamListen(streamId).catchError((e, st) {
451 _getEventStreamController(streamId).addError(e, st);
452 });
453 }
454
455 void _streamCancelHandleError(String streamId) {
456 // TODO(turnidge): Consider removing the controller from the map here.
457 streamCancel(streamId).catchError((e, st) {
458 _getEventStreamController(streamId).addError(e, st);
459 });
460 }
461
462 StreamController _getEventStreamController(String streamId) {
463 var controller = _streamControllers.putIfAbsent(
464 streamId, () {
465 return new StreamController.broadcast(
466 onListen: () => _streamListenHandleError(streamId),
467 onCancel: () => _streamCancelHandleError(streamId));
468 });
469 return controller;
470 }
471
472 Stream getEventStream(String streamId) {
473 return _getEventStreamController(streamId).stream;
474 }
475
476 Stream get isolateEvents => getEventStream(kIsolateEventStreamId);
477 Stream get debugEvents => getEventStream(kDebugEventStreamId);
478 Stream get gcEvents => getEventStream(kGCEventStreamId);
479
480 void postServiceEvent(String streamId, Map response, ByteData data) {
481 assert(streamId != null);
439 var map = toObservable(response); 482 var map = toObservable(response);
440 assert(!map.containsKey('_data')); 483 assert(!map.containsKey('_data'));
441 if (data != null) { 484 if (data != null) {
442 map['_data'] = data; 485 map['_data'] = data;
443 } 486 }
444 if (map['type'] != 'ServiceEvent') { 487 if (map['type'] != 'ServiceEvent') {
445 Logger.root.severe( 488 Logger.root.severe(
446 "Expected 'ServiceEvent' but found '${map['type']}'"); 489 "Expected 'ServiceEvent' but found '${map['type']}'");
447 return; 490 return;
448 } 491 }
449 492
450 var eventIsolate = map['isolate']; 493 var eventIsolate = map['isolate'];
494 var event;
451 if (eventIsolate == null) { 495 if (eventIsolate == null) {
452 var event = new ServiceObject._fromMap(vm, map); 496 event = new ServiceObject._fromMap(vm, map);
453 events.add(event);
454 } else { 497 } else {
455 // getFromMap creates the Isolate if it hasn't been seen already. 498 // getFromMap creates the Isolate if it hasn't been seen already.
456 var isolate = getFromMap(map['isolate']); 499 var isolate = getFromMap(map['isolate']);
457 var event = new ServiceObject._fromMap(isolate, map); 500 event = new ServiceObject._fromMap(isolate, map);
458 if (event.eventType == ServiceEvent.kIsolateExit) { 501 if (event.eventType == ServiceEvent.kIsolateExit) {
459 _removeIsolate(isolate.id); 502 _removeIsolate(isolate.id);
460 } 503 }
504 // Give the isolate a chance to process the event first before
505 // dispatching it to others.
461 isolate._onEvent(event); 506 isolate._onEvent(event);
462 events.add(event);
463 } 507 }
508 _getEventStreamController(streamId).add(event);
464 } 509 }
465 510
466 void _removeIsolate(String isolateId) { 511 void _removeIsolate(String isolateId) {
467 assert(_isolateCache.containsKey(isolateId)); 512 assert(_isolateCache.containsKey(isolateId));
468 _isolateCache.remove(isolateId); 513 _isolateCache.remove(isolateId);
469 notifyPropertyChange(#isolates, true, false); 514 notifyPropertyChange(#isolates, true, false);
470 } 515 }
471 516
472 void _removeDeadIsolates(List newIsolates) { 517 void _removeDeadIsolates(List newIsolates) {
473 // Build a set of new isolates. 518 // Build a set of new isolates.
(...skipping 2639 matching lines...) Expand 10 before | Expand all | Expand 10 after
3113 var v = list[i]; 3158 var v = list[i];
3114 if ((v is ObservableMap) && _isServiceMap(v)) { 3159 if ((v is ObservableMap) && _isServiceMap(v)) {
3115 list[i] = owner.getFromMap(v); 3160 list[i] = owner.getFromMap(v);
3116 } else if (v is ObservableList) { 3161 } else if (v is ObservableList) {
3117 _upgradeObservableList(v, owner); 3162 _upgradeObservableList(v, owner);
3118 } else if (v is ObservableMap) { 3163 } else if (v is ObservableMap) {
3119 _upgradeObservableMap(v, owner); 3164 _upgradeObservableMap(v, owner);
3120 } 3165 }
3121 } 3166 }
3122 } 3167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698