| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library socket.server; |
| 6 |
| 7 import 'package:analysis_server/src/analysis_server.dart'; |
| 8 import 'package:analysis_server/src/channel.dart'; |
| 9 import 'package:analysis_server/src/domain_context.dart'; |
| 10 import 'package:analysis_server/src/domain_server.dart'; |
| 11 import 'package:analysis_server/src/protocol.dart'; |
| 12 |
| 13 /** |
| 14 * Instances of the class [SocketServer] implement the common parts of |
| 15 * http-based and stdio-based analysis servers. The primary responsibility of |
| 16 * the SocketServer is to manage the lifetime of the AnalysisServer and to |
| 17 * encode and decode the JSON messages exchanged with the client. |
| 18 */ |
| 19 class SocketServer { |
| 20 /** |
| 21 * The analysis server that was created when a client established a |
| 22 * connection, or `null` if no such connection has yet been established. |
| 23 */ |
| 24 AnalysisServer analysisServer; |
| 25 |
| 26 /** |
| 27 * Create an analysis server which will communicate with the client using the |
| 28 * given serverChannel. |
| 29 */ |
| 30 void createAnalysisServer(ServerCommunicationChannel serverChannel) { |
| 31 if (analysisServer != null) { |
| 32 // TODO(paulberry): add a message to the protocol so that the server can |
| 33 // inform the client of a successful connection. |
| 34 var error = new RequestError.serverAlreadyStarted(); |
| 35 serverChannel.sendResponse(new Response('', error)); |
| 36 serverChannel.listen((Request request) { |
| 37 serverChannel.sendResponse(new Response(request.id, error)); |
| 38 }); |
| 39 return; |
| 40 } |
| 41 analysisServer = new AnalysisServer(serverChannel); |
| 42 _initializeHandlers(analysisServer); |
| 43 analysisServer.run(); |
| 44 } |
| 45 |
| 46 /** |
| 47 * Initialize the handlers to be used by the given [server]. |
| 48 */ |
| 49 void _initializeHandlers(AnalysisServer server) { |
| 50 server.handlers = [ |
| 51 new ServerDomainHandler(server), |
| 52 new ContextDomainHandler(server), |
| 53 ]; |
| 54 } |
| 55 |
| 56 } |
| OLD | NEW |