1 package com.guinetik.hexafun.examples.sysmon;
2
3 import static com.guinetik.hexafun.examples.sysmon.SysmonAdapters.*;
4 import static com.guinetik.hexafun.examples.sysmon.SysmonKeys.*;
5
6 import com.guinetik.hexafun.HexaApp;
7
8 /**
9 * Factory for creating the System Monitor HexaApp instance.
10 *
11 * <p>This class wires together:
12 * <ul>
13 * <li>Use cases (handlers) for fetching metrics</li>
14 * <li>Adapters for transforming metrics to various output formats</li>
15 * <li>The MetricsProvider port for infrastructure access</li>
16 * </ul>
17 *
18 * <h2>Hexagonal Architecture</h2>
19 * <pre>
20 * [TUI] --invokes--> [UseCase] --uses port--> [MetricsProvider]
21 * |
22 * [Adapter] --transforms--> [Output Format]
23 * </pre>
24 */
25 public final class SysmonApp {
26
27 private SysmonApp() {}
28
29 /**
30 * Create a configured HexaApp for system monitoring.
31 *
32 * @param provider The MetricsProvider implementation to use
33 * @return Configured HexaApp with all use cases and adapters registered
34 */
35 public static HexaApp createApp(MetricsProvider provider) {
36 HexaApp app = HexaApp.create().port(MetricsProvider.class, provider);
37
38 // Register use case handlers
39 app
40 .withUseCase(GET_CPU, new SysmonHandlers.GetCpuHandler(app))
41 .withUseCase(GET_MEMORY, new SysmonHandlers.GetMemoryHandler(app))
42 .withUseCase(GET_DISK, new SysmonHandlers.GetDiskHandler(app))
43 .withUseCase(GET_ALL, new SysmonHandlers.GetAllMetricsHandler(app));
44
45 // Register output adapters
46 app
47 .withAdapter(TO_TUI, TUI_ADAPTER)
48 .withAdapter(TO_CLI, CLI_ADAPTER)
49 .withAdapter(TO_JSON, JSON_ADAPTER)
50 .withAdapter(TO_PROMETHEUS, PROMETHEUS_ADAPTER);
51
52 return app;
53 }
54 }