<commit_before>var util = require('util')
  , http = require('http')
  , domain = require('domain')
  , _ = require('lodash')
  , EventEmitter2 = require('eventemitter2').EventEmitter2;


//util.inherits(Brokowski, EventEmitter); // what about maxListeners??????????


module.exports = function() {
  return new Brokowski();
};


function Brokowski() {
  this.ee = new EventEmitter2({
    maxListeners: 20
  });
  this.clear();
}


Brokowski.prototype.clear = function() {
  this.subscriptions = {};
  this.ee.removeAllListeners();
};


Brokowski.prototype.publish = function(event, data, httpMock) {
  this.ee.emit(event, data, httpMock || http);
};


Brokowski.prototype.subscribe = function(event, sub) {
  if(!isValid(sub)) return 400;

  this.subscriptions[event] = this.subscriptions[event] || {};

  if(isSubscribed(event, sub, this.subscriptions)) return 500;

  this.subscriptions[event][hash(sub)] = sub;

  this.ee.on(event, function(data, http) {
    http.request(sub)
      .on('error', function(err) {})
      .end(data);
  });

  return 200;
};


Brokowski.prototype.resubscribe = function(event, sub) {
  this.unsubscribe(event, sub);
  return this.subscribe(event, sub);
};


Brokowski.prototype.unsubscribe = function(event, sub) {
  if(this.subscriptions[event]) {
    if(this.subscriptions[event][hash(sub)]) {
      delete this.subscriptions[event][hash(sub)];
      return 200;
    }
  }
  return 500;
};


function isValid(sub) {
  if(sub.method) {
    var method = sub.method.toLowerCase();<commit_msg>trying to fix travis-ci build: broker inherits from node's builtin EventEmitter<commit_after>var util = require('util')
  , http = require('http')
  , domain = require('domain')
  , _ = require('lodash')
  , EventEmitter = require('events').EventEmitter;


util.inherits(Brokowski, EventEmitter); // what about maxListeners??????????


module.exports = function() {
  return new Brokowski();
};


function Brokowski() {
  this.clear();
}


Brokowski.prototype.clear = function() {
  this.subscriptions = {};
  this.removeAllListeners();
};


Brokowski.prototype.publish = function(event, data, httpMock) {
  this.emit(event, data, httpMock || http);
};


Brokowski.prototype.subscribe = function(event, sub) {
  if(!isValid(sub)) return 400;

  this.subscriptions[event] = this.subscriptions[event] || {};

  if(isSubscribed(event, sub, this.subscriptions)) return 500;

  this.subscriptions[event][hash(sub)] = sub;

  this.on(event, function(data, http) {
    http.request(sub)
      .on('error', function(err) {})
      .end(data);
  });

  return 200;
};


Brokowski.prototype.resubscribe = function(event, sub) {
  this.unsubscribe(event, sub);
  return this.subscribe(event, sub);
};


Brokowski.prototype.unsubscribe = function(event, sub) {
  if(this.subscriptions[event]) {
    if(this.subscriptions[event][hash(sub)]) {
      delete this.subscriptions[event][hash(sub)];
      return 200;
    }
  }
  return 500;
};


function isValid(sub) {
  if(sub.method) {
    var method = sub.method.toLowerCase();
{'fraction_non_alphanumeric': 0.16650213886146759, 'fraction_numerical': 0.011846001974333662, 'mean_word_length': 4.2504317789291886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1944504', 'n_tokens_mistral': 1047, 'n_tokens_neox': 985, 'n_words': 182}