concept monitor in category java

appears as: monitor, monitor
The Java Module System

This is an excerpt from Manning's book The Java Module System.

  • monitor—Triggers data collection and pipes the data through statistics into persistence; implements the REST API with spark
  • Upon requests, MonitorServer, which exposes the REST API, asks the monitor to provide the statistical data—either from memory or from persistence—and then extracts the requested bits and returns them.

    Listing 2.5 MonitorServer class
    public class MonitorServer {
    
     private final Supplier<Statistics> statistics;
    
     public MonitorServer(Supplier<Statistics> statistics) {
      this.statistics = statistics;
     }
    
     // [...]
    
     private Statistics getStatistics() {
      return statistics.get();
     }
    
     // [...]
    
    }

    An interesting detail to note is that although MonitorServer calls Monitor, it doesn’t depend on it. That’s because MonitorServer doesn’t get a reference to a monitor but rather a supplier for the data that forwards calls to the monitor. The reason is pretty simple: Monitor orchestrates the entire application, which makes it a class with a lot going on inside. I didn’t want to couple the REST API to such a heavyweight object just to call a single getter. Before Java 8, I might have created a dedicated interface to get the statistics and make Monitor implement it; but since Java 8, lambda expressions and the existing functional interfaces make ad hoc decoupling much easier.

    Figure 10.6 Service binding is part of module resolution: Once a module is resolved (like monitor or java.base), its uses directives are analyzed, and all modules that provide matching services (alpha and beta as well as charsets and localedata) are added to the module graph.

    c10_06.png
    sitemap

    Unable to load book!

    The book could not be loaded.

    (try again in a couple of minutes)

    manning.com homepage
    test yourself with a liveTest