Source: sessionHandler/sessionHandlerExecutor.js

  1. /**
  2. * @author Sloan Seaman
  3. * @copyright 2016 and on
  4. * @version .1
  5. * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  6. */
  7. /** @private */
  8. var AbstractPromiseExecutor = require('../executor/abstractPromiseExecutor.js');
  9. var log = require('winston-simple').getLogger('SessionHandlerExecutor');
  10. /**
  11. * The SessionHandlerExecutor manages the execution of the registered SessionHandlers.
  12. *
  13. * This works by iterating over the list of registered SessionHandlers and, when a `Promise` is discovered, waits
  14. * until the completion, and then continues over the loop
  15. *
  16. * @constructor
  17. * @see {@link SessionHandlerManager}
  18. * @param {SessionHandler} [startHandlers] The start SessionHandlers to execute
  19. * @param {SessionHandler} [endHandlers] The end SessionHandlers to execute
  20. */
  21. function SessionHandlerExecutor(startHandlers, endHandlers) {
  22. this._start = startHandlers;
  23. this._end = endHandlers;
  24. }
  25. SessionHandlerExecutor.prototype = Object.create(AbstractPromiseExecutor.prototype);
  26. SessionHandlerExecutor.prototype.constructor = SessionHandlerExecutor;
  27. /**
  28. * Executes the start SessionHandlers.
  29. *
  30. * @function
  31. * @param {SVContext} svContext The context to execute with
  32. * @returns {Promise} The `Promise` that can be used to wait until this completes
  33. */
  34. SessionHandlerExecutor.prototype.executeStart = function(svContext) {
  35. var she = this; // to control scoping in the promises
  36. return new Promise(function (resolve, reject) {
  37. log.info("Starting SessionHandler Execution");
  38. she._doExecute('sessionStart', she._start, svContext)
  39. .then(function() {
  40. log.info("SessionHandler Execution completed");
  41. resolve();
  42. })
  43. .catch(function(err) {
  44. reject(err);
  45. });
  46. });
  47. };
  48. /**
  49. * Executes the end SessionHandlers
  50. *
  51. * @function
  52. * @param {SVContext} svContext The context to execute with
  53. * @returns {Promise} The `Promise` that can be used to wait until this completes
  54. */
  55. SessionHandlerExecutor.prototype.executeEnd = function(svContext) {
  56. var she = this; // to control scoping in the promises
  57. return new Promise(function (resolve, reject) {
  58. log.info("Starting SessionHandler Execution");
  59. she._doExecute('sessionEnd', she._start, svContext)
  60. .then(function() {
  61. log.info("SessionHandler Execution completed");
  62. resolve();
  63. })
  64. .catch(function(err) {
  65. reject(err);
  66. });
  67. });
  68. };
  69. module.exports = SessionHandlerExecutor;