Time for action - writing the bookshelf service iPOJO configuration

Create the iPOJO configuration file for the bookshelf-service bundle (under src/main/ipojo/meta.xml):

<ipojo
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="org.apache.felix.ipojo
http://felix.apache.org/ipojo/schemas/CURRENT/core.xsd"
xmlns="org.apache.felix.ipojo">

The component we're declaring here is the BookshelfServiceImpl:

<component
classname=
"com.packtpub.felix.bookshelf.service.impl.BookshelfServiceImpl"
name="BookshelfServiceImpl">

And it provides a service, which will be published against the BookshelfService interface.

<provides />

In addition to that, we ask iPOJO to inject the inventory field we have just declared:

<requires field="inventory" />
</component>

And we finish with the instance declaration:

<instance
component="BookshelfServiceImpl"
name="bookshelf.service.impl" />
</ipojo>

Update the POM

The bookshelf-service bundle should now have version 1.9.0. Edit the build plugins section of the POM, commenting out (or removing) the Bundle-Activator instruction:

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.1.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Category>sample</Bundle-Category>
<Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
<Export-Package>
com.packtpub.felix.bookshelf.service.api,
com.packtpub.felix.bookshelf.service.impl
</Export-Package>
<!-- <Bundle-Activator>
com.packtpub.felix.bookshelf.service.impl.activator.BookshelfServiceImplActivator
</Bundle-Activator>
<Private-Package>
com.packtpub.felix.bookshelf.service.impl.activator
</Private-Package> -->
</instructions>
<!-- ... -->

The activator class is also deleted.

Also add the maven-ipojo-plugin declaration:

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-ipojo-plugin</artifactId>
<version>1.4.2</version>
<executions>
<execution>
<goals>
<goal>ipojo-bundle</goal>
</goals>
<configuration>
<metadata>src/main/ipojo/meta.xml</metadata>
</configuration>
</execution>
</executions>
</plugin>

Note

Notice that the maven-ipojo-plugin declaration is the same for all projects. If you're comfortable with Maven multi-projects, this can be moved to a parent POM.

This bundle is now ready to be packaged and deployed.

Deploy and check

Once rebuilt and deployed to the releases repository, and then installed and started in Felix, checking with the ipojo:instances command should give:

g! instances
Instance bookshelf.inventory.impl.mock -> valid
Instance org.apache.felix.ipojo.arch.gogo.Arch-0 -> valid

Instance bookshelf.service.impl -> valid

The newly configured bundle was recognized by iPOJO. Let's check its details as follows:

g! instance bookshelf.service.impl
instance
component.type="BookshelfServiceImpl"
state="valid"
bundle="9"
name="bookshelf.service.impl"
handler
state="valid"
name="org.apache.felix.ipojo:requires"
requires optional="false" aggregate="false" state="resolved"
binding-policy="dynamic" proxy="true"
id="com.packtpub.felix.bookshelf.inventory.api.BookInventory"
specification=
"com.packtpub.felix.bookshelf.inventory.api.BookInventory"

...

The detailed instance information shows the bookshelf.service.impl instance registered as requiring com.packtpub.felix.bookshelf.inventory.api.BookInventory and that this requirement is fulfilled (state="resolved").

Testing the book commands should show no difference in their behavior. We'll go through a round of tests after updating the text UI bundle. But first, let's learn how to use annotations for component declarations instead of XML.

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

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