PooledResource.js 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. const PooledResourceStateEnum = require("./PooledResourceStateEnum");
  3. /**
  4. * @class
  5. * @private
  6. */
  7. class PooledResource {
  8. constructor(resource) {
  9. this.creationTime = Date.now();
  10. this.lastReturnTime = null;
  11. this.lastBorrowTime = null;
  12. this.lastIdleTime = null;
  13. this.obj = resource;
  14. this.state = PooledResourceStateEnum.IDLE;
  15. }
  16. // mark the resource as "allocated"
  17. allocate() {
  18. this.lastBorrowTime = Date.now();
  19. this.state = PooledResourceStateEnum.ALLOCATED;
  20. }
  21. // mark the resource as "deallocated"
  22. deallocate() {
  23. this.lastReturnTime = Date.now();
  24. this.state = PooledResourceStateEnum.IDLE;
  25. }
  26. invalidate() {
  27. this.state = PooledResourceStateEnum.INVALID;
  28. }
  29. test() {
  30. this.state = PooledResourceStateEnum.VALIDATION;
  31. }
  32. idle() {
  33. this.lastIdleTime = Date.now();
  34. this.state = PooledResourceStateEnum.IDLE;
  35. }
  36. returning() {
  37. this.state = PooledResourceStateEnum.RETURNING;
  38. }
  39. }
  40. module.exports = PooledResource;