var Logger = require('logger-facade-nodejs'),
    _ = require('lodash'),
    SMI = require('./smi'),
    Backend = require('./backend'),
    Frontend = require('./frontend'),
    packageJson = require('../package.json');

var Broker = function(configuration, smiService, frontend, backend){
  var defaults = {
    frontend: 'tcp://127.0.0.1:5560',
    backend: 'tcp://127.0.0.1:5559',
    smi: {
      // heartbeat interval in ms
      heartbeat: 1000,
      // max ttl for a service in ms
      maxTTL: 1500,
      // refresh service ttl update interval in ms
      updateInterval: 100
    }
  };

  var config = _.defaults(configuration, defaults);

  // alway override version
  config.version = packageJson.version;

  var log = Logger.getLogger('Broker');

  // public methods

  this.version = config.version;

  this.run = function(){
    log.info("Async Broker v%s", config.version);

    smiService = smiService || new SMI(config.smi);
    smiService.run(config.smi);

    backend =  backend || new Backend({ backend: config.backend }, smiService);
    frontend = frontend || new Frontend({ frontend: config.frontend }, smiService);

    backend.frontendSendCallback = frontend.send;
    frontend.backendSendCallback = backend.send;

    backend.run();
    frontend.run();

    log.info("Async Broker is waiting for messages...\n");
  };

  this.stop = function(){
    log.info("\nAsync Broker disconnecting...");

    smiService.stop();
    frontend.stop();
    backend.stop();
  };

};

module.exports = Broker;

@@ -761,68 +761,12 @@
 %0A%0A  
-// public methods%0A%0A  this.version = config.version;%0A%0A  this.
+var 
 run 
@@ -1291,13 +1291,12 @@
 %0A%0A  
-this.
+var 
 stop
@@ -1430,16 +1430,97 @@
 ;%0A  %7D;%0A%0A
+  return %7B%0A    version: config.version,%0A    run:     run,%0A    stop:    stop%0A  %7D;%0A
 %7D;%0A%0Amodu

refactor broker module to avoid using the this keywords