server_selection_events.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.WaitingForSuitableServerEvent = exports.ServerSelectionSucceededEvent = exports.ServerSelectionFailedEvent = exports.ServerSelectionStartedEvent = exports.ServerSelectionEvent = void 0;
  4. const utils_1 = require(".././utils");
  5. const constants_1 = require("../constants");
  6. /**
  7. * The base export class for all logs published from server selection
  8. * @internal
  9. * @category Log Type
  10. */
  11. class ServerSelectionEvent {
  12. /** @internal */
  13. constructor(selector, topologyDescription, operation) {
  14. this.selector = selector;
  15. this.operation = operation;
  16. this.topologyDescription = topologyDescription;
  17. }
  18. }
  19. exports.ServerSelectionEvent = ServerSelectionEvent;
  20. /**
  21. * An event published when server selection starts
  22. * @internal
  23. * @category Event
  24. */
  25. class ServerSelectionStartedEvent extends ServerSelectionEvent {
  26. /** @internal */
  27. constructor(selector, topologyDescription, operation) {
  28. super(selector, topologyDescription, operation);
  29. /** @internal */
  30. this.name = constants_1.SERVER_SELECTION_STARTED;
  31. this.message = 'Server selection started';
  32. }
  33. }
  34. exports.ServerSelectionStartedEvent = ServerSelectionStartedEvent;
  35. /**
  36. * An event published when a server selection fails
  37. * @internal
  38. * @category Event
  39. */
  40. class ServerSelectionFailedEvent extends ServerSelectionEvent {
  41. /** @internal */
  42. constructor(selector, topologyDescription, error, operation) {
  43. super(selector, topologyDescription, operation);
  44. /** @internal */
  45. this.name = constants_1.SERVER_SELECTION_FAILED;
  46. this.message = 'Server selection failed';
  47. this.failure = error;
  48. }
  49. }
  50. exports.ServerSelectionFailedEvent = ServerSelectionFailedEvent;
  51. /**
  52. * An event published when server selection succeeds
  53. * @internal
  54. * @category Event
  55. */
  56. class ServerSelectionSucceededEvent extends ServerSelectionEvent {
  57. /** @internal */
  58. constructor(selector, topologyDescription, address, operation) {
  59. super(selector, topologyDescription, operation);
  60. /** @internal */
  61. this.name = constants_1.SERVER_SELECTION_SUCCEEDED;
  62. this.message = 'Server selection succeeded';
  63. const { host, port } = utils_1.HostAddress.fromString(address).toHostPort();
  64. this.serverHost = host;
  65. this.serverPort = port;
  66. }
  67. }
  68. exports.ServerSelectionSucceededEvent = ServerSelectionSucceededEvent;
  69. /**
  70. * An event published when server selection is waiting for a suitable server to become available
  71. * @internal
  72. * @category Event
  73. */
  74. class WaitingForSuitableServerEvent extends ServerSelectionEvent {
  75. /** @internal */
  76. constructor(selector, topologyDescription, remainingTimeMS, operation) {
  77. super(selector, topologyDescription, operation);
  78. /** @internal */
  79. this.name = constants_1.WAITING_FOR_SUITABLE_SERVER;
  80. this.message = 'Waiting for suitable server to become available';
  81. this.remainingTimeMS = remainingTimeMS;
  82. }
  83. }
  84. exports.WaitingForSuitableServerEvent = WaitingForSuitableServerEvent;
  85. //# sourceMappingURL=server_selection_events.js.map