|
1 | 1 | import { GetMore, KillCursor, Msg, WriteProtocolMessageType } from './commands';
|
2 | 2 | import { calculateDurationInMs, deepCopy } from '../utils';
|
3 |
| -import { ConnectionPool, ConnectionPoolOptions } from './connection_pool'; |
| 3 | +import type { ConnectionPool } from './connection_pool'; |
4 | 4 | import type { Connection } from './connection';
|
5 | 5 | import type { Document } from '../bson';
|
6 |
| -import type { AnyError } from '../error'; |
7 |
| - |
8 |
| -/** |
9 |
| - * The base export class for all monitoring events published from the connection pool |
10 |
| - * @public |
11 |
| - * @category Event |
12 |
| - */ |
13 |
| -export class ConnectionPoolMonitoringEvent { |
14 |
| - /** A timestamp when the event was created */ |
15 |
| - time: Date; |
16 |
| - /** The address (host/port pair) of the pool */ |
17 |
| - address: string; |
18 |
| - |
19 |
| - constructor(pool: ConnectionPool) { |
20 |
| - this.time = new Date(); |
21 |
| - this.address = pool.address; |
22 |
| - } |
23 |
| -} |
24 |
| - |
25 |
| -/** |
26 |
| - * An event published when a connection pool is created |
27 |
| - * @public |
28 |
| - * @category Event |
29 |
| - */ |
30 |
| -export class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent { |
31 |
| - /** The options used to create this connection pool */ |
32 |
| - options?: ConnectionPoolOptions; |
33 |
| - |
34 |
| - constructor(pool: ConnectionPool) { |
35 |
| - super(pool); |
36 |
| - this.options = pool.options; |
37 |
| - } |
38 |
| -} |
39 |
| - |
40 |
| -/** |
41 |
| - * An event published when a connection pool is closed |
42 |
| - * @public |
43 |
| - * @category Event |
44 |
| - */ |
45 |
| -export class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent { |
46 |
| - constructor(pool: ConnectionPool) { |
47 |
| - super(pool); |
48 |
| - } |
49 |
| -} |
50 |
| - |
51 |
| -/** |
52 |
| - * An event published when a connection pool creates a new connection |
53 |
| - * @public |
54 |
| - * @category Event |
55 |
| - */ |
56 |
| -export class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent { |
57 |
| - /** A monotonically increasing, per-pool id for the newly created connection */ |
58 |
| - connectionId: number | '<monitor>'; |
59 |
| - |
60 |
| - constructor(pool: ConnectionPool, connection: Connection) { |
61 |
| - super(pool); |
62 |
| - this.connectionId = connection.id; |
63 |
| - } |
64 |
| -} |
65 |
| - |
66 |
| -/** |
67 |
| - * An event published when a connection is ready for use |
68 |
| - * @public |
69 |
| - * @category Event |
70 |
| - */ |
71 |
| -export class ConnectionReadyEvent extends ConnectionPoolMonitoringEvent { |
72 |
| - /** The id of the connection */ |
73 |
| - connectionId: number | '<monitor>'; |
74 |
| - |
75 |
| - constructor(pool: ConnectionPool, connection: Connection) { |
76 |
| - super(pool); |
77 |
| - this.connectionId = connection.id; |
78 |
| - } |
79 |
| -} |
80 |
| - |
81 |
| -/** |
82 |
| - * An event published when a connection is closed |
83 |
| - * @public |
84 |
| - * @category Event |
85 |
| - */ |
86 |
| -export class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent { |
87 |
| - /** The id of the connection */ |
88 |
| - connectionId: number | '<monitor>'; |
89 |
| - /** The reason the connection was closed */ |
90 |
| - reason: string; |
91 |
| - |
92 |
| - constructor(pool: ConnectionPool, connection: Connection, reason: string) { |
93 |
| - super(pool); |
94 |
| - this.connectionId = connection.id; |
95 |
| - this.reason = reason || 'unknown'; |
96 |
| - } |
97 |
| -} |
98 |
| - |
99 |
| -/** |
100 |
| - * An event published when a request to check a connection out begins |
101 |
| - * @public |
102 |
| - * @category Event |
103 |
| - */ |
104 |
| -export class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEvent { |
105 |
| - constructor(pool: ConnectionPool) { |
106 |
| - super(pool); |
107 |
| - } |
108 |
| -} |
109 |
| - |
110 |
| -/** |
111 |
| - * An event published when a request to check a connection out fails |
112 |
| - * @public |
113 |
| - * @category Event |
114 |
| - */ |
115 |
| -export class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent { |
116 |
| - /** The reason the attempt to check out failed */ |
117 |
| - reason: AnyError | string; |
118 |
| - |
119 |
| - constructor(pool: ConnectionPool, reason: AnyError | string) { |
120 |
| - super(pool); |
121 |
| - this.reason = reason; |
122 |
| - } |
123 |
| -} |
124 |
| - |
125 |
| -/** |
126 |
| - * An event published when a connection is checked out of the connection pool |
127 |
| - * @public |
128 |
| - * @category Event |
129 |
| - */ |
130 |
| -export class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent { |
131 |
| - /** The id of the connection */ |
132 |
| - connectionId: number | '<monitor>'; |
133 |
| - |
134 |
| - constructor(pool: ConnectionPool, connection: Connection) { |
135 |
| - super(pool); |
136 |
| - this.connectionId = connection.id; |
137 |
| - } |
138 |
| -} |
139 |
| - |
140 |
| -/** |
141 |
| - * An event published when a connection is checked into the connection pool |
142 |
| - * @public |
143 |
| - * @category Event |
144 |
| - */ |
145 |
| -export class ConnectionCheckedInEvent extends ConnectionPoolMonitoringEvent { |
146 |
| - /** The id of the connection */ |
147 |
| - connectionId: number | '<monitor>'; |
148 |
| - |
149 |
| - constructor(pool: ConnectionPool, connection: Connection) { |
150 |
| - super(pool); |
151 |
| - this.connectionId = connection.id; |
152 |
| - } |
153 |
| -} |
154 |
| - |
155 |
| -/** |
156 |
| - * An event published when a connection pool is cleared |
157 |
| - * @public |
158 |
| - * @category Event |
159 |
| - */ |
160 |
| -export class ConnectionPoolClearedEvent extends ConnectionPoolMonitoringEvent { |
161 |
| - constructor(pool: ConnectionPool) { |
162 |
| - super(pool); |
163 |
| - } |
164 |
| -} |
165 |
| - |
166 |
| -export const CMAP_EVENT_NAMES = [ |
167 |
| - ConnectionPool.CONNECTION_POOL_CREATED, |
168 |
| - ConnectionPool.CONNECTION_POOL_CLOSED, |
169 |
| - ConnectionPool.CONNECTION_CREATED, |
170 |
| - ConnectionPool.CONNECTION_READY, |
171 |
| - ConnectionPool.CONNECTION_CLOSED, |
172 |
| - ConnectionPool.CONNECTION_CHECK_OUT_STARTED, |
173 |
| - ConnectionPool.CONNECTION_CHECK_OUT_FAILED, |
174 |
| - ConnectionPool.CONNECTION_CHECKED_OUT, |
175 |
| - ConnectionPool.CONNECTION_CHECKED_IN, |
176 |
| - ConnectionPool.CONNECTION_POOL_CLEARED |
177 |
| -] as const; |
178 | 6 |
|
179 | 7 | /**
|
180 | 8 | * An event indicating the start of a given
|
|
0 commit comments