View Javadoc
1   package com.guinetik.hexafun.examples.sysmon;
2   
3   import com.guinetik.hexafun.HexaApp;
4   import com.guinetik.hexafun.hexa.UseCaseHandler;
5   
6   /**
7    * Use case handlers for system monitoring operations.
8    *
9    * <p>Each handler extends {@link UseCaseHandler} to get port access,
10   * then delegates to the {@link MetricsProvider} port for actual data.</p>
11   *
12   * <h2>Architecture</h2>
13   * <pre>
14   * [Handler] --uses--> [MetricsProvider port] --impl--> [Mock/Real Provider]
15   * </pre>
16   */
17  public final class SysmonHandlers {
18  
19      private SysmonHandlers() {}
20  
21      /**
22       * Handler for GET_CPU use case.
23       */
24      public static class GetCpuHandler extends UseCaseHandler<Void, Double> {
25  
26          public GetCpuHandler(HexaApp app) {
27              super(app);
28          }
29  
30          @Override
31          public Double apply(Void input) {
32              return port(MetricsProvider.class).getCpuUsage();
33          }
34      }
35  
36      /**
37       * Handler for GET_MEMORY use case.
38       */
39      public static class GetMemoryHandler extends UseCaseHandler<Void, Double> {
40  
41          public GetMemoryHandler(HexaApp app) {
42              super(app);
43          }
44  
45          @Override
46          public Double apply(Void input) {
47              return port(MetricsProvider.class).getMemoryUsage();
48          }
49      }
50  
51      /**
52       * Handler for GET_DISK use case.
53       */
54      public static class GetDiskHandler extends UseCaseHandler<Void, Double> {
55  
56          public GetDiskHandler(HexaApp app) {
57              super(app);
58          }
59  
60          @Override
61          public Double apply(Void input) {
62              return port(MetricsProvider.class).getDiskUsage();
63          }
64      }
65  
66      /**
67       * Handler for GET_ALL use case.
68       *
69       * <p>Returns a complete SystemMetrics snapshot.</p>
70       */
71      public static class GetAllMetricsHandler extends UseCaseHandler<Void, SystemMetrics> {
72  
73          public GetAllMetricsHandler(HexaApp app) {
74              super(app);
75          }
76  
77          @Override
78          public SystemMetrics apply(Void input) {
79              return port(MetricsProvider.class).getAllMetrics();
80          }
81      }
82  }