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

Side by Side Diff: pkg/analysis_server/lib/src/protocol.dart

Issue 865383002: add optional request field to record time at which client made request (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 11 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
« no previous file with comments | « pkg/analysis_server/doc/api.html ('k') | pkg/analysis_server/test/protocol_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library protocol; 5 library protocol;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 part 'generated_protocol.dart'; 10 part 'generated_protocol.dart';
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 * The name of the JSON attribute containing the name of the request. 490 * The name of the JSON attribute containing the name of the request.
491 */ 491 */
492 static const String METHOD = 'method'; 492 static const String METHOD = 'method';
493 493
494 /** 494 /**
495 * The name of the JSON attribute containing the request parameters. 495 * The name of the JSON attribute containing the request parameters.
496 */ 496 */
497 static const String PARAMS = 'params'; 497 static const String PARAMS = 'params';
498 498
499 /** 499 /**
500 * The name of the optional JSON attribute indicating the time
501 * (milliseconds since epoch) at which the client made the request.
502 */
503 static const String CLIENT_REQUEST_TIME = 'clientRequestTime';
504
505 /**
500 * The unique identifier used to identify this request. 506 * The unique identifier used to identify this request.
501 */ 507 */
502 final String id; 508 final String id;
503 509
504 /** 510 /**
505 * The method being requested. 511 * The method being requested.
506 */ 512 */
507 final String method; 513 final String method;
508 514
509 /** 515 /**
510 * A table mapping the names of request parameters to their values. 516 * A table mapping the names of request parameters to their values.
511 */ 517 */
512 final Map<String, Object> _params; 518 final Map<String, Object> _params;
513 519
514 /** 520 /**
521 * The time (milliseconds since epoch) at which the client made the request
522 * or `null` if this information is not provided by the client.
523 */
524 final int clientRequestTime;
525
526 /**
515 * Initialize a newly created [Request] to have the given [id] and [method] 527 * Initialize a newly created [Request] to have the given [id] and [method]
516 * name. If [params] is supplied, it is used as the "params" map for the 528 * name. If [params] is supplied, it is used as the "params" map for the
517 * request. Otherwise an empty "params" map is allocated. 529 * request. Otherwise an empty "params" map is allocated.
518 */ 530 */
519 Request(this.id, this.method, [Map<String, Object> params]) 531 Request(this.id, this.method, [Map<String, Object> params,
532 this.clientRequestTime])
520 : _params = params != null ? params : new HashMap<String, Object>(); 533 : _params = params != null ? params : new HashMap<String, Object>();
521 534
522 /** 535 /**
523 * Return a request parsed from the given [data], or `null` if the [data] is 536 * Return a request parsed from the given [data], or `null` if the [data] is
524 * not a valid json representation of a request. The [data] is expected to 537 * not a valid json representation of a request. The [data] is expected to
525 * have the following format: 538 * have the following format:
526 * 539 *
527 * { 540 * {
528 * 'id': String, 541 * 'id': String,
529 * 'method': methodName, 542 * 'method': methodName,
530 * 'params': { 543 * 'params': {
531 * paramter_name: value 544 * paramter_name: value
532 * } 545 * }
546 * 'clientRequestTime': millisecondsSinceEpoch
533 * } 547 * }
534 * 548 *
535 * where the parameters are optional and can contain any number of name/value 549 * where both the parameters and clientRequestTime are optional.
536 * pairs. 550 * The parameters can contain any number of name/value pairs.
551 * The clientRequestTime must be an int representing the time at which
552 * the client issued the request (milliseconds since epoch).
537 */ 553 */
538 factory Request.fromString(String data) { 554 factory Request.fromString(String data) {
539 try { 555 try {
540 var result = JSON.decode(data); 556 var result = JSON.decode(data);
541 if (result is! Map) { 557 if (result is! Map) {
542 return null; 558 return null;
543 } 559 }
544 var id = result[Request.ID]; 560 var id = result[Request.ID];
545 var method = result[Request.METHOD]; 561 var method = result[Request.METHOD];
546 if (id is! String || method is! String) { 562 if (id is! String || method is! String) {
547 return null; 563 return null;
548 } 564 }
565 var time = result[Request.CLIENT_REQUEST_TIME];
566 if (time != null && time is! int) {
567 return null;
568 }
549 var params = result[Request.PARAMS]; 569 var params = result[Request.PARAMS];
550 if (params is Map || params == null) { 570 if (params is Map || params == null) {
551 return new Request(id, method, params); 571 return new Request(id, method, params, time);
552 } else { 572 } else {
553 return null; 573 return null;
554 } 574 }
555 } catch (exception) { 575 } catch (exception) {
556 return null; 576 return null;
557 } 577 }
558 } 578 }
559 579
560 /** 580 /**
561 * Return a table representing the structure of the Json object that will be 581 * Return a table representing the structure of the Json object that will be
562 * sent to the client to represent this response. 582 * sent to the client to represent this response.
563 */ 583 */
564 Map<String, Object> toJson() { 584 Map<String, Object> toJson() {
565 Map<String, Object> jsonObject = new HashMap<String, Object>(); 585 Map<String, Object> jsonObject = new HashMap<String, Object>();
566 jsonObject[ID] = id; 586 jsonObject[ID] = id;
567 jsonObject[METHOD] = method; 587 jsonObject[METHOD] = method;
568 if (_params.isNotEmpty) { 588 if (_params.isNotEmpty) {
569 jsonObject[PARAMS] = _params; 589 jsonObject[PARAMS] = _params;
570 } 590 }
591 if (clientRequestTime != null) {
592 jsonObject[CLIENT_REQUEST_TIME] = clientRequestTime;
593 }
571 return jsonObject; 594 return jsonObject;
572 } 595 }
573 } 596 }
574 597
575 598
576 /** 599 /**
577 * JsonDecoder for decoding requests. Errors are reporting by throwing a 600 * JsonDecoder for decoding requests. Errors are reporting by throwing a
578 * [RequestFailure]. 601 * [RequestFailure].
579 */ 602 */
580 class RequestDecoder extends JsonDecoder { 603 class RequestDecoder extends JsonDecoder {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 /** 707 /**
685 * Initialize a newly created instance to represent a response to a request 708 * Initialize a newly created instance to represent a response to a request
686 * with the given [id]. If [_result] is provided, it will be used as the 709 * with the given [id]. If [_result] is provided, it will be used as the
687 * result; otherwise an empty result will be used. If an [error] is provided 710 * result; otherwise an empty result will be used. If an [error] is provided
688 * then the response will represent an error condition. 711 * then the response will represent an error condition.
689 */ 712 */
690 Response(this.id, {Map<String, Object> result, this.error}) 713 Response(this.id, {Map<String, Object> result, this.error})
691 : _result = result; 714 : _result = result;
692 715
693 /** 716 /**
717 * Initialize a newly created instance to represent the
718 * FORMAT_INVALID_FILE error condition.
719 */
720 Response.formatInvalidFile(Request request)
721 : this(
722 request.id,
723 error: new RequestError(
724 RequestErrorCode.FORMAT_INVALID_FILE,
725 'Error during `edit.format`: invalid file.'));
726
727 /**
694 * Initialize a newly created instance based upon the given JSON data 728 * Initialize a newly created instance based upon the given JSON data
695 */ 729 */
696 factory Response.fromJson(Map<String, Object> json) { 730 factory Response.fromJson(Map<String, Object> json) {
697 try { 731 try {
698 Object id = json[Response.ID]; 732 Object id = json[Response.ID];
699 if (id is! String) { 733 if (id is! String) {
700 return null; 734 return null;
701 } 735 }
702 Object error = json[Response.ERROR]; 736 Object error = json[Response.ERROR];
703 RequestError decodedError; 737 RequestError decodedError;
704 if (error is Map) { 738 if (error is Map) {
705 decodedError = 739 decodedError =
706 new RequestError.fromJson(new ResponseDecoder(null), '.error', error ); 740 new RequestError.fromJson(new ResponseDecoder(null), '.error', error );
707 } 741 }
708 Object result = json[Response.RESULT]; 742 Object result = json[Response.RESULT];
709 Map<String, Object> decodedResult; 743 Map<String, Object> decodedResult;
710 if (result is Map) { 744 if (result is Map) {
711 decodedResult = result; 745 decodedResult = result;
712 } 746 }
713 return new Response(id, error: decodedError, result: decodedResult); 747 return new Response(id, error: decodedError, result: decodedResult);
714 } catch (exception) { 748 } catch (exception) {
715 return null; 749 return null;
716 } 750 }
717 } 751 }
718 752
719 /** 753 /**
720 * Initialize a newly created instance to represent the 754 * Initialize a newly created instance to represent the
721 * FORMAT_INVALID_FILE error condition.
722 */
723 Response.formatInvalidFile(Request request)
724 : this(
725 request.id,
726 error: new RequestError(
727 RequestErrorCode.FORMAT_INVALID_FILE,
728 'Error during `edit.format`: invalid file.'));
729
730 /**
731 * Initialize a newly created instance to represent the
732 * GET_ERRORS_INVALID_FILE error condition. 755 * GET_ERRORS_INVALID_FILE error condition.
733 */ 756 */
734 Response.getErrorsInvalidFile(Request request) 757 Response.getErrorsInvalidFile(Request request)
735 : this( 758 : this(
736 request.id, 759 request.id,
737 error: new RequestError( 760 error: new RequestError(
738 RequestErrorCode.GET_ERRORS_INVALID_FILE, 761 RequestErrorCode.GET_ERRORS_INVALID_FILE,
739 'Error during `analysis.getErrors`: invalid file.')); 762 'Error during `analysis.getErrors`: invalid file.'));
740 763
741 /** 764 /**
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); 899 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
877 hash = hash ^ (hash >> 11); 900 hash = hash ^ (hash >> 11);
878 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); 901 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
879 } 902 }
880 903
881 static int hash2(a, b) => finish(combine(combine(0, a), b)); 904 static int hash2(a, b) => finish(combine(combine(0, a), b));
882 905
883 static int hash4(a, b, c, d) => 906 static int hash4(a, b, c, d) =>
884 finish(combine(combine(combine(combine(0, a), b), c), d)); 907 finish(combine(combine(combine(combine(0, a), b), c), d));
885 } 908 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/doc/api.html ('k') | pkg/analysis_server/test/protocol_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698