connection_pool_events.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ConnectionPoolClearedEvent = exports.ConnectionCheckedInEvent = exports.ConnectionCheckedOutEvent = exports.ConnectionCheckOutFailedEvent = exports.ConnectionCheckOutStartedEvent = exports.ConnectionClosedEvent = exports.ConnectionReadyEvent = exports.ConnectionCreatedEvent = exports.ConnectionPoolClosedEvent = exports.ConnectionPoolCreatedEvent = exports.ConnectionPoolMonitoringEvent = void 0;
  4. /**
  5. * The base export class for all monitoring events published from the connection pool
  6. * @public
  7. * @category Event
  8. */
  9. class ConnectionPoolMonitoringEvent {
  10. /** @internal */
  11. constructor(pool) {
  12. this.time = new Date();
  13. this.address = pool.address;
  14. }
  15. }
  16. exports.ConnectionPoolMonitoringEvent = ConnectionPoolMonitoringEvent;
  17. /**
  18. * An event published when a connection pool is created
  19. * @public
  20. * @category Event
  21. */
  22. class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
  23. /** @internal */
  24. constructor(pool) {
  25. super(pool);
  26. this.options = pool.options;
  27. }
  28. }
  29. exports.ConnectionPoolCreatedEvent = ConnectionPoolCreatedEvent;
  30. /**
  31. * An event published when a connection pool is closed
  32. * @public
  33. * @category Event
  34. */
  35. class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
  36. /** @internal */
  37. constructor(pool) {
  38. super(pool);
  39. }
  40. }
  41. exports.ConnectionPoolClosedEvent = ConnectionPoolClosedEvent;
  42. /**
  43. * An event published when a connection pool creates a new connection
  44. * @public
  45. * @category Event
  46. */
  47. class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
  48. /** @internal */
  49. constructor(pool, connection) {
  50. super(pool);
  51. this.connectionId = connection.id;
  52. }
  53. }
  54. exports.ConnectionCreatedEvent = ConnectionCreatedEvent;
  55. /**
  56. * An event published when a connection is ready for use
  57. * @public
  58. * @category Event
  59. */
  60. class ConnectionReadyEvent extends ConnectionPoolMonitoringEvent {
  61. /** @internal */
  62. constructor(pool, connection) {
  63. super(pool);
  64. this.connectionId = connection.id;
  65. }
  66. }
  67. exports.ConnectionReadyEvent = ConnectionReadyEvent;
  68. /**
  69. * An event published when a connection is closed
  70. * @public
  71. * @category Event
  72. */
  73. class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent {
  74. /** @internal */
  75. constructor(pool, connection, reason) {
  76. super(pool);
  77. this.connectionId = connection.id;
  78. this.reason = reason || 'unknown';
  79. this.serviceId = connection.serviceId;
  80. }
  81. }
  82. exports.ConnectionClosedEvent = ConnectionClosedEvent;
  83. /**
  84. * An event published when a request to check a connection out begins
  85. * @public
  86. * @category Event
  87. */
  88. class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEvent {
  89. /** @internal */
  90. constructor(pool) {
  91. super(pool);
  92. }
  93. }
  94. exports.ConnectionCheckOutStartedEvent = ConnectionCheckOutStartedEvent;
  95. /**
  96. * An event published when a request to check a connection out fails
  97. * @public
  98. * @category Event
  99. */
  100. class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent {
  101. /** @internal */
  102. constructor(pool, reason) {
  103. super(pool);
  104. this.reason = reason;
  105. }
  106. }
  107. exports.ConnectionCheckOutFailedEvent = ConnectionCheckOutFailedEvent;
  108. /**
  109. * An event published when a connection is checked out of the connection pool
  110. * @public
  111. * @category Event
  112. */
  113. class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
  114. /** @internal */
  115. constructor(pool, connection) {
  116. super(pool);
  117. this.connectionId = connection.id;
  118. }
  119. }
  120. exports.ConnectionCheckedOutEvent = ConnectionCheckedOutEvent;
  121. /**
  122. * An event published when a connection is checked into the connection pool
  123. * @public
  124. * @category Event
  125. */
  126. class ConnectionCheckedInEvent extends ConnectionPoolMonitoringEvent {
  127. /** @internal */
  128. constructor(pool, connection) {
  129. super(pool);
  130. this.connectionId = connection.id;
  131. }
  132. }
  133. exports.ConnectionCheckedInEvent = ConnectionCheckedInEvent;
  134. /**
  135. * An event published when a connection pool is cleared
  136. * @public
  137. * @category Event
  138. */
  139. class ConnectionPoolClearedEvent extends ConnectionPoolMonitoringEvent {
  140. /** @internal */
  141. constructor(pool, serviceId) {
  142. super(pool);
  143. this.serviceId = serviceId;
  144. }
  145. }
  146. exports.ConnectionPoolClearedEvent = ConnectionPoolClearedEvent;
  147. //# sourceMappingURL=connection_pool_events.js.map