concept ServiceMonitor in category java

This is an excerpt from Manning's book The Java Module System.
The first step is to show you an example of how the various features discussed throughout the book can come together by applying most of them to the ServiceMonitor application (section 15.1). Then I’ll take a deep dive into a number of more general concerns that will help you decide whether to even create modules, what to aim for when doing so, and how to carefully evolve your module declarations so they stay squeaky clean (section 15.2). I’ll close with a review of the technology landscape surrounding the module system (section 15.3) and my vision for Java’s modular ecosystem (section 15.4).
15.1 Adding bells and whistles to ServiceMonitor
Chapter 2 showed the anatomy of the ServiceMonitor application. In section 2.2, you created simple modules that only used plain
requiresandexportsdirectives. Since then, we’ve not only discussed those in detail but also explored the module system’s more-advanced features. We’ve looked at each of them individually, but now I want to put them all together.To enjoy the ServiceMonitor application in all its glory, check out the repository’s
features-combinedbranch. The following listing contains the declarations for all the modules in ServiceMonitor.Listing 15.1 ServiceMonitor, using advanced features presented throughout the book
module monitor.observer { exports monitor.observer; exports monitor.observer.utils #1 to monitor.observer.alpha, monitor.observer.beta; } module monitor.observer.alpha { requires monitor.observer; provides monitor.observer.ServiceObserverFactory #2 with monitor.observer.alpha.AlphaServiceObserverFactory; } // [...] #3 module monitor.statistics { requires transitive monitor.observer; #4 requires static stats.fancy; #5 exports monitor.statistics; } module stats.fancy { exports stats.fancy; } module monitor.persistence { requires transitive monitor.statistics; #4 requires hibernate.jpa; #6 exports monitor.persistence; opens monitor.persistence.entity; #7 } module monitor.rest { requires transitive monitor.statistics; #4 requires spark.core; #6 exports monitor.rest; } module monitor { requires monitor.observer; requires monitor.statistics; requires monitor.persistence; requires monitor.rest; uses monitor.observer.ServiceObserverFactory; #2 }
If you compare this listing to listing 2.2 or look at figure 15.1, you can see that the fundamental structure of ServiceMonitor has stayed pretty much the same. But looking closer, you can see a number of improvements. Let’s go over them one by one.
Figure 15.1a Comparison of module graphs for the ServiceMonitor application depending on feature use. The first variant only uses plain
exportsandrequiresdirectives (a), whereas the second makes full use of refined dependencies and exports as well as services (b). (The basic variant has been extended to include the same modules and packages as the advanced one.)![]()