JBI logically separates Binding Components and Service Engines as two flavours of a component, the Maven JBI tooling provides that you can define a project as a jbi-component and then specify whether it is a service-engine or binding-component. Like the shared libraries we have just covered the definition of a jbi-component firstly requires the steps from Getting Started (plugin repositories and plugin) and then it also requires you change the packaging of your project.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.servicemix</groupId>
  <artifactId>MyBindingComponent</artifactId>
  <packaging>jbi-component</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>An example binding component</name>
  ...
</project>

Since a binding component or service engine has more settings than can be derived from your Maven POM.xml we also need to update the plugin section we added to configure these additional settings:

<plugin>
  <groupId>org.apache.servicemix.tooling</groupId>
  <artifactId>jbi-maven-plugin</artifactId>
  <extensions>true</extensions>
  <configuration>
    <type>binding-component</type>
    <bootstrap>org.apache.servicemix.MyBootstrap</bootstrap>
    <component>org.apache.servicemix.MyComponent</component>
  </configuration>
</plugin>

The parameters allow you to specify the following :

type - whether this is a binding-component or a service-engine
bootstrap - the name of the class that will be your bootstrap implementation
component - the name of the class that will be your component implementation

Using a Default Bootstrap

Often when you build a new component you don't need the bootstrap class and end up simply having to create a class to fulfill the specification. However, with the Maven JBI tooling you can simply not specify a bootstrap in your configuration for the plugin and the plugin will copy the DefaultBootstrap from the servicemix-common project (which basically just implements the interface) into you project and will correctly reference this in the jbi.xml. This is because the service-common shared-library is not available to the classloader for bootstrapping.

Once you have configured these steps you can run mvn install and much like the shared library maven will create both a standard jar and also a component installer.  If you have a locally running Apache ServiceMix instance (which its default settings) you can even use the plugin to install the Component by simply typing:

mvn jbi:installComponent

This will call the ANT tasks from within Maven giving the component to install as the one built in the install phase.

Service Unit Analyzers 

One of the aspects of packaging of Service Unit is providing the services element of the jbi.xml,  this is an element that contains consumes and provides (to show the services that will be used or exposed).  The JBI tooling has been extended to allow a component to intercept the construction of a service unit (for that component) in order to "analyze" the service unit and thus create the consumes and provides.

The exact mechanism for a component determining the consumes and provides for a service unit is dependent on the component and how it handles service units,  however the tooling does provide that a component can provide the configuration element serviceUnitAnalyzer this will refer to a classname within the component package.

The class defined in the serviceUnitAnalyzer needs to implement the interface ServiceUnitAnalyzer which is defined in the servicemix-common jar,  it has a simple init method which is called and passed the exploed (source) service unit and then methods that it returns a list of Consumes and Provides.  This informaiton is taken and used by the JBI plugin during the creation of the service unit for the component to add in consumes and provides.  While this information isn't needed for the JBI specification is it key to providing core information for tooling.

  • No labels