Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

iPOJO is a component model on the top of OSGi? OSGi™ aiming to simplify the development of OSGi? OSGi™ applications. Moreover, iPOJO provide an extensibility mechanism allowing developers to extend the component model.

...

A composite can be represented as a service registry. Moreover, composite can be contained in other composite. The OSGi? OSGi™ service registry is the root composite.

...

  • Import services from the parent service registry
  • Export Provide services to the parent service registry
  • Contain "sub-services" instantiated inside the composite registry

Sub-services lives in the composite and use the composite service registry. However, they don't know that they are inside a composite and use services normally. This "scoping" effect of composite allows to limit the service range.

"Hello World" composite

This section describes a simple composition example importing several services, instantiating 3 sub-services and exporting one service.

...

To illustrate the composition we will design a Hello World application named HelloComposition. This application offers a service writing a Hello message for each imported Person. Each person is published as a service and is used by the composition to write the message.
The application provides the HelloDispatcher service :

Code Block

public interface HelloDispatcher{
              public void dispatch();
	      public String getLanguage();
	      public List<Person>getPersons();
}

 

Application Design

To implement this application, we can reuse existing service implementation. Indeed, we have on the shelf 3 "instantiable" services.

  • an Hello Service : returning a Hello message
  • a Directory service : aggregating Person services to create a Directory
  • a Say Hello Dispatch Service : requiring an Hello Service and a Directory Service to write Hello Service to person contained in the Directory.

    An "instantiable" service is a service that we can instantiate through a Factory. The following code snippets show the different service specification:
    Code Block
    public interface Hello {
                  public void hello(String name);
    	      public String getLanguage();
    }
    
    Code Block
    public interface Directory {
                    public Person getPerson(String name);
                    public List<Person> getPersons();
                    public void addPerson(String name, String adress);
                    public void removePerson(String name);
    }
    
    Code Block
    public interface Person {
           public String getName();
           public String getAddress();
    }
    
    Code Block
    public interface SayService Dispatch{
                    public void say();
    }
    
    So to design our application we will use these services to obtain the following applications.

...

Code Block
<composite name="HelloComposition" factory="Hello">
                <import specification="org.apache.felix.ipojo.composition.ex1.person.Person"  aggregate="true"/>
                <export<provides specification="org.apache.felix.ipojo.composition.ex1.saycompo.SayServiceHelloDispatcher"/>
                <service specification="org.apache.felix.ipojo.composition.ex1.hello.Hello"/>
                <service specification="org.apache.felix.ipojo.composition.ex1.say.SayServiceDispatcher"/>
                <service specification="org.apache.felix.ipojo.composition.ex1.directory.Directory"/>
</composite>

...

  • Imports all available Person service in the parent composite.
  • Exports Provides the SayService Hello Dispatch to the parent composite.
  • Instantiates inside the composition a Hello service, a Say Dispatcher Service and a Directory Service.

...

  • Two factories that can create Hello service providers
  • A factory that can create SayHello Dispatch service providers
  • A factory that can create Directory service  providers

...

  • The composite will import all available services.
  • The composite will instantiate a Hello provider, one Directory provider and one SayHello provider inside the composite.
  • The composite will export the SayHello services.provides the HelloDispatcher service.
    The service providing is made by delegating service invocation on services contained in the composition. If the mapping cannot be infered, the composition is considered as invalid and cannot be started.
    If the factory which creates the Hello provider disappears, the composite will automatically used the second one to re-instantiate the service. If the second one disappears too, the composite will be invalidate (the exported service will be removed), and will wait for the apparition of a new consistent factory. Hello service implementation can be composition too.

When a person service appears this service is automatically inserted inside the composite, as well as if a person service disappear this service is automatically removed.

...

Code Block
<import specification="...Hello" optional="true" aggregate="true" filter="(language=en)"/>

Service

...

Providing

The composite can export provide services from the composite to the parent composite. Each export service providing is described by an export 'provides' element in the composite description. An export A 'provides' needs to specify targeted specification. Moreover, an export can be:provided specification.

The service providing is realized by delegating invocation on servuces contained in the composition. If the delegating mapping cannot be discovered, the composition is invalidated.  

  • Simple / aggregate: one provider is exported / all available providers are exported
  • Mandatory /optional: if no providers are available, the composite is invalidated if the export is mandatory
  • Filtered: an export can filter providers
Code Block
<export<provides specification="...Hello" optional="true" aggregate="true" filter="(language=en)"/>

Service Instantiation

A composite can instantiate a service inside the composition. The composite will track Factories able to create targeted specification providers. The create service is accessible only inside the composite (except if the service is exported). Created instance can be composite too. Each service to instantiate is represented in the composite description by a service element.

...