@@ -19,9 +19,9 @@ import { HostInfo } from "../../host_info";
1919import { AwsWrapperError , IllegalArgumentError } from "../../utils/errors" ;
2020import { Monitor , MonitorImpl } from "./monitor" ;
2121import { WrapperProperties } from "../../wrapper_property" ;
22- import { SlidingExpirationCache } from "../../utils/sliding_expiration_cache" ;
2322import { PluginService } from "../../plugin_service" ;
2423import { Messages } from "../../utils/messages" ;
24+ import { SlidingExpirationCacheWithCleanupTask } from "../../utils/sliding_expiration_cache_with_cleanup_task" ;
2525import { ClientWrapper } from "../../client_wrapper" ;
2626
2727export interface MonitorService {
@@ -44,10 +44,13 @@ export interface MonitorService {
4444
4545export class MonitorServiceImpl implements MonitorService {
4646 private static readonly CACHE_CLEANUP_NANOS = BigInt ( 60_000_000_000 ) ;
47- protected static readonly monitors : SlidingExpirationCache < string , Monitor > = new SlidingExpirationCache (
47+ protected static readonly monitors : SlidingExpirationCacheWithCleanupTask < string , Monitor > = new SlidingExpirationCacheWithCleanupTask (
4848 MonitorServiceImpl . CACHE_CLEANUP_NANOS ,
4949 undefined ,
50- ( ) => { }
50+ async ( monitor : Monitor ) => {
51+ await monitor . releaseResources ( ) ;
52+ } ,
53+ "efm/MonitorServiceImpl.monitors"
5154 ) ;
5255 private readonly pluginService : PluginService ;
5356 private cachedMonitorHostKeys : Set < string > | undefined ;
@@ -108,7 +111,7 @@ export class MonitorServiceImpl implements MonitorService {
108111 }
109112
110113 stopMonitoringForAllConnections ( hostKeys : Set < string > ) {
111- let monitor ;
114+ let monitor : Monitor ;
112115 for ( const hostKey of hostKeys ) {
113116 monitor = MonitorServiceImpl . monitors . get ( hostKey ) ;
114117 if ( monitor ) {
@@ -119,8 +122,8 @@ export class MonitorServiceImpl implements MonitorService {
119122 }
120123
121124 async getMonitor ( hostKeys : Set < string > , hostInfo : HostInfo , properties : Map < string , any > ) : Promise < Monitor | null > {
122- let monitor ;
123- let anyHostKey ;
125+ let monitor : Monitor ;
126+ let anyHostKey : string ;
124127 for ( const hostKey of hostKeys ) {
125128 monitor = MonitorServiceImpl . monitors . get ( hostKey ) ;
126129 anyHostKey = hostKey ;
@@ -159,16 +162,13 @@ export class MonitorServiceImpl implements MonitorService {
159162 }
160163
161164 async releaseResources ( ) {
162- for ( const [ _key , monitor ] of MonitorServiceImpl . monitors . entries ) {
163- if ( monitor . item ) {
164- await monitor . item . releaseResources ( ) ;
165- }
166- }
165+ await MonitorServiceImpl . monitors . clear ( ) ;
167166 this . cachedMonitorHostKeys = undefined ;
168167 this . cachedMonitorRef = undefined ;
169168 }
170169
171- static clearMonitors ( ) {
172- MonitorServiceImpl . monitors . clear ( ) ;
170+ // Used for performance testing.
171+ static async clearMonitors ( ) {
172+ await MonitorServiceImpl . monitors . clear ( ) ;
173173 }
174174}
0 commit comments