OSGi is the dynamic module system for
Java. In OSGi parlance, a module is known as a bundle. OSGi provides a framework for managing bundles that are packaged as regular Java JAR files with an accompanying manifest. The manifest contains important metadata that describes the bundles and its dependencies to the OSGi framework. However, OSGi is not a prerequisite for using the modularity
patterns. OSGi simply provides a runtime environment that enables and enforces modularity on the Java platform. OSGi offers the following capabilities:
Modularity: Enables and enforces a modular approach to architecture on the Java platform.Versioning: Supports multiple versions of the same software module deployed within the same Java Virtual Machine (JVM) instance.Hot deployments: Permits modules to be deployed and updated within a running system without restarting the application or the JVM.Encapsulation: Allows modules to hide their implementation details from consuming modules.Service orientation: Encourages service-oriented design principles in a more granular level within the JVM. To accomplish this, OSGi uses μServices.Dependency management: Requires explicit declaration of dependencies between modules.
You can read all about OSGi at the
OSGi Alliance website.
OSGi is certainly applicable for any type of application, especially if any of the above advantages interest you. One of the greatest advantages of OSGi is that it enforces modularity. To use OSGi today, you have to embed an OSGi framework, such as Equinox or Apache Felix, into your application. For Java web apps that run on an app server, this can be a bit challenging if the app server itself doesn't do it for you since OSGi uses a different classloader model (i.e. peer) than most app servers (i.e., hierarchical). However, almost all app server platforms are incorporating OSGi and exposing it to the developer and allow you to take advantage of OSGi.
The beauty of the Java Application Architecture book is that it shows you how to develop modular software even if you cannot use OSGi today (i.e., lack of platform support) so that in the future, you can easily take advantage of the benefits of OSGi (or even Jigsaw in Java 8) when it's available. So the book allows you to start developing modular software today in anticipation of platform support for modularity in the future. Part 3 in the book shows you exactly how easy this can be.
Visit the book's website at
modularity.kirkk.com where you can review all 18 patterns and download an excerpt of the book. There is also a
mobile web application available that you can take with you wherever you go.