-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4557464
Showing
9 changed files
with
337 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Compiled source # | ||
################### | ||
*.com | ||
*.class | ||
*.dll | ||
*.exe | ||
*.o | ||
*.so | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store* | ||
ehthumbs.db | ||
Icon? | ||
Thumbs.db | ||
Desktop.ini | ||
.Spotlight-V100 | ||
.Trashes | ||
._* | ||
|
||
# NetBeans # | ||
############ | ||
nbsettings/ | ||
nbproject/ | ||
nbbuild/ | ||
nbdist/ | ||
nbactions.xml | ||
nb-configuration.xml | ||
|
||
# Textmate # | ||
############ | ||
*.tmproj | ||
*.tmproject | ||
tmtags | ||
|
||
# VIM # | ||
####### | ||
.*.sw[a-z] | ||
*.un~ | ||
Session.vim | ||
|
||
# Sublime TextEditor # | ||
###################### | ||
*.sublime-project | ||
|
||
# Eclipse # | ||
###################### | ||
/.project | ||
/.settings | ||
|
||
# Node # | ||
###################### | ||
node_modules | ||
npm-debug.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
predef: [ | ||
"console", | ||
"require", | ||
"define" | ||
], | ||
node: true, | ||
devel: true, | ||
bitwise: true, | ||
curly: true, | ||
eqeqeq: true, | ||
forin: false, | ||
immed: true, | ||
latedef: false, | ||
newcap: true, | ||
noarg: true, | ||
noempty: false, | ||
nonew: true, | ||
plusplus: false, | ||
regexp: true, | ||
undef: true, | ||
unused: true, | ||
quotmark: "single", | ||
strict: true, | ||
trailing: true, | ||
asi: false, | ||
boss: false, | ||
debug: false, | ||
eqnull: true, | ||
es5: false, | ||
esnext: false, | ||
evil: false, | ||
expr: false, | ||
funcscope: false, | ||
globalstrict: false, | ||
iterator: false, | ||
lastsemic: false, | ||
laxbreak: false, | ||
laxcomma: false, | ||
loopfunc: true, | ||
multistr: false, | ||
onecase: true, | ||
regexdash: false, | ||
scripturl: false, | ||
smarttabs: false, | ||
shadow: false, | ||
sub: false, | ||
supernew: false, | ||
validthis: false, | ||
nomen: false, | ||
onevar: false, | ||
white: true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Compiled source # | ||
################### | ||
*.com | ||
*.class | ||
*.dll | ||
*.exe | ||
*.o | ||
*.so | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store* | ||
ehthumbs.db | ||
Icon? | ||
Thumbs.db | ||
Desktop.ini | ||
.Spotlight-V100 | ||
.Trashes | ||
._* | ||
|
||
# NetBeans # | ||
############ | ||
nbsettings/ | ||
nbproject/ | ||
nbbuild/ | ||
nbdist/ | ||
nbactions.xml | ||
nb-configuration.xml | ||
|
||
# Textmate # | ||
############ | ||
*.tmproj | ||
*.tmproject | ||
tmtags | ||
|
||
# VIM # | ||
####### | ||
.*.sw[a-z] | ||
*.un~ | ||
Session.vim | ||
|
||
# Sublime TextEditor # | ||
###################### | ||
*.sublime-project | ||
|
||
# Eclipse # | ||
###################### | ||
/.project | ||
/.settings | ||
|
||
# Node # | ||
###################### | ||
node_modules | ||
npm-debug.* | ||
|
||
# Project specific # | ||
###################### | ||
/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- 0.9 | ||
- 0.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2012 Indigo United <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 1 | ||
|
||
Clustering module based on 0MQ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var One = require('../index.js'); | ||
|
||
var one = new One(); | ||
|
||
one.join('test'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
var EventEmitter = require('events').EventEmitter; | ||
var zmq = require('zmq'); | ||
var mdns = require('mdns'); | ||
var mout = require('mout'); | ||
//var uuid = require('uuid'); | ||
|
||
function freeport(cb) { | ||
cb(mout.random.randInt(1001, 10000)); | ||
} | ||
|
||
var Node = function(opt) { | ||
opt = opt || {}; | ||
|
||
// cluster which the node belongs to | ||
this._cluster = opt.cluster || 'default'; | ||
|
||
// id of the node | ||
// this._id = opt.id || uuid.v4(); | ||
|
||
// port in which the node will be publishing messages | ||
this._pubPort = opt.pubPort; // if port is not defined, a free one is used | ||
|
||
// interface in which the node will bind | ||
this._addr = opt.addr || '0.0.0.0'; | ||
|
||
// status flags | ||
this._inCluster = false; | ||
this._advertising = false; | ||
this._discovering = false; | ||
|
||
// used to store information about the other nodes in the cluster | ||
this._cluster = {}; | ||
|
||
// pub and sub sockets | ||
this._pub = null; | ||
this._sub = null; | ||
|
||
this._emitter = new EventEmitter(); | ||
}; | ||
|
||
// ----------------------------- PUBLIC METHODS -------------------------------- | ||
|
||
Node.prototype.join = function (callback) { | ||
this._pub = zmq.socket('pub'); | ||
this._sub = zmq.socket('sub'); | ||
|
||
var bindPub = function () { | ||
this._pub.bind(this._getBind(this._addr, this._pubPort), function (err) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
callback(); | ||
}) | ||
}.bind(this); | ||
|
||
if (this._pubPort) { | ||
bindPort(); | ||
} | ||
else { | ||
freeport(function (port) { | ||
this._pubPort = port; | ||
|
||
bindPort(); | ||
}.bind(this)); | ||
} | ||
}; | ||
|
||
Node.prototype.leave = function () { | ||
this._sub.close(); | ||
this._pub.close(); | ||
}; | ||
|
||
Node.prototype.startAdvertise = function (callback) { | ||
|
||
}; | ||
|
||
Node.prototype.stopAdvertise = function (callback) { | ||
|
||
}; | ||
|
||
Node.prototype.startDiscovery = function (callback) { | ||
|
||
}; | ||
|
||
Node.prototype.stopDiscovery = function (callback) { | ||
|
||
}; | ||
|
||
Node.prototype.subscribe = function (channel) { | ||
|
||
}; | ||
|
||
Node.prototype.unsubscribe = function (channel) { | ||
|
||
}; | ||
|
||
Node.prototype.publish = function (channel, payload) { | ||
|
||
}; | ||
|
||
Node.prototype.getCluster = function () { | ||
return this._cluster; | ||
}; | ||
|
||
// ----------------------------- PROTECTED METHODS ----------------------------- | ||
|
||
Node.prototype._handleNodeUp = function (service) { | ||
|
||
}; | ||
|
||
Node.prototype._handleNodeDown = function (service) { | ||
|
||
}; | ||
|
||
Node.prototype._handleMessage = function (data) { | ||
this._emitter.emit('message', data); | ||
}; | ||
|
||
Node.prototype._getBind = function (addr, port) { | ||
return 'tcp://' + addr + ':' + port; | ||
} | ||
|
||
|
||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
module.exports = Node; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "1", | ||
"version": "0.0.1", | ||
"description": "Clustering module based on 0MQ", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": "", | ||
"keywords": [ | ||
"0mq", | ||
"cluster", | ||
"mq", | ||
"queue", | ||
"nodes" | ||
], | ||
"author": "Marco Oliveira", | ||
"license": "MIT", | ||
"dependencies": { | ||
"mdns": "~1.1.0", | ||
"zmq": "~2.2.0", | ||
"mout": "~0.2.0", | ||
"uuid": "0.0.2" | ||
} | ||
} |