connection.js 844 B

1234567891011121314151617181920212223242526272829303132333435
  1. var ConnectionService = require('../common/service/connectionService');
  2. /**
  3. * Connection component for statistics connection status of frontend servers
  4. */
  5. module.exports = function(app) {
  6. return new Component(app);
  7. };
  8. var Component = function(app) {
  9. this.app = app;
  10. this.service = new ConnectionService(app);
  11. // proxy the service methods except the lifecycle interfaces of component
  12. var method, self = this;
  13. var getFun = function(m) {
  14. return (function() {
  15. return function() {
  16. return self.service[m].apply(self.service, arguments);
  17. };
  18. })();
  19. };
  20. for(var m in this.service) {
  21. if(m !== 'start' && m !== 'stop') {
  22. method = this.service[m];
  23. if(typeof method === 'function') {
  24. this[m] = getFun(m);
  25. }
  26. }
  27. }
  28. };
  29. Component.prototype.name = '__connection__';