-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvironment.js
More file actions
56 lines (43 loc) · 1.25 KB
/
environment.js
File metadata and controls
56 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var Server = require("./configuration/server")
, Connection = require("./configuration/connection")
, initialize = require("./initializer")
, Socket = require("./socket")
;
function Environment(messaging, cache) {
if (!(this instanceof Environment)) return new Environment();
this.server = new Server();
this.db = new Connection();
this.messaging = messaging;
this.cache = cache;
}
Environment.prototype.init = function(callback) {
var that = this;
this.db.open(function(connection) {
connection.once("open", function() {
that.models = initialize("model", connection);
that.server.configure(that.models);
initialize("resource", that.server.app, that.models, that.messaging, that.cache);
callback();
});
});
}
Environment.prototype.start = function(callback) {
var that = this;
this.init(function() {
that.server.start(function() {
new Socket(that.server.io, that.messaging).broadcast();
if (callback) callback();
});
});
}
Environment.prototype.stop = function(callback) {
var that = this;
this.db.close(function() {
that.db = new Connection();
if (that.server.started)
that.server.stop(callback);
else
callback();
});
}
module.exports = Environment;