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

Side by Side Diff: pkg/analysis_server/lib/http_server.dart

Issue 237643003: Split analysis server's HttpAnalysisServer into two classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing initialization of socketServer. Created 6 years, 8 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 | « no previous file | pkg/analysis_server/lib/src/get_handler.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 http.server; 5 library http.server;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/channel.dart'; 9 import 'package:analysis_server/src/channel.dart';
11 import 'package:analysis_server/src/domain_context.dart';
12 import 'package:analysis_server/src/domain_server.dart';
13 import 'package:analysis_server/src/get_handler.dart'; 10 import 'package:analysis_server/src/get_handler.dart';
14 import 'package:analysis_server/src/protocol.dart'; 11 import 'package:analysis_server/src/socket_server.dart';
15 import 'package:args/args.dart'; 12 import 'package:args/args.dart';
16 13
17 /** 14 /**
18 * Instances of the class [HttpServer] implement a simple HTTP server. The 15 * Instances of the class [HttpServer] implement a simple HTTP server. The
19 * primary responsibility of this server is to listen for an UPGRADE request and 16 * primary responsibility of this server is to listen for an UPGRADE request and
20 * to start an analysis server. 17 * to start an analysis server.
21 */ 18 */
22 class HttpAnalysisServer { 19 class HttpAnalysisServer {
23 /** 20 /**
24 * The name of the application that is used to start a server. 21 * The name of the application that is used to start a server.
25 */ 22 */
26 static const BINARY_NAME = 'server'; 23 static const BINARY_NAME = 'server';
27 24
28 /** 25 /**
29 * The name of the option used to print usage information. 26 * The name of the option used to print usage information.
30 */ 27 */
31 static const String HELP_OPTION = "help"; 28 static const String HELP_OPTION = "help";
32 29
33 /** 30 /**
34 * The name of the option used to specify the port to which the server will 31 * The name of the option used to specify the port to which the server will
35 * connect. 32 * connect.
36 */ 33 */
37 static const String PORT_OPTION = "port"; 34 static const String PORT_OPTION = "port";
38 35
39 /** 36 /**
40 * The analysis server that was created when an UPGRADE request was received, 37 * An object that can handle either a WebSocket connection or a connection
41 * or `null` if no such request has yet been received. 38 * to the client over stdio.
42 */ 39 */
43 AnalysisServer analysisServer; 40 SocketServer socketServer = new SocketServer();
44 41
45 /** 42 /**
46 * An object that can handle GET requests. 43 * An object that can handle GET requests.
47 */ 44 */
48 GetHandler getHandler; 45 GetHandler getHandler;
49 46
50 /** 47 /**
51 * Initialize a newly created HTTP server. 48 * Initialize a newly created HTTP server.
52 */ 49 */
53 HttpAnalysisServer(); 50 HttpAnalysisServer();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 _returnUnknownRequest(request); 105 _returnUnknownRequest(request);
109 } 106 }
110 }); 107 });
111 } 108 }
112 109
113 /** 110 /**
114 * Handle a GET request received by the HTTP server. 111 * Handle a GET request received by the HTTP server.
115 */ 112 */
116 void _handleGetRequest(HttpRequest request) { 113 void _handleGetRequest(HttpRequest request) {
117 if (getHandler == null) { 114 if (getHandler == null) {
118 getHandler = new GetHandler(); 115 getHandler = new GetHandler(socketServer);
119 getHandler.server = analysisServer;
120 } 116 }
121 getHandler.handleGetRequest(request); 117 getHandler.handleGetRequest(request);
122 } 118 }
123 119
124 /** 120 /**
125 * Handle an UPGRADE request received by the HTTP server by creating and 121 * Handle an UPGRADE request received by the HTTP server by creating and
126 * running an analysis server on a [WebSocket]-based communication channel. 122 * running an analysis server on a [WebSocket]-based communication channel.
127 */ 123 */
128 void _handleWebSocket(WebSocket socket) { 124 void _handleWebSocket(WebSocket socket) {
129 ServerCommunicationChannel serverChannel = new WebSocketServerChannel(socket ); 125 socketServer.createAnalysisServer(new WebSocketServerChannel(socket));
130 if (analysisServer != null) {
131 // TODO(paulberry): add a message to the protocol so that the server can
132 // inform the client of a successful connection.
133 var error = new RequestError.serverAlreadyStarted();
134 serverChannel.sendResponse(new Response('', error));
135 serverChannel.listen((Request request) {
136 serverChannel.sendResponse(new Response(request.id, error));
137 });
138 return;
139 }
140 analysisServer = new AnalysisServer(new WebSocketServerChannel(socket));
141 _initializeHandlers(analysisServer);
142 if (getHandler != null) {
143 getHandler.server = analysisServer;
144 }
145 analysisServer.run();
146 } 126 }
147 127
148 /** 128 /**
149 * Initialize the handlers to be used by the given [server].
150 */
151 void _initializeHandlers(AnalysisServer server) {
152 server.handlers = [
153 new ServerDomainHandler(server),
154 new ContextDomainHandler(server),
155 ];
156 }
157
158 /**
159 * Print information about how to use the server. 129 * Print information about how to use the server.
160 */ 130 */
161 void _printUsage(ArgParser parser) { 131 void _printUsage(ArgParser parser) {
162 print('Usage: $BINARY_NAME [flags]'); 132 print('Usage: $BINARY_NAME [flags]');
163 print(''); 133 print('');
164 print('Supported flags are:'); 134 print('Supported flags are:');
165 print(parser.getUsage()); 135 print(parser.getUsage());
166 } 136 }
167 137
168 /** 138 /**
169 * Return an error in response to an unrecognized request received by the HTTP 139 * Return an error in response to an unrecognized request received by the HTTP
170 * server. 140 * server.
171 */ 141 */
172 void _returnUnknownRequest(HttpRequest request) { 142 void _returnUnknownRequest(HttpRequest request) {
173 HttpResponse response = request.response; 143 HttpResponse response = request.response;
174 response.statusCode = HttpStatus.NOT_FOUND; 144 response.statusCode = HttpStatus.NOT_FOUND;
175 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain"); 145 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain");
176 response.write('Not found'); 146 response.write('Not found');
177 response.close(); 147 response.close();
178 } 148 }
179 } 149 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/get_handler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698