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

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

Issue 138163006: Add top-level server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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
OLDNEW
(Empty)
1 library get.handler;
2
3 import 'dart:io';
4
5 import 'package:analyzer/src/generated/engine.dart';
6
7 import 'analysis_server.dart';
8
9 /**
10 * Instances of the class [GetHandler] handle GET requests
11 */
12 class GetHandler {
13 /**
14 * The path used to request the status of the analysis server as a whole.
15 */
16 static const String STATUS_PATH = '/status';
devoncarew 2014/01/21 20:59:27 awesome!
17
18 /**
19 * The analysis server whose status is to be reported on, or `null` if the
20 * server has not yet been created.
21 */
22 AnalysisServer server;
23
24 /**
25 * Initialize a newly created handler for GET requests.
26 */
27 GetHandler();
28
29 /**
30 * Handle a GET request received by the HTTP server.
31 */
32 void handleGetRequest(HttpRequest request) {
33 String path = request.uri.path;
34 if (path == STATUS_PATH) {
35 _returnServerStatus(request);
36 } else {
37 _returnUnknownRequest(request);
38 }
39 }
40
41 /**
42 * Return a response indicating the status of the analysis server.
43 */
44 void _returnServerStatus(HttpRequest request) {
45 HttpResponse response = request.response;
46 response.statusCode = HttpStatus.OK;
47 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/html");
48 response.write('<html>');
49 response.write('<head>');
50 response.write('<title>Dart Analysis Server - Status</title>');
51 response.write('</head>');
52 response.write('<body>');
53 response.write('<h1>Analysis Server</h1>');
54 if (server == null) {
55 response.write('<p>Not running</p>');
56 } else {
57 response.write('<p>Running</p>');
58 response.write('<h1>Analysis Contexts</h1>');
59 response.write('<h2>Summary</h2>');
60 response.write('<table>');
61 _writeRow(
62 response,
63 ['Context', 'ERROR', 'FLUSHED', 'IN_PROCESS', 'INVALID', 'VALID'],
64 true);
65 server.contextMap.forEach((String key, AnalysisContext context) {
66 AnalysisContentStatistics statistics =
67 (context as AnalysisContextImpl).statistics;
68 int errorCount = 0;
69 int flushedCount = 0;
70 int inProcessCount = 0;
71 int invalidCount = 0;
72 int validCount = 0;
73 statistics.cacheRows.forEach((AnalysisContentStatistics_CacheRow row) {
74 errorCount += row.errorCount;
75 flushedCount += row.flushedCount;
76 inProcessCount += row.inProcessCount;
77 invalidCount += row.invalidCount;
78 validCount += row.validCount;
79 });
80 _writeRow(response, [
81 '<a href="#context_$key">$key</a>',
82 errorCount,
83 flushedCount,
84 inProcessCount,
85 invalidCount,
86 validCount]);
87 });
88 response.write('</table>');
89 server.contextMap.forEach((String key, AnalysisContext context) {
90 response.write('<h2><a name="context_$key">Analysis Context: $key}</a></ h2>');
91 AnalysisContentStatistics statistics = (context as AnalysisContextImpl). statistics;
92 response.write('<table>');
93 _writeRow(
94 response,
95 ['Item', 'ERROR', 'FLUSHED', 'IN_PROCESS', 'INVALID', 'VALID'],
96 true);
97 statistics.cacheRows.forEach((AnalysisContentStatistics_CacheRow row) {
98 _writeRow(
99 response,
100 [row.name,
101 row.errorCount,
102 row.flushedCount,
103 row.inProcessCount,
104 row.invalidCount,
105 row.validCount]);
106 });
107 response.write('</table>');
108 List<AnalysisException> exceptions = statistics.exceptions;
109 if (!exceptions.isEmpty) {
110 response.write('<h2>Exceptions</h2>');
111 exceptions.forEach((AnalysisException exception) {
112 response.write('<p>${exception.message}</p>');
113 });
114 }
115 });
116 }
117 response.write('</body>');
118 response.write('</html>');
119 response.close();
120 }
121
122 /**
123 * Return an error in response to an unrecognized request received by the HTTP
124 * server.
125 */
126 void _returnUnknownRequest(HttpRequest request) {
127 HttpResponse response = request.response;
128 response.statusCode = HttpStatus.NOT_FOUND;
129 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain");
130 response.write('Not found');
131 response.close();
132 }
133
134 /**
135 * Write a single row within a table to the given [response] object. The row
136 * will have one cell for each of the [columns], and will be a header row if
137 * [header] is `true`.
138 */
139 void _writeRow(HttpResponse response, List<Object> columns, [bool header = fal se]) {
140 if (header) {
141 response.write('<th>');
142 } else {
143 response.write('<tr>');
144 }
145 columns.forEach((Object value) {
146 response.write('<td>');
147 response.write(value);
148 response.write('</td>');
149 });
150 if (header) {
151 response.write('</th>');
152 } else {
153 response.write('</tr>');
154 }
155 }
156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698