Introduction

This book is about OSGi's role in enterprise Java and how the Spring Dynamic Modules for OSGi (Spring-DM) fulfills this role.

I first learned about OSGi when the Eclipse IDE started using it in its plug-in architecture. At the time, the versioning and modularity features seemed nicer "for an IDE" than what was available using stand-alone Java. However, OSGi still seemed something reserved to the internal workings of an IDE.

Next, I read about Java SE initiatives to incorporate similar modularity features, with OSGi being a leading contender. Competing in this space were JSR-277, "Java Module System," and JSR-291, "Dynamic Component Support for Java," the latter based on OSGi principles. Knowing that OSGi might very well influence the Java language itself—via Java SE—raised my interest in OSGi and how it could be applied to scenarios in the enterprise Java space.

It didn't take much research to find out that some Java EE application server vendors had relied on those same OSGi features to design their products. But in much the same way as the Eclipse IDE, OSGi still seemed reserved to the internal workings of a product. So I was still left with a big question: could OSGi influence enterprise Java applications in some other way? When I discovered Spring-DM, the answer became clear: yes.

OSGi along with Spring-DM will make you rethink the way you design Java applications. Support for runtime versioning is probably one of the biggest changes you will appreciate. Running multiple versions of the same class in a JVM instance is a difficult task in standalone Java, requiring the use of custom class loaders.

With OSGi this is not the case. No longer will you need to check your CLASSPATH variable to avoid running multiple JARs with the same name that may contain conflicting classes. OSGi eliminates this burden, letting you install and run as many different JAR versions as required in a single JVM instance.

This same approach will also play a part in your enterprise Java applications. The typical enterprise Java application is packaged as a Web Archive (WAR) or Enterprise Archive (EAR), monolithic formats containing every dependency used by an application. While these formats are warranted due to the way in which Java EE application servers (containers) operate—providing class isolation for each application—OSGi will make these heavyweight formats look irrelevant, since it can manage versioning and class isolation at a another level.

Additionally, WARs and EARs often contain the same staple JARs, such as logging, Java frameworks, or special libraries, leading to multiple instances of the same JAR taking up valuable memory resources in application servers. By avoiding WARs and EARs, OSGi can manage a single JAR, with different versions, that is shared across various applications.

As a consequence of applying OSGi principles to enterprise Java applications, the deployment infrastructure—Java EE application servers—will also reveal some weaknesses. That is why you also need to learn about SpringSource dm Server, a new breed of Java EE application server designed to accommodate the special features of OSGi and Spring-DM.

Once you've got a feel for OSGi's packaging approach and the benefits it brings in terms of runtime versioning and class isolation, you can start to think about OSGi services. Though not a prerequisite for using OSGi's other features, OSGi services will allow your applications to expose and consume business logic in more manageable pieces.

Instead of having application JARs expose and access Java classes available in other JARs, as is typically done, OSGi allows you to expose and consume prebuilt services contained in JARs. This allows business logic to become more manageable, since you don't have to access individual classes, but rather just query an OSGi service to obtain an end result more quickly.

Still, don't think you need to rely on the entire Spring Framework as a prerequisite to use OSGi in your enterprise Java applications. Spring-DM simply makes it easier to use OSGi in your applications employing the principles set forth by this framework. The purpose of Spring-DM is that you won't have to learn or deal with the OSGi API directly, but rather rely on dependency injection and descriptors—tenets of the Spring Framework—to work with OSGi.

As a technologist, you may well ask yourself whether OSGi and Spring-DM are the future, or just alternatives to other approaches that are likely to surpass them. I can point you to various sources that indicate that both OSGi's and Spring-DM's futures are solid.

Project Jigsaw is one of the catalysts that makes OSGi a frontrunner in the race for incorporating a module system into Java SE. For more details on this project, I will point you to a post from Mark Reinhold, Principal Engineer at Sun Microsystems for JavaSE, on the subject and its relation to OSGi: http://blogs.sun.com/mr/entry/jigsaw.

As far as Spring-DM is concerned, its principles now form part of RFC-124, "A Component Model for OSGi," which itself forms part of OSGi's 4.2 release, so its relevance is more than assured in the OSGi ecosystem. For more details on this last initiative, I can point you to two sources, one by Eric Newcomer, Chief Technology Officer at IONA, http://blogs.iona.com/newcomer/archives/000578.html, and another by Adrian Colyer, Chief Technology Officer at SpringSource, http://blog.springsource.com/2008/09/01/early-draft-of-osgi-serviceplatform-release-42-specification-now-available/.

To what extent OSGi and Spring-DM will form part of your day-to-day tasks as a Java developer is still questionable, but that they will steadily gain influence should be without question. You need not look as far as the previous resources to observe the traction both technologies are gaining in terms of standardization—explore the contents of this book to discover for yourself the benefits they bring to Java development.

Who This Book Is For

Java developers who use the Spring Framework and are looking to take advantage of OSGi features as well as Java developers in general looking to explore OSGi's role on server-side development will benefit.

How This Book Is Structured

Chapter 1 provides an introduction to OSGi. It includes a detailed look at the concepts and benefits of using OSGi with Java. It also contains a sample application to help you familiarize yourself with how OSGi applications are structured and deployed.

Chapter 2 provides an introduction to the Spring Framework. It includes a detailed look at the core concepts that have made this framework so popular in enterprise Java applications. It also contains a comprehensive application that illustrates various areas covered by the framework, such as persistence through Relational Database Management Systems (RDBMS), Model-View-Controller (MVC) design, integration testing, and deployment to a web container. Though anyone familiar with the Spring Framework should be able to skip this chapter, I recommend that you take a look at the sample application, since future chapters involve redesigned versions of this same application.

Chapter 3 provides an introduction to integrating Spring and OSGi. It includes a detailed look at the various layers—as they relate to enterprise Java applications—that need to be contemplated in order to integrate Spring and OSGi. In addition, it also contains a sample application that illustrates how Spring-DM is used in the overall design of an application.

Chapter 4 covers Spring-DM in depth. It includes an overview of fragments and extenders—OSGi concepts—and how they relate to Spring-DM. It also covers the various Spring-DM elements used inside Spring-type descriptors for registering and looking up OSGi services.

Chapter 5 provides an introduction to the SpringSource dm Server. It includes a detailed look at why this software eases the deployment of OSGi and Spring-DM applications, as well as the concepts you need to familiarize yourself with in order to use it. In addition, it contains a sample application that illustrates how to design and deploy an application using an RDBMS. (This is a version of the application introduced in Chapter 2.)

Chapter 6 covers OSGi versioning. It includes a series of case scenarios and the entire spectrum of OSGi versioning behaviors, which includes package versioning, bundle versioning, fragment versioning, and versioning cases applicable to Spring-DM and the SpringSource dm Server. A discussion on OSGi split packages is also included.

Chapter 7 covers data access and bundle management without the SpringSource dm Server. It takes a detailed look at deploying full-fledged applications without the provisions of the SpringSource dm Server. This includes a detailed look at RDBMS access in the context of OSGi, bundle dependency management using Apache Ivy, and using BND to transform JARs into OSGi-compliant bundles. It also contains a sample application ported from Chapter 5.

Chapter 8 covers web applications in the context of Spring-DM. It zooms in on how web applications are delegated and processed by an OSGi'fied web container. It also contains application samples for enabling Secure Socket Layer (SSL) or https:// web sites, working with Flex applications, and using the Jetty web server, all in the context of Spring-DM. These last applications are ported from the application presented in Chapter 7.

Chapter 9 covers Spring-DM testing. It includes a detailed look at the Spring-DM testing framework and how it facilitates the creation of tests in the context of Spring-DM. In addition, it provides working tests for the applications designed in earlier chapters.

Prerequisites

The book requires working knowledge of the Java programming language.

Downloading the Code

The source code for this book is available to readers at http://www.apress.com in the Source Code section of this book's home page. Please feel free to visit the Apress web site and download all the code there. You can also check for errata and find related titles from Apress.

Contacting the Author

You can contact me at .

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.36.38