Comparing version 0.1.0 to 0.1.2
70
index.js
@@ -9,4 +9,4 @@ 'use strict'; | ||
var freeport = require('./lib/freeport'); | ||
// var inspect = require('./lib/inspect'); | ||
var async = require('async'); | ||
var inherits = require('util').inherits; | ||
@@ -18,2 +18,4 @@ | ||
var One = function (opt) { | ||
EventEmitter.call(this); | ||
opt = opt || {}; | ||
@@ -53,6 +55,6 @@ | ||
this._adInfo = null; | ||
this._emitter = new EventEmitter(); | ||
}; | ||
inherits(One, EventEmitter); | ||
// ----------------------------- PUBLIC METHODS -------------------------------- | ||
@@ -88,4 +90,2 @@ | ||
async.waterfall([ | ||
// find pub port, if none is defined | ||
@@ -131,3 +131,3 @@ function (next) { | ||
// callback + emit join | ||
this._emitter.emit('join', this._cluster); | ||
this.emit('join', this._cluster); | ||
callback && process.nextTick(callback.bind(null, null, this._cluster)); | ||
@@ -192,3 +192,3 @@ | ||
var banner = { | ||
id: this._id, | ||
name: this._id, | ||
txtRecord: { | ||
@@ -216,3 +216,3 @@ cluster: this._cluster | ||
}; | ||
this._emitter.emit('advertise_start', this._adInfo); | ||
this.emit('advertise_start', this._adInfo); | ||
callback && process.nextTick(callback.bind(null, null, this._adInfo)); | ||
@@ -233,3 +233,3 @@ | ||
this._emitter.emit('advertise_stop', this._adInfo); | ||
this.emit('advertise_stop', this._adInfo); | ||
callback && process.nextTick(callback.bind(null, null, this._adInfo)); | ||
@@ -249,3 +249,3 @@ | ||
this._emitter.emit('subscribe', channel); | ||
this.emit('subscribe', channel); | ||
callback && process.nextTick(callback.bind(null, null, channel)); | ||
@@ -263,3 +263,3 @@ | ||
this._emitter.emit('unsubscribe', channel); | ||
this.emit('unsubscribe', channel); | ||
callback && process.nextTick(callback.bind(null, null, channel)); | ||
@@ -277,3 +277,3 @@ | ||
this._emitter.emit('publish', channel, payload); | ||
this.emit('publish', channel, payload); | ||
@@ -285,34 +285,2 @@ this._pub.send(channel + ':' + payload); | ||
One.prototype.addListener = function () { | ||
return this._emitter.addListener.apply(this._emitter, arguments); | ||
}; | ||
One.prototype.on = function () { | ||
return this._emitter.on.apply(this._emitter, arguments); | ||
}; | ||
One.prototype.once = function () { | ||
return this._emitter.once.apply(this._emitter, arguments); | ||
}; | ||
One.prototype.removeListener = function () { | ||
return this._emitter.removeListener.apply(this._emitter, arguments); | ||
}; | ||
One.prototype.removeAllListeners = function () { | ||
return this._emitter.removeAllListeners.apply(this._emitter, arguments); | ||
}; | ||
One.prototype.setMaxListeners = function () { | ||
return this._emitter.setMaxListeners.apply(this._emitter, arguments); | ||
}; | ||
One.prototype.listeners = function () { | ||
return this._emitter.listeners.apply(this._emitter, arguments); | ||
}; | ||
One.prototype.emit = function () { | ||
return this._emitter.emit.apply(this._emitter, arguments); | ||
}; | ||
// ----------------------------- PROTECTED METHODS ----------------------------- | ||
@@ -356,3 +324,3 @@ | ||
// if node already in cluster or belongs to other cluster, ignore | ||
if (!mout.lang.isObject(this._clusterTopology[banner.id]) && | ||
if (!mout.lang.isObject(this._clusterTopology[banner.name]) && | ||
banner.txtRecord.cluster === this._cluster) { | ||
@@ -362,3 +330,3 @@ | ||
var info = { | ||
id: banner.id, | ||
id: banner.name, | ||
timestamp: (new Date()).toJSON(), | ||
@@ -377,3 +345,3 @@ address: banner.addresses[0], | ||
this._emitter.emit('node_up', info); | ||
this.emit('node_up', info); | ||
} | ||
@@ -388,3 +356,3 @@ }; | ||
this._emitter.emit('node_down', info); | ||
this.emit('node_down', info); | ||
} | ||
@@ -400,3 +368,3 @@ }; | ||
this._emitter.emit('message', chan, payload); | ||
this.emit('message', chan, payload); | ||
}; | ||
@@ -419,4 +387,4 @@ | ||
} | ||
this._emitter.emit('error', err); | ||
this.emit('error', err); | ||
}; | ||
@@ -423,0 +391,0 @@ |
{ | ||
"name": "1", | ||
"version": "0.1.0", | ||
"description": "Distributed pub/sub based on ØMQ", | ||
"version": "0.1.2", | ||
"description": "Distributed pub/sub based in ØMQ", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
# 1 ( *One* ) | ||
Clustering module based on [ØMQ](http://www.zeromq.org/). | ||
Distributed pub/sub based in [ØMQ](http://www.zeromq.org/). | ||
@@ -47,3 +47,3 @@ *1* (pronounced One) is a sort of magnet module, gluing together all the nodes that you launch in a network, and providing a simple pub/sub. It allows you to separate several services in the same network by means of | ||
``` | ||
```js | ||
var One = require('1'); | ||
@@ -83,3 +83,3 @@ | ||
``` | ||
```js | ||
// You can pass a few options when instantiating One. | ||
@@ -118,3 +118,3 @@ // Note that these are all optional, and you can instantiate without any option. | ||
``` | ||
```js | ||
var one = new One({ | ||
@@ -146,3 +146,3 @@ service: 'myStorageService' | ||
``` | ||
```js | ||
var one = new One({ | ||
@@ -170,3 +170,3 @@ service: 'myStorageService', | ||
``` | ||
```js | ||
one.on('join', function (cluster) { | ||
@@ -173,0 +173,0 @@ console.log('joined cluster:', cluster); |
21626
12
341