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 tutorial illustrates some advanced features of iPOJO

Div
classtoc
Table of Contents
maxLevel4
minLevel2

...

Context

This tutorial is based on a very simple application; customers are using a vendor service to buy hot dog or pop corn according to the availability of appropriate providers. Both of the vendors implement (and provide) the vendor service. The hot dog vendor depends on two others services to get the ingredients (buns and wiener). To sell pop corn, the pop corn vendor requires having enough corn in stock.

...

The tutorial archive is available here. This archive contains both the source code and a pre-configured version of Felix. First, unzip the archive. Then, launch 'ant' to compile the bundles composing this tutorial. Once compiled, you can launch Felix and start the tutorial. To launch, Felix launch the following command from the felix directory:

...

This class just implements the two service interfaces. Its descriptor (contained in the metadata.xml file) is:

Code Block
xml
xml
<ipojo>
<component 
    classname="org.apache.felix.ipojo.example.vendor.provider.BunWienerProvider" 
    name="buns_and_wieners" public="false">
	<provides/>
</component>

<instance component="buns_and_wieners"/>
</ipojo>

...

Compile the bundles, by launching ant at the root of the tutorial. Then launch Felix is indicated above.
Once started, launch the following commands

Code Block
none
none
start file:../vendor.services/output/vendor.services.jar
start file:../vendor.buns-and-wieners/output/vendor.buns-and-wieners.jar
start file:../vendor.hotdog/output/vendor.hotdog.jar
start file:../vendor.customer/output/vendor.customer.jar
start file:../vendor.customer.creator/output/vendor.customer.creator.jar

Something like this should appear:

Code Block
none
none
Customer customer-1 bought Hotdog from Fenway Park
Customer customer-2 bought Hotdog from Fenway Park
Customer customer-3 bought Hotdog from Fenway Park
Customer customer-4 bought Hotdog from Fenway Park
Customer customer-5 bought Hotdog from Fenway Park
Customer customer-6 bought Hotdog from Fenway Park
Customer customer-7 bought Hotdog from Fenway Park
Customer customer-8 bought Hotdog from Fenway Park

...

The instance can be re-validated by setting the field to true.
So, no deploy the pop corn vendor.

Code Block
none
none
-> start file:../vendor.popcorn/output/vendor.popcorn.jar
Customer customer-10 bought popcorn from D & P
Customer customer-9 bought popcorn from D & P

Our two last customers are no more hungry. However, new customers arrives, we have the following situation:

Code Block
none
none
-> update 10
Customer customer-1 bought popcorn from D & P
Customer customer-2 bought popcorn from D & P
Stop selling popcorn ... Run out of stock
Customer customer-3 bought popcorn from D & P

...

Create a new configuration from the configuration admin and configure this configuration to add corn. Then, we update this configuration. This will reconfigured our popcorn vendor. More information on the Configuration Admin is available in the OSGi R4 Compendium.
So, now if we deploy this bundle, we will provide enough corn to feed all the customers:

Code Block
none
none
-> start file:../vendor.corn.transporter/output/vendor.corn.transporter.jar
Update configuration of Super.PopCorn.Stock(
       file:../vendor.popcorn/output/vendor.popcorn.jar)
Refill the stock : 5
Customer customer-10 bought popcorn from D & P
Customer customer-9 bought popcorn from D & P
Customer customer-8 bought popcorn from D & P
Customer customer-7 bought popcorn from D & P
Customer customer-6 bought popcorn from D & P
Customer customer-5 bought popcorn from D & P
Customer customer-4 bought popcorn from D & P

...

This small tutorial has presented some of of the iPOJO features. 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