(function() {
  var _;

  _ = require("underscore");

  module.exports = function(user_list) {
    var TestConnector;
    return TestConnector = (function() {
      function TestConnector(engine, HB, execution_listener) {
        var appliedOperationsListener, send_;
        this.engine = engine;
        this.HB = HB;
        this.execution_listener = execution_listener;
        send_ = (function(_this) {
          return function(o) {
            return _this.send(o);
          };
        })(this);
        this.execution_listener.push(send_);
        this.applied_operations = [];
        appliedOperationsListener = (function(_this) {
          return function(o) {
            return _this.applied_operations.push(o);
          };
        })(this);
        this.execution_listener.push(appliedOperationsListener);
        if (!((user_list != null ? user_list.length : void 0) === 0)) {
          this.engine.applyOps(user_list[0].getHistoryBuffer()._encode());
        }
        this.HB.setManualGarbageCollect();
        this.unexecuted = {};
      }

      TestConnector.prototype.getOpsInExecutionOrder = function() {
        return this.applied_operations;
      };

      TestConnector.prototype.send = function(o) {
        var user, _i, _len, _results;
        if ((o.uid.creator === this.HB.getUserId()) && (typeof o.uid.op_number !== "string")) {
          _results = [];
          for (_i = 0, _len = user_list.length; _i < _len; _i++) {
            user = user_list[_i];
            if (user.getUserId() !== this.HB.getUserId()) {
              _results.push(user.getConnector().receive(o));
            } else {
              _results.push(void 0);
            }
          }
          return _results;
        }
      };

      TestConnector.prototype.receive = function(o) {
        var _base, _name;
        if ((_base = this.unexecuted)[_name = o.uid.creator] == null) {
          _base[_name] = [];
        }
        return this.unexecuted[o.uid.creator].push(o);
      };

      TestConnector.prototype.flushOne = function(user) {
        var _ref;
        if (((_ref = this.unexecuted[user]) != null ? _ref.length : void 0) > 0) {
          return this.engine.applyOp(this.unexecuted[user].shift());
        }
      };

      TestConnector.prototype.flushOneRandom = function() {
        return this.flushOne(_.random(0, user_list.length - 1));
      };

      TestConnector.prototype.flushAll = function() {
        var n, ops, _ref;
        _ref = this.unexecuted;
        for (n in _ref) {
          ops = _ref[n];
          this.engine.applyOps(ops);
        }
        return this.unexecuted = {};
      };

      return TestConnector;

    })();
  };

}).call(this);

//# sourceMappingURL=../ConnectorsDeprecated/TestConnector.js.map