Skip to content

Commit

Permalink
make One a proper emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
marcooliveira committed Mar 4, 2014
1 parent cbc47a6 commit 9bdd2d7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 1 ( *One* )

Clustering module based on [ØMQ](http://www.zeromq.org/).
Distributed pub/sub based in [ØMQ](http://www.zeromq.org/).

*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

Expand Down
50 changes: 9 additions & 41 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ var mdns = require('mdns2');
var mout = require('mout');
var uuid = require('node-uuid');
var freeport = require('./lib/freeport');
// var inspect = require('./lib/inspect');
var async = require('async');
var inherits = require('util').inherit;



// ------------------------------ CONSTRUCTOR ----------------------------------

var One = function (opt) {
EventEmitter.call(this);

opt = opt || {};

// the id of the service that the node will provide
Expand Down Expand Up @@ -48,10 +50,10 @@ var One = function (opt) {

// information that is used to advertise the service
this._adInfo = null;

this._emitter = new EventEmitter();
};

inherits(One, EventEmitter);

// ----------------------------- PUBLIC METHODS --------------------------------

One.prototype.getId = function () {
Expand Down Expand Up @@ -82,8 +84,6 @@ One.prototype.join = function (callback) {
this._sub.on('message', this._handleMessage.bind(this));

async.waterfall([


// find pub port, if none is defined
function (next) {
// if port is not defined, find one
Expand Down Expand Up @@ -184,7 +184,7 @@ One.prototype.advertise = function (details, callback) {

// banner will be used to announce the service
var banner = {
id: this._id,
name: this._id,
txtRecord: {
cluster: this._cluster
}
Expand Down Expand Up @@ -271,38 +271,6 @@ One.prototype.publish = function (channel, payload) {
return this;
};

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 -----------------------------

One.prototype._startDiscovery = function (callback) {
Expand Down Expand Up @@ -341,12 +309,12 @@ One.prototype._stopDiscovery = function (callback) {

One.prototype._handleNodeUp = function (banner) {
// 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) {

// add node to this node's perception of the cluster
var info = {
id: banner.id,
id: banner.name,
timestamp: (new Date()).toJSON(),
address: banner.addresses[0],
port: banner.port
Expand Down Expand Up @@ -399,7 +367,7 @@ One.prototype._error = function (err, callback) {
if (typeof(callback) === 'function') {
return callback(err);
}

this._emitter.emit('error', err);
};

Expand Down
13 changes: 0 additions & 13 deletions lib/inspect.js

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "1",
"version": "0.1.0",
"description": "Distributed pub/sub based on ØMQ",
"version": "0.1.1",
"description": "Distributed pub/sub based in ØMQ",
"main": "index.js",
"scripts": {
"test": "mocha -R spec"
Expand Down

0 comments on commit 9bdd2d7

Please sign in to comment.