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

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

Issue 1900503002: More steps toward making server strong mode clean (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/search/element_references.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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; 9 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:analysis_server/src/channel/channel.dart'; 10 import 'package:analysis_server/src/channel/channel.dart';
(...skipping 18 matching lines...) Expand all
29 */ 29 */
30 ClientCommunicationChannel channel; 30 ClientCommunicationChannel channel;
31 31
32 /** 32 /**
33 * Stop the analysis server. 33 * Stop the analysis server.
34 * 34 *
35 * Returns `true` if the signal is successfully sent and process terminates. 35 * Returns `true` if the signal is successfully sent and process terminates.
36 * Otherwise there was no attached process or the signal could not be sent, 36 * Otherwise there was no attached process or the signal could not be sent,
37 * usually meaning that the process is already dead. 37 * usually meaning that the process is already dead.
38 */ 38 */
39 Future<bool> stop() { 39 Future<bool> stop() async {
40 if (process == null) { 40 if (process == null) {
41 return channel.close().then((_) => false); 41 await channel.close();
42 return false;
42 } 43 }
43 return channel 44 int result = await channel
44 .sendRequest(new ServerShutdownParams().toRequest('0')) 45 .sendRequest(new ServerShutdownParams().toRequest('0'))
45 .timeout(new Duration(seconds: 2), onTimeout: () { 46 .timeout(new Duration(seconds: 2), onTimeout: () {
46 print('Expected shutdown response'); 47 print('Expected shutdown response');
47 }).then((Response response) { 48 }).then((Response response) {
48 return channel.close().then((_) => process.exitCode); 49 return channel.close().then((_) => process.exitCode);
49 }).timeout(new Duration(seconds: 2), onTimeout: () { 50 }).timeout(new Duration(seconds: 2), onTimeout: () {
50 print('Expected server to shutdown'); 51 print('Expected server to shutdown');
51 process.kill(); 52 process.kill();
52 }).then((int result) {
53 if (result != null && result != 0) {
54 exitCode = result;
55 }
56 return true;
57 }); 53 });
54 if (result != null && result != 0) {
55 exitCode = result;
56 }
57 return true;
58 } 58 }
59 59
60 /** 60 /**
61 * Launch an analysis server and open a connection to that server. 61 * Launch an analysis server and open a connection to that server.
62 */ 62 */
63 Future<AnalysisManager> _launchServer(String pathToServer) async { 63 Future<AnalysisManager> _launchServer(String pathToServer) async {
64 try { 64 try {
65 // TODO dynamically allocate port and/or allow client to specify port 65 // TODO dynamically allocate port and/or allow client to specify port
66 List<String> serverArgs = [pathToServer, '--port', PORT.toString()]; 66 List<String> serverArgs = [pathToServer, '--port', PORT.toString()];
67 Process process = await Process.start(Platform.executable, serverArgs); 67 Process process = await Process.start(Platform.executable, serverArgs);
(...skipping 27 matching lines...) Expand all
95 } catch (error) { 95 } catch (error) {
96 exitCode = 1; 96 exitCode = 1;
97 process.kill(); 97 process.kill();
98 throw 'Expected port from analysis server'; 98 throw 'Expected port from analysis server';
99 } 99 }
100 } 100 }
101 101
102 /** 102 /**
103 * Open a connection to the analysis server using the given URL. 103 * Open a connection to the analysis server using the given URL.
104 */ 104 */
105 Future<AnalysisManager> _openConnection(String serverUrl) { 105 Future<AnalysisManager> _openConnection(String serverUrl) async {
106 Function onError = (error) { 106 Function onError = (error) {
107 exitCode = 1; 107 exitCode = 1;
108 if (process != null) { 108 if (process != null) {
109 process.kill(); 109 process.kill();
110 } 110 }
111 throw 'Failed to connect to analysis server at $serverUrl\n $error'; 111 throw 'Failed to connect to analysis server at $serverUrl\n $error';
112 }; 112 };
113 try { 113 try {
114 return WebSocket 114 WebSocket socket = await WebSocket.connect(serverUrl).catchError(onError);
115 .connect(serverUrl) 115 this.channel = new WebSocketClientChannel(socket);
116 .catchError(onError) 116 return this;
117 .then((WebSocket socket) {
118 this.channel = new WebSocketClientChannel(socket);
119 return this;
120 });
121 } catch (error) { 117 } catch (error) {
122 onError(error); 118 onError(error);
123 } 119 }
124 } 120 }
125 121
126 /** 122 /**
127 * Open a connection to a running analysis server 123 * Open a connection to a running analysis server
128 * and return a future with a manager for that analysis server. 124 * and return a future with a manager for that analysis server.
129 */ 125 */
130 static Future<AnalysisManager> connect(String serverUrl) { 126 static Future<AnalysisManager> connect(String serverUrl) {
131 return new AnalysisManager()._openConnection(serverUrl); 127 return new AnalysisManager()._openConnection(serverUrl);
132 } 128 }
133 129
134 /** 130 /**
135 * Launch analysis server in a separate process 131 * Launch analysis server in a separate process
136 * and return a future with a manager for that analysis server. 132 * and return a future with a manager for that analysis server.
137 */ 133 */
138 static Future<AnalysisManager> start(String serverPath) { 134 static Future<AnalysisManager> start(String serverPath) {
139 return new AnalysisManager()._launchServer(serverPath); 135 return new AnalysisManager()._launchServer(serverPath);
140 } 136 }
141 } 137 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/search/element_references.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698