Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/qiankanglai/pomelo
Browse files Browse the repository at this point in the history
  • Loading branch information
qiankanglai committed Jun 21, 2014
2 parents c5d353f + 7578eba commit 6e3e316
Show file tree
Hide file tree
Showing 30 changed files with 183 additions and 78 deletions.
6 changes: 6 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.0.0 / 2014-06-19
=================
* mqtt connector
* support ie6,7,8 with sioconnector
* support hot update partially

1.0.0-pre / 2014-05-16
=================
* add udpconnector
Expand Down
3 changes: 2 additions & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');

var src = ['test/manager/taskManager.js', 'test/filters/*.js',
'test/remote/*.js', 'test/service/*.js', 'test/util/*.js', 'test/*.js'];
'test/remote/*.js', 'test/service/*.js', 'test/modules/*.js', 'test/util/*.js', 'test/*.js'];

// Project configuration.
grunt.initConfig({
mochaTest: {
test: {
options: {
reporter: 'spec',
timeout: 5000,
require: 'coverage/blanket'
},
src: src
Expand Down
6 changes: 3 additions & 3 deletions lib/common/service/channelService.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ var sendMessageByGroup = function(channelService, route, msg, groups, opts, cb)
var sendMessage = function(sid) {
return (function() {
if(sid === app.serverId) {
channelService.channelRemote[method](route, msg, groups[sid], opts, rpcCB);
channelService.channelRemote[method](route, msg, groups[sid], opts, rpcCB(sid));
} else {
app.rpcInvoke(sid, {namespace: namespace, service: service,
method: method, args: [route, msg, groups[sid], opts]}, rpcCB(sid));
Expand All @@ -441,7 +441,7 @@ var sendMessageByGroup = function(channelService, route, msg, groups, opts, cb)
sendMessage(sid);
} else {
// empty group
process.nextTick(rpcCB);
process.nextTick(rpcCB(sid));
}
}
};
Expand Down Expand Up @@ -541,4 +541,4 @@ var genKey = function(self, name) {

var genValue = function(sid, uid) {
return sid + ':' + uid;
};
};
20 changes: 16 additions & 4 deletions lib/common/service/handlerService.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
var logger = require('pomelo-logger').getLogger('pomelo', __filename);
var forwardLogger = require('pomelo-logger').getLogger('forward-log', __filename);
var fs = require('fs');
var utils = require('../../util/utils');
var Loader = require('pomelo-loader');
var pathUtil = require('../../util/pathUtil');

var logger = require('pomelo-logger').getLogger('pomelo', __filename);
var forwardLogger = require('pomelo-logger').getLogger('forward-log', __filename);
/**
* Handler service.
* Dispatch request to the relactive handler.
*
* @param {Object} app current application context
*/
var Service = function(app) {
var Service = function(app, opts) {
this.app = app;
this.handlerMap = {};
if(!!opts.reloadHandlers) {
watchHandlers(app, this.handlerMap);
}
};

module.exports = Service;
Expand Down Expand Up @@ -78,4 +81,13 @@ var loadHandlers = function(app, serverType, handlerMap) {
if(p) {
handlerMap[serverType] = Loader.load(p, app);
}
};

var watchHandlers = function(app, handlerMap) {
var p = pathUtil.getHandlerPath(app.getBase(), app.serverType);
fs.watch(p, function(event, name) {
if(event === 'change') {
handlerMap[app.serverType] = Loader.load(p, app);
}
});
};
8 changes: 4 additions & 4 deletions lib/components/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ var Server = require('../server/server');
* @param {Object} app current application context
* @return {Object} component instance
*/
module.exports = function(app) {
return new Component(app);
module.exports = function(app, opts) {
return new Component(app, opts);
};

/**
* Server component class
*
* @param {Object} app current application context
*/
var Component = function(app) {
this.server = Server.create(app);
var Component = function(app, opts) {
this.server = Server.create(app, opts);
};

var pro = Component.prototype;
Expand Down
2 changes: 1 addition & 1 deletion lib/connectors/hybridsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Socket.prototype.sendRaw = function(msg) {

this.socket.send(msg, {binary: true}, function(err) {
if(!!err) {
logger.error('websocket([%s]:[%s]) send binary data failed: %j', self.socket._socket.remoteAddress, self.socket._socket.remotePort, err);
logger.error('websocket send binary data failed: %j', err.stack);
return;
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/pomelo.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var Pomelo = module.exports = {};
* Framework version.
*/

Pomelo.version = '1.0.0-pre';
Pomelo.version = '1.0.0';

/**
* Event definitions that would be emitted by app.event
Expand Down
13 changes: 7 additions & 6 deletions lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ var ST_STOPED = 2; // server stoped
* @param {Object} app current application context
* @return {Object} erver instance
*/
module.exports.create = function(app) {
return new Server(app);
module.exports.create = function(app, opts) {
return new Server(app, opts);
};

var Server = function (app) {
var Server = function (app, opts) {
this.opts = opts || {};
this.app = app;
this.globalFilterService = null;
this.filterService = null;
Expand All @@ -53,7 +54,7 @@ pro.start = function() {

this.globalFilterService = initFilter(true, this.app);
this.filterService = initFilter(false, this.app);
this.handlerService = initHandler(this.app);
this.handlerService = initHandler(this.app, this.opts);
this.cronHandlers = loadCronHandlers(this.app);
loadCrons(this, this.app);
this.state = ST_STARTED;
Expand Down Expand Up @@ -183,8 +184,8 @@ var initFilter = function(isGlobal, app) {
return service;
};

var initHandler = function(app) {
return new HandlerService(app);
var initHandler = function(app, opts) {
return new HandlerService(app, opts);
};

/**
Expand Down
17 changes: 15 additions & 2 deletions lib/util/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var os = require('os');
var util = require('util');
var exec = require('child_process').exec;
var logger = require('pomelo-logger').getLogger('pomelo', __filename);
var Constants = require('./constants');
var pomelo = require('../pomelo');

var utils = module.exports;

Expand Down Expand Up @@ -189,8 +191,15 @@ utils.checkPort = function(server, cb) {
var host = server.host;
var generateCommand = function(self, host, port) {
var cmd;
var ssh_params = pomelo.app.get(Constants.RESERVED.SSH_CONFIG_PARAMS);
if(!!ssh_params && Array.isArray(ssh_params)) {
ssh_params = ssh_params.join(' ');
}
else{
ssh_params = "";
}
if (!self.isLocal(host)) {
cmd = util.format('ssh %s "netstat -an|awk \'{print $4}\'|grep %s|wc -l"', host, port);
cmd = util.format('ssh %s %s "netstat -an|awk \'{print $4}\'|grep %s|wc -l"', host, ssh_params, port);
} else {
cmd = util.format('netstat -an|awk \'{print $4}\'|grep %s|wc -l', port);
}
Expand Down Expand Up @@ -222,7 +231,11 @@ utils.checkPort = function(server, cb) {

utils.isLocal = function(host) {
var app = require('../pomelo').app;
return host === '127.0.0.1' || host === 'localhost' || inLocal(host) || host === app.master.host;
if(!app) {
return host === '127.0.0.1' || host === 'localhost' || inLocal(host);
} else {
return host === '127.0.0.1' || host === 'localhost' || inLocal(host) || host === app.master.host;
}
};

/**
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pomelo",
"version": "1.0.0-pre",
"version": "1.0.0",
"private": false,
"homepage": "https://github.com/NetEase/pomelo",
"repository": {
Expand Down Expand Up @@ -35,10 +35,10 @@
"cliff": "0.1.8",
"mkdirp": "0.3.3",
"pomelo-loader": "0.0.6",
"pomelo-rpc": "0.4.0",
"pomelo-rpc": "0.4.1",
"pomelo-protocol": "0.1.3",
"pomelo-admin": "0.4.0",
"pomelo-logger": "0.1.2",
"pomelo-admin": "0.4.1",
"pomelo-logger": "0.1.5",
"pomelo-scheduler": "0.3.8",
"ws": "0.4.25",
"pomelo-protobuf": "0.4.0",
Expand Down
3 changes: 1 addition & 2 deletions test/application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var lib = process.env.POMELO_COV ? 'lib-cov' : 'lib';
var app = require('../' + lib + '/application');
var app = require('../lib/application');
var pomelo = require('../');
var should = require('should');

Expand Down
5 changes: 2 additions & 3 deletions test/filters/handler/serial.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var lib = process.env.POMELO_COV ? 'lib-cov' : 'lib';
var should = require('should');
var serialFilter = require('../../../' + lib + '/filters/handler/serial');
var FilterService = require('../../../' + lib + '/common/service/filterService');
var serialFilter = require('../../../lib/filters/handler/serial');
var FilterService = require('../../../lib/common/service/filterService');
var util = require('util');

var mockSession = {
Expand Down
5 changes: 2 additions & 3 deletions test/filters/handler/time.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var lib = process.env.POMELO_COV ? 'lib-cov' : 'lib';
var should = require('should');
var serialFilter = require('../../../' + lib + '/filters/handler/time');
var FilterService = require('../../../' + lib + '/common/service/filterService');
var serialFilter = require('../../../lib/filters/handler/time');
var FilterService = require('../../../lib/common/service/filterService');
var util = require('util');
var mockSession = {
key : "123"
Expand Down
5 changes: 2 additions & 3 deletions test/filters/handler/timeout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var lib = process.env.POMELO_COV ? 'lib-cov' : 'lib';
var should = require('should');
var timeoutFilter = require('../../../' + lib + '/filters/handler/timeout');
var FilterService = require('../../../' + lib + '/common/service/filterService');
var timeoutFilter = require('../../../lib/filters/handler/timeout');
var FilterService = require('../../../lib/common/service/filterService');
var util = require('util');
var mockSession = {
key : "123"
Expand Down
5 changes: 2 additions & 3 deletions test/filters/handler/toobusy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var lib = process.env.POMELO_COV ? 'lib-cov' : 'lib';
var should = require('should');
var toobusyFilter = require('../../../' + lib + '/filters/handler/toobusy');
var FilterService = require('../../../' + lib + '/common/service/filterService');
var toobusyFilter = require('../../../lib/filters/handler/toobusy');
var FilterService = require('../../../lib/common/service/filterService');
var util = require('util');
var mockSession = {
key : "123"
Expand Down
3 changes: 1 addition & 2 deletions test/filters/rpc/rpcLog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var lib = process.env.POMELO_COV ? 'lib-cov' : 'lib';
var should = require('should');
var rpcLogFilter = require('../../../' + lib + '/filters/rpc/rpcLog');
var rpcLogFilter = require('../../../lib/filters/rpc/rpcLog');

var mockData = {
serverId : "connector-server-1",
Expand Down
3 changes: 1 addition & 2 deletions test/filters/rpc/toobusy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var lib = process.env.POMELO_COV ? 'lib-cov' : 'lib';
var should = require('should');
var toobusyFilter = require('../../../' + lib + '/filters/rpc/toobusy');
var toobusyFilter = require('../../../lib/filters/rpc/toobusy');

var mockData = {
serverId : "connector-server-1",
Expand Down
4 changes: 1 addition & 3 deletions test/manager/mockChannelManager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
var lib = process.env.POMELO_COV ? 'lib-cov' : 'lib';

var DEFAULT_PREFIX = 'POMELO:CHANNEL';
var utils = require('../../' + lib + '/util/utils');
var utils = require('../../lib/util/utils');

var MockManager = function(app, opts) {
this.app = app;
Expand Down
3 changes: 1 addition & 2 deletions test/manager/taskManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var lib = process.env.POMELO_COV ? 'lib-cov' : 'lib';
var should = require('should');
var taskManager = require('../../' + lib + '/common/manager/taskManager');
var taskManager = require('../../lib/common/manager/taskManager');

// set timeout for test
taskManager.timeout = 100;
Expand Down
Loading

0 comments on commit 6e3e316

Please sign in to comment.