master.js 876 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Component for master.
  3. */
  4. var Master = require('../master/master');
  5. /**
  6. * Component factory function
  7. *
  8. * @param {Object} app current application context
  9. * @return {Object} component instances
  10. */
  11. module.exports = function (app, opts) {
  12. return new Component(app, opts);
  13. };
  14. /**
  15. * Master component class
  16. *
  17. * @param {Object} app current application context
  18. */
  19. var Component = function (app, opts) {
  20. this.master = new Master(app, opts);
  21. };
  22. var pro = Component.prototype;
  23. pro.name = '__master__';
  24. /**
  25. * Component lifecycle function
  26. *
  27. * @param {Function} cb
  28. * @return {Void}
  29. */
  30. pro.start = function (cb) {
  31. this.master.start(cb);
  32. };
  33. /**
  34. * Component lifecycle function
  35. *
  36. * @param {Boolean} force whether stop the component immediately
  37. * @param {Function} cb
  38. * @return {Void}
  39. */
  40. pro.stop = function (force, cb) {
  41. this.master.stop(cb);
  42. };