Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Include Page
FELIX:apache-felix-ipojo-headerFELIX:
apache-felix-ipojo-header

...

This page presents how to use the iPOJO runtime and its associated service component model. The concepts of the service component model are introduced, followed by a simple example that demonstrates the features of iPOJO. This tutorial uses XML to describe components, however. However, iPOJO also supports annotations and provides an a Java API for this purpose.

Introduction

iPOJO aims to simplify service-oriented programming on OSGi frameworks; the name iPOJO is an abbreviation for injected POJO. iPOJO provides a new way to develop OSGi service components with the main goal being to simplify , simplifying service component implementation by transparently managing the dynamics of the environment as well as other non-functional requirements. The iPOJO framework allows developers to more clearly separate functional code (i.e., the POJOPOJOs) from the non-functional code (i.e., dependency management, service provision, configuration, etc.). At run time, iPOJO combines the functional and non-functional aspects at run time. To achieve this, iPOJO provides a simple and extensible service component model based on POJOs.

The POJO concept

"POJO" is just an acronym for Plain Old Java Object, but it embodies a concept that the simpler and less intrusive the design of a given framework, the better. The name is used to emphasize that a given object is not somehow special, but is an ordinary Java Object. Martin Fowler, Rebecca Parsons and Josh Mackenzie coined the term POJO in September 2000: "We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it's caught on very nicely." From the a developer's perspective, the iPOJO framework strives as much as possible to only require POJOs in as much as it is possible.

iPOJO service component overview

A service component is able to provide and/or require services, where a service is an object that implements a given service interface embodied as a Java interface. In addition, iPOJO introduces a callback concept to notify a component about various state changes.

The component is the a central concept in iPOJO. In the core iPOJO model, a component describes service dependencies, provided services, and callbacks; this information is recorded in the component's metadata. ThenAfter components, the second next most important concept in iPOJO is the component instancesinstance. A component instances instance is a special version of the a component. By merging component metadata and instance configuration, the iPOJO runtime is able to manage the component, i.e., manage its life cycle, discover and inject required services, publish provided services, discover needed servicesand manage the component's life cycle.

A simple example

In this tutorial we will present how to:

...

Once created, you can build the project by launching Ant from the project directory.

Code Block
shellnoneshell
none
$ ant
Buildfile: build.xml
clean:
compile:
    [mkdir] Created dir: d:\clement\workspaces\sandbox\ipojo\examples\tutorial-ant\
            spell.services\output
    [mkdir] Created dir: d:\clement\workspaces\sandbox\ipojo\examples\tutorial-ant\
            spell.services\output\classes
    [javac] Compiling 2 source files to d:\clement\workspaces\sandbox\ipojo\examples\
            tutorial-ant\spell.services\output\classes
package:
      [bnd] spell.services 2
BUILD SUCCESSFUL
Total time: 0 seconds

...

Then, we are able to create the bundle. In the spell.english directory launch the ant command:

Code Block
shellnoneshell
none
$ ant
Buildfile: build.xml
clean:
   [delete] Deleting directory d:\clement\workspaces\sandbox\ipojo\examples\
            tutorial-ant\spell.english\output\classes
   [delete] Deleting directory d:\clement\workspaces\sandbox\ipojo\examples\
            tutorial-ant\spell.english\output
buildclasspath:
compile:
    [mkdir] Created dir: d:\clement\workspaces\sandbox\ipojo\examples\
            tutorial-ant\spell.english\output
    [mkdir] Created dir: d:\clement\workspaces\sandbox\ipojo\examples\
            tutorial-ant\spell.english\output\classes
    [javac] Compiling 1 source file to d:\clement\workspaces\sandbox\ipojo\examples\
            tutorial-ant\spell.english\output\classes
package:
      [bnd] spell.english 1
    [ipojo] Input Bundle File : d:\clement\workspaces\sandbox\ipojo\examples\
            tutorial-ant\spell.english\output\spell.english.jar
    [ipojo] Metadata File : d:\clement\workspaces\sandbox\ipojo\examples\
            tutorial-ant\spell.english\metadata.xml
    [ipojo] Start bundle manipulation
    [ipojo] Bundle manipulation - SUCCESS
    [ipojo] Output File : d:\clement\workspaces\sandbox\ipojo\examples\
            tutorial-ant\spell.english\output\spell.english.jar
BUILD SUCCESSFUL
Total time: 1 second

...

To run the example, start Felix. A distribution of Felix is provided in the felix directory. This version is configured to launch iPOJO automatically. From the Felix directory, launch the following command to start the framework. Then enter a profile name.

Code Block
shellnoneshell
none
java -jar bin/felix.jar

You can check installed bundles by using the 'ps' command:

Code Block
shellnoneshell
none
-> ps
START LEVEL 1
   ID   State        Level  Name
[   0] [Active     ] [    0] System Bundle (2.0.5)
[   1] [Active     ] [    1] Apache Felix Bundle Repository (1.4.3)
[   2] [Active     ] [    1] Apache Felix iPOJO (1.6.0)
[   3] [Active     ] [    1] Apache Felix iPOJO Arch Command (1.6.0)
[   4] [Active     ] [    1] Apache Felix Shell Service (1.4.2)
[   5] [Active     ] [    1] Apache Felix Shell TUI (1.4.1)
->

iPOJO runtime is the bundle 4. Once started, install the four created bundles as above:

Code Block
shellnoneshell
none
start file:../spell.services/output/spell.services.jar
start file:../spell.english/output/spell.english.jar
start file:../spell.checker/output/spell.checker.jar
start file:../spell.checker.gui/output/spell.checker.gui.jar

...

iPOJO provides a lot of others features that you can try in the others available tutorials. Subscribe to the Felix users mailing list by sending a message to users-subscribe@felix.apache.org; after subscribing, email questions or feedback to users@felix.apache.org.

Include Page
FELIX:apache-felix-ipojo-footerFELIX:
apache-felix-ipojo-footer