The bookshelf service is the business logic component of our case study. It will stand as a middle tier between the inventory (or data layer), which we've implemented in Chapter 4, Let's Get Started: The Bookshelf Project, and the presentation layer, which we will implement in later chapters.
In this chapter, we will define the service's API and implement it. We will also create an activator for the service to register it.
Since we do not yet have a presentation layer, we will also make the activator perform a few test actions on the service at startup to ensure that it's working as expected.
You will:
BookshelfService
interface and implement itIn the previous chapters, when we have worked on the Bookshelf Inventory API and mock implementation, we separated the API bundle from that holding the implementation.
In general, it is a good practice to separate them as it enforces the loose coupling between components and prevents the developer from making assumptions about the specifics of the implementation.
As we've seen, this loose coupling makes it easier to replace the specific implementation of the API without impacting the components that depend on it
An added benefit is that it limits the strict dependencies to those required by the API bundle. For example, our bookshelf-inventory-api
bundle has no dependencies while the bookshelf-inventory-impl-mock
bundle does. Keeping them separate simplifies the dependency structure.
However, this separation has the downside of increasing the number of bundles we're working with. The lose coupling also adds the overhead of identifying the implementation and installing it separately.
To make the previous points clearer, we will define the API and the implementation in the same bundle for the Bookshelf Service. This way, you'd have seen both cases in action and you can choose which one fits your needs best.
Let's start with the boiler-plate project preparation.
We've already gone through those steps before for the bookshelf-inventory-api
and bookshelf-inventory-impl-mock
bundles. Let's see if you can go through them on your own. The following is the information that you'll need during your setup.
com.packtpub.felix
com.packtpub.felix.bookshelf-service
1.7.0
bundle
The project will have dependencies to:
com.packtpub.felix.bookshelf-inventory-api
(1.5.0)org.osgi.core
(4.2.0)com.packtpub.felix.bookshelf.service.api
for the API interfaces and classescom.packtpub.felix.bookshelf.service.impl
for the implementationBookshelfServiceImplActivator
in the package com.packtpub.felix.bookshelf.service.impl.activator
This information should be all you need to set up the project base structure.
Once you're done with the setup, download the accompanying code and double-check if you've got it all right.
The BookshelfService
interface provides the bookshelf business logic and functionality to components that require it. It will perform a few checks before delegating to the inventory tier.
In our example, and for simplicity, the business logic tier also includes the authentication functionality. The authentication functionality is defined by the Authentication
interface, which the BookshelfService
interface extends.