Skip to content
This repository was archived by the owner on Mar 18, 2021. It is now read-only.

Commit 54e5a89

Browse files
committed
Merge pull request #16 from stablekernel/jc/cleanup
Cleaning up some stuff
2 parents 2914b14 + 9a3fbed commit 54e5a89

11 files changed

+187
-160
lines changed

lib/application.dart

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ part of monadart;
22

33
/// A set of values to configure an instance of a web server application.
44
class ApplicationInstanceConfiguration {
5-
65
/// The address to listen for HTTP requests on.
76
///
87
/// By default, this address will default to 'any' address. If [isIpv6Only] is true,
@@ -37,7 +36,6 @@ class ApplicationInstanceConfiguration {
3736
/// that are attached to this application.
3837
Map<dynamic, dynamic> pipelineOptions;
3938

40-
4139
/// Whether or not the server configuration defined by this instance can be shared across isolates.
4240
///
4341
/// Defaults to false. When false, only one isolate may listen for requests on the [address] and [port]
@@ -51,13 +49,13 @@ class ApplicationInstanceConfiguration {
5149
/// A copy constructor
5250
ApplicationInstanceConfiguration.fromConfiguration(
5351
ApplicationInstanceConfiguration config)
54-
: this.address = config.address,
55-
this.port = config.port,
56-
this.isIpv6Only = config.isIpv6Only,
57-
this.isUsingClientCertificate = config.isUsingClientCertificate,
58-
this.serverCertificateName = config.serverCertificateName,
59-
this.shared = config.shared,
60-
this.pipelineOptions = config.pipelineOptions;
52+
: this.address = config.address,
53+
this.port = config.port,
54+
this.isIpv6Only = config.isIpv6Only,
55+
this.isUsingClientCertificate = config.isUsingClientCertificate,
56+
this.serverCertificateName = config.serverCertificateName,
57+
this.shared = config.shared,
58+
this.pipelineOptions = config.pipelineOptions;
6159
}
6260

6361
/// A abstract class that concrete subclasses will implement to provide request handling behavior.
@@ -66,34 +64,31 @@ class ApplicationInstanceConfiguration {
6664
/// responds to requests is defined by its [ApplicationPipeline]. Instances of this class must implement the
6765
/// [handleRequest] method from [RequestHandler] - this is the entry point of all requests into this pipeline.
6866
abstract class ApplicationPipeline implements RequestHandler {
69-
7067
/// Passed in options for this pipeline from its owning [Application].
7168
///
7269
/// These values give an opportunity for a pipeline to have a customization point within attachTo., like running
7370
/// the owning [Application] in 'Development' or 'Production' mode. This property will always be set prior to invoking attachTo, but may be null
7471
/// if the user did not set any configuration values.
7572
Map<String, dynamic> options;
7673

77-
void onPipelineOpen();
74+
void pipelineWillOpen();
75+
void pipelineDidOpen();
7876
}
7977

80-
81-
8278
/// A container for web server applications.
8379
///
8480
/// Applications are responsible for managing starting and stopping of HTTP server instances across multiple isolates.
8581
/// Behavior specific to an application is implemented by setting the [Application]'s [configuration] and providing
8682
/// a [pipelineType] as a [ApplicationPipeline] subclass.
8783
class Application {
88-
8984
/// A list of items identifying the Isolates running a HTTP(s) listener and response handlers.
9085
List<_ServerRecord> servers = [];
9186

9287
/// The configuration for the HTTP(s) server this application is running.
9388
///
9489
/// This must be configured prior to [start]ing the [Application].
9590
ApplicationInstanceConfiguration configuration =
96-
new ApplicationInstanceConfiguration();
91+
new ApplicationInstanceConfiguration();
9792

9893
/// The type of [ApplicationPipeline] that configures how requests are handled.
9994
///
@@ -118,7 +113,7 @@ class Application {
118113

119114
for (int i = 0; i < numberOfInstances; i++) {
120115
var config =
121-
new ApplicationInstanceConfiguration.fromConfiguration(configuration);
116+
new ApplicationInstanceConfiguration.fromConfiguration(configuration);
122117

123118
var serverRecord = await _spawn(config, i + 1);
124119
servers.add(serverRecord);
@@ -129,17 +124,18 @@ class Application {
129124
});
130125
}
131126

132-
Future<_ServerRecord> _spawn(ApplicationInstanceConfiguration config, int identifier) async {
127+
Future<_ServerRecord> _spawn(
128+
ApplicationInstanceConfiguration config, int identifier) async {
133129
var receivePort = new ReceivePort();
134130

135131
var pipelineTypeMirror = reflectType(pipelineType);
136132
var pipelineLibraryURI = (pipelineTypeMirror.owner as LibraryMirror).uri;
137133
var pipelineTypeName = MirrorSystem.getName(pipelineTypeMirror.simpleName);
138134

139-
var initialMessage = new _InitialServerMessage(
140-
pipelineTypeName, pipelineLibraryURI, config, identifier, receivePort.sendPort);
135+
var initialMessage = new _InitialServerMessage(pipelineTypeName,
136+
pipelineLibraryURI, config, identifier, receivePort.sendPort);
141137
var isolate =
142-
await Isolate.spawn(_Server.entry, initialMessage, paused: true);
138+
await Isolate.spawn(_Server.entry, initialMessage, paused: true);
143139
isolate.addErrorListener(receivePort.sendPort);
144140

145141
return new _ServerRecord(isolate, receivePort, identifier);
@@ -153,52 +149,56 @@ class _Server {
153149
ApplicationPipeline pipeline;
154150
int identifier;
155151

156-
_Server(this.pipeline, this.configuration, this.identifier, this.parentMessagePort);
152+
_Server(this.pipeline, this.configuration, this.identifier,
153+
this.parentMessagePort);
157154

158155
Future start() async {
156+
pipeline.options = configuration.pipelineOptions;
157+
pipeline.pipelineWillOpen();
158+
159159
var onBind = (s) {
160160
server = s;
161161

162162
server.serverHeader = "monadart/${this.identifier}";
163163

164-
pipeline.options = configuration.pipelineOptions;
165-
server.map((httpReq) => new ResourceRequest(httpReq))
166-
.listen(pipeline.handleRequest);
164+
server
165+
.map((httpReq) => new ResourceRequest(httpReq))
166+
.listen(pipeline.handleRequest);
167167

168-
pipeline.onPipelineOpen();
168+
pipeline.pipelineDidOpen();
169169
};
170170

171171
if (configuration.serverCertificateName != null) {
172172
HttpServer
173-
.bindSecure(configuration.address, configuration.port,
174-
certificateName: configuration.serverCertificateName,
175-
v6Only: configuration.isIpv6Only,
176-
shared: configuration.shared)
177-
.then(onBind);
173+
.bindSecure(configuration.address, configuration.port,
174+
certificateName: configuration.serverCertificateName,
175+
v6Only: configuration.isIpv6Only,
176+
shared: configuration.shared)
177+
.then(onBind);
178178
} else if (configuration.isUsingClientCertificate) {
179179
HttpServer
180-
.bindSecure(configuration.address, configuration.port,
181-
requestClientCertificate: true,
182-
v6Only: configuration.isIpv6Only,
183-
shared: configuration.shared)
184-
.then(onBind);
180+
.bindSecure(configuration.address, configuration.port,
181+
requestClientCertificate: true,
182+
v6Only: configuration.isIpv6Only,
183+
shared: configuration.shared)
184+
.then(onBind);
185185
} else {
186186
HttpServer
187-
.bind(configuration.address, configuration.port,
188-
v6Only: configuration.isIpv6Only, shared: configuration.shared)
189-
.then(onBind);
187+
.bind(configuration.address, configuration.port,
188+
v6Only: configuration.isIpv6Only, shared: configuration.shared)
189+
.then(onBind);
190190
}
191191
}
192192

193193
static void entry(_InitialServerMessage params) {
194194
var pipelineSourceLibraryMirror =
195-
currentMirrorSystem().libraries[params.pipelineLibraryURI];
195+
currentMirrorSystem().libraries[params.pipelineLibraryURI];
196196
var pipelineTypeMirror = pipelineSourceLibraryMirror.declarations[
197-
new Symbol(params.pipelineTypeName)] as ClassMirror;
197+
new Symbol(params.pipelineTypeName)] as ClassMirror;
198198

199199
var app = pipelineTypeMirror.newInstance(new Symbol(""), []).reflectee;
200-
var server =
201-
new _Server(app, params.configuration, params.identifier, params.parentMessagePort);
200+
var server = new _Server(
201+
app, params.configuration, params.identifier, params.parentMessagePort);
202202

203203
server.start();
204204
}
@@ -224,5 +224,5 @@ class _InitialServerMessage {
224224
int identifier;
225225

226226
_InitialServerMessage(this.pipelineTypeName, this.pipelineLibraryURI,
227-
this.configuration, this.identifier, this.parentMessagePort);
228-
}
227+
this.configuration, this.identifier, this.parentMessagePort);
228+
}

lib/controller_routing.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
part of monadart;
22

3-
4-
53
/// A 'GET' HttpMethod annotation.
64
///
75
/// Handler methods on [HttpController]s that handle GET requests must be annotated with this.
@@ -42,8 +40,8 @@ class HttpMethod {
4240
const HttpMethod(this.method) : this._parameters = null;
4341

4442
HttpMethod._fromMethod(HttpMethod m, List<String> parameters)
45-
: this.method = m.method,
46-
this._parameters = parameters;
43+
: this.method = m.method,
44+
this._parameters = parameters;
4745

4846
/// Returns whether or not this [HttpMethod] matches a [ResourceRequest].
4947
bool matchesRequest(ResourceRequest req) {

lib/documentable.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
abstract class Documentable {
2-
3-
}
1+
abstract class Documentable {}

0 commit comments

Comments
 (0)