Permalink
Browse files

server: lazy-load memcache module

Don't require that the memcache module is installed if metrics_enabled=false.
  • Loading branch information...
1 parent 34d3c08 commit cfde236247eb07afa6a1ae4bf033932e2ff035ae @bnoordhuis bnoordhuis committed Mar 28, 2012
Showing with 6 additions and 8 deletions.
  1. +3 −4 server/js/main.js
  2. +3 −4 server/js/metrics.js
View
7 server/js/main.js
@@ -13,7 +13,7 @@ function main(config) {
worlds = [],
lastTotalPlayers = 0,
checkPopulationInterval = setInterval(function() {
- if(metrics.isReady) {
+ if(metrics && metrics.isReady) {
metrics.getTotalPlayers(function(totalPlayers) {
if(totalPlayers !== lastTotalPlayers) {
lastTotalPlayers = totalPlayers;
@@ -44,7 +44,7 @@ function main(config) {
}
};
- if(config.metrics_enabled) {
+ if(metrics) {
metrics.getOpenWorldCount(function(open_world_count) {
// choose the least populated world among open worlds
world = _.min(_.first(worlds, open_world_count), function(w) { return w.playerCount; });
@@ -78,8 +78,7 @@ function main(config) {
var world = new WorldServer('world'+ (i+1), config.nb_players_per_world, server);
world.run(config.map_filepath);
worlds.push(world);
-
- if(config.metrics_enabled) {
+ if(metrics) {
world.onPlayerAdded(onPopulationChange);
world.onPlayerRemoved(onPopulationChange);
}
View
7 server/js/metrics.js
@@ -1,14 +1,13 @@
var cls = require("./lib/class"),
- _ = require("underscore"),
- memcache = require("memcache");
+ _ = require("underscore");
module.exports = Metrics = Class.extend({
init: function(config) {
var self = this;
this.config = config;
- this.client = new memcache.Client(config.memcached_port, config.memcached_host),
+ this.client = new require("memcache").Client(config.memcached_port, config.memcached_host),
this.client.connect();
this.isReady = false;
@@ -73,4 +72,4 @@ module.exports = Metrics = Class.extend({
callback(result);
});
}
-});
+});

0 comments on commit cfde236

Please sign in to comment.