Adrià Vilanova Martínez | 43c7520 | 2024-10-19 15:55:15 +0200 | [diff] [blame^] | 1 | import NodeWatcherSingleton, { NodeWatcherAdapter } from '../../../../infrastructure/presentation/nodeWatcher/NodeWatcher.adapter'; |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 2 | import { ConcreteNodeWatcherScriptHandler } from './handlers/NodeWatcherScriptHandler'; |
| 3 | import Script from '../Script'; |
| 4 | |
Adrià Vilanova Martínez | 8b591d9 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 5 | /** |
| 6 | * @deprecated |
| 7 | */ |
| 8 | export default abstract class LegacyNodeWatcherScript<Options> extends Script { |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 9 | public abstract handlers: Map< |
| 10 | string, |
| 11 | ConcreteNodeWatcherScriptHandler<Options> |
| 12 | >; |
| 13 | |
Adrià Vilanova Martínez | 43c7520 | 2024-10-19 15:55:15 +0200 | [diff] [blame^] | 14 | private nodeWatcher: NodeWatcherAdapter; |
| 15 | |
| 16 | constructor() { |
| 17 | super(); |
| 18 | |
| 19 | // TODO(https://iavm.xyz/b/226): Retrieve this via constructor injection. |
| 20 | this.nodeWatcher = NodeWatcherSingleton.getInstance(); |
| 21 | } |
| 22 | |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 23 | /** |
| 24 | * Resolves to the options when the script is executed. |
| 25 | * |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 26 | */ |
| 27 | protected abstract optionsFactory(): Options; |
| 28 | |
| 29 | execute() { |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 30 | const options = this.optionsFactory(); |
| 31 | |
Adrià Vilanova Martínez | 43c7520 | 2024-10-19 15:55:15 +0200 | [diff] [blame^] | 32 | this.nodeWatcher.start(); |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 33 | for (const [key, handlerClass] of this.handlers) { |
| 34 | const handler = new handlerClass(options); |
Adrià Vilanova Martínez | 43c7520 | 2024-10-19 15:55:15 +0200 | [diff] [blame^] | 35 | this.nodeWatcher.setHandler(key, handler); |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | } |