Service oriented component model


Published on

The OSGi Service oriented Component Model

Published in: Technology, Education
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • SOA
  • Dynamic nature: they can be registered/unregistered to/from the service registry at any moment and the client must be prepared to cope with this situation, i.e. some notification. A service requester must be prepared to cope with situations where no required services are found or, on the other hand, multiple matching services are found. service requesters do not directly instantiate service instances, as is the case in object orientation, for example. As a result, service requesters do not know whether they are interacting with a common service instance or with different instances providing the same service.
  • Need a way to help architects to design service applications Need an easy programming model to develop applications using services
  • A typical view of components is that they implement one or more provided interfaces, where an interface is a contract of functional behavior. In this sense, interfaces provided by components are very similar to service interfaces. This makes components an ideal candidate for implementing services, where a service is equated with a provided interface.
  • Compositions are expressed in term of service specifications Applications are build by using available services
  • a service platform that includes a minimal component model, a small framework for managing the components, and a service registry. Services (i.e.,Java interfaces) are packaged along with their implementations and their associated resources into bundles . Services are deployed, as bundles. The OSGi framework creates a host environment for managing bundles and the services they provide; a bundle is the physical unit of deployment in OSGi and is also a logical concept used by the framework to internally represent the service implementation. The management mechanisms provided by the framework allow for the installation, activation, deactivation, update, and removal of bundles.
  • The activator implements activation and deactivation methods that are called to initialize and de-initialize it, respectively. In the activation/deactivation methods the activator receives a context object, which gives it access to the framework and the service registry. The context allows the activator component to register services, lookfor other services, and register itself as a listener to different types of events that the framework may fire.
  • The state of a bundle can change at any moment while the framework is running. When a bundle is stopped, its associated activator component must unregister its services and release the services that it is using. Clients of the activator component's services must take care to observe the departure of the services. The OSGi framework uses event notifications to signal service arrival and departure, but does not provide any additional support for service dependency management. Two classes of service dependencies exist in OSGi: component to-service and service-to-service. A component-to-service dependency occurs when a component depends on a service without itself providing any services. A service-to-service dependency occurs when a component provides services and also requires other services to provide its own. Writing the code tomanage component-to-service and service-to-service dependencies is complex and error-prone; managing service dependencies involves concurrency and synchronization issues as well as tedious code to monitor the arrival and departure of any used services. Monitoring involves the observation of changes in the service registry. This is done through the reception of notifications produced by the service registry that announce arrival, departure or changes in the servies. Reconfiguration involves acting in response to the changes in the services. Reconfiguration includes the release of a departing service but also the creation of a new binding towards a substituting or newly arriving service.
  • iPOJO is a service component runtime aiming to simplify OSGi application development. Based on the concept of POJO, application logic is developped easily. Non functional properties are injected in the component at runtime. iPOJO strength points are : components are developped as POJO the component model is extensible the standard component model manages service providing and service dependencies iPOJO manage the component lifecycle and the environment dynamics
  • A POJO is a very simple Java class containing only the business logic. A POJO has not dependencies on its execution environment. In iPOJO, a POJO is a Java class which serve of implementation to a component type. As a content of a component, non-functional requirements of this class will be injected by the container.
  • a component type is described by an implementation class and a container configuration. This container configuration describes non-functional requirements of the implementation / component type. For example, the container description can declare that fields are service dependencies, that it provides a service...
  • A handler is an object who can be plugged on an instance container. A handler manages one non-functional requirement of the instances. Handler can be created and deployed separately from the iPOJO runtime. So everybody can implement its own handler. It is possible to extend the component model by creating your own handler. Service dependency handler managing OSGi service discovery and invocation Service Providing handler managing the publication and the providing of OSGi services Lifecycle callback handler allowing the invocation of methods when the instance state changes Configuration Handler allowing the configuration and the dynamic reconfiguration of the instance Architecture Handler allowing to get information about the instance (state, handler ...) Lifecycle Invoke a method when the instance becomes valid or invalid Configuration Admin support Allow to dynamically (re-) configure an instance with the configuration admin Architecture view Allow to view instance and handlers information External handlers mechanism Allow to add non functional concerns in the component model Persistency Connectors : Event admin / Wire admin Configuration : JMX Task management : Cron, TaskScheduler Security … Easy to develop and to deploy
  • In fact, the container of the component contains a "Dependencies Manager" managing all the service dependency of the component. To do this, it registers an OSGi service event listener and listens for interesting events. When an interesting service arrives, it stores the service reference. When the service is used, it obtains the service object and returns the object to the component. If it is a multiple dependencies, it returns an array of service object. When a service goes away, the dependencies manager removes the reference from its list (and call the unget method): the manager does not keep any reference on the old service. This allows a complete unloading of the service. Two calls to a service can use two different service implementations if the used implementation has gone. iPOJO tries to return always the same service object, since the service goes away.
  • Field : name of the field reprensenting the dependency in the component class Interface : type of the field Optional : is the dependency an optional dependency ? Filter : filter selecting service provider Callback : allow to call a method on the component instances when a service provider (matching with the dependency) appears or disappears
  • POJO provides an ADL based of the notion of services. This kind of "composition" can be named Structural Service Composition. Generally, the application is described in terms of components or instances. iPOJO compositions are described in term of services. This composition allows more flexibility and allows service implementations to evolve without breaking the composition. As a composition can export/implement a service, a composition can be used inside another composition transparently. This brings a hierarchical composition model. Moreover, as the rest of iPOJO the composition is extensible via "composite handler", which are handler participating to a composition.
  • During execution, every component instance is managed independently by an instance manager that takes in charge service registration and service dependency management activities based on the information present in the component descriptor. The instance manager is a container that manages the instance's life-cycle through control methods and interfaces, which are only visible to the instance manager, following the Inversion of Control pattern (see figure 1).
  • A component instance is in one of two states: valid or invalid . When an instance is valid, its services are registered in the service registry and it is active (i.e., executing). When an instance is invalid, its services are not registered in the service registry and it is not active. When an instance is created, it is initially invalid. After creation, the instance manager enters a configuration phase (see figure 2). At this point, it creates bindings between the instance it manages and other instances that provide services required by the managed instance. Configuration can only succeed if bindings can be created for required service interfaces that are categorized as being mandatory. After configuration, the instance manager activates the component instance, and registers its services in the service registry. At that point the instance is valid. If configuration fails, the instance manager waits for the arrival of services that can be used to configure the instance. As soon as all mandatory services become present, the instance is validated. During execution, the instance manager receives notifications from the service registry. These notifications can trigger re-configuration activities, which depend on the dependency properties associated to the component that is being managed. The behavior of the instance manager with respect to the service dependency properties is summarized .
  • A static binding policy indicates that dependency bindings cannot change at run time, whereas a dynamic binding policy indicates that dependency bindings can change at run time. A static dependency is simpler to program than a dynamic one. 1..1, static Instance is bound to one service, any change invalidates the instance 1..1, dynamic Instance is bound to one service, changes do not invalidate the instance as long as it can be bound to another service 1..n, static Instance is bound to at least one service, any change invalidates the instance 1..n, dynamic Instance is bound to at least one service, changes do not invalidate the instance as long as the binding count is non-zero 0..1, static Instance is bound to at most one service (i.e., optional), if it is bound, departure of the bound service invalidates the instance 0..1, dynamic Instance is bound to at most one service (i.e., optional), the instance never becomes invalid 0..n, static Instance is bound to all available services at the time of binding, any departure of a bound service invalidates the instance 0..n, dynamic Instance is bound to all available services at the time of binding, as services arrive/depart they are bound/unbound to/from the instance, the instance never becomes invalid
  • bind-method: The name of the method to call on the component instance to bind a service to it. 􀀀 unbind-method: The name of the method that to call on the component instance to unbind a service from it.
  • When multiple required services are declared, it may be necessary for the component instance to be notified when the configuration phase is finished. Similarly, it may be necessary to be notified when the component instance is about to be invalidated (versus a re-configuration). This is the purpose of the methods defined in the Lifecycle interface. If the component implementation class implements this interface, the following methods are called at two different moments: activate(): During configuration, after all the bindings have been created, but before the provided services are registered. deactivate(): During execution, when the instance is about to be invalidated, after its services are unregistered and before its bindings are destroyed. ServiceBinderContext When writing an the component implementation class, it may be necessary to access the OSGi's bundle context that is provided to the activator of the bundle (altough this is usually not necessary). ServiceBinderContext is a class provided to solve this issue. If the instance class constructor receives a single ServiceBinderContext parameter, a context will be passed into it during instantiation. The methods that are provided in this context allow to: Access the bundle's BundleContext. Obtain the InstanceReference object corresponding to this instance. Obtain a list of all of the instance references that belong to the bun protected Object proxyProvidedServiceObject(Object obj, InstanceMetadata metadata) protected Object proxyRequiredServiceObject(Object obj, DependencyMetadata metadata) The first parameter of both methods contains the object to which a proxy will be added. The first method is called right after the component instance is created. The InstanceMetadata passed as a parameter provides the information about the component found on the descriptor file. The second method is called right before an invocation to a bind method takes place. The DependencyMetadata passed as a parameter contains information about the dependency such as the filter and the name of the service.
  • Service oriented component model

    1. 1. Service-Oriented Component Model
    2. 2. Content 10/19/10 2 Service-Oriented Component Model 1 A Glance at OSGi 2 iPOJO & Service Binder 3 DS & Spring OSGi 4 Comparison 5 Summary 6
    3. 3. Service-Oriented Model 10/19/10 Publication Lookup Bind & Invoke <ul><ul><li>Service: Contract of defined behavior </li></ul></ul>Service Registry Service Consumer Service Provider Service Specification
    4. 4. Service-Oriented Model <ul><li>Good challenger to tackle dynamic environments </li></ul><ul><ul><li>Loose-coupling </li></ul></ul><ul><ul><ul><li>Design by Contract </li></ul></ul></ul><ul><ul><li>Late-binding </li></ul></ul><ul><ul><ul><li>At runtime, on demand </li></ul></ul></ul><ul><ul><li>Hide heterogeneity </li></ul></ul><ul><li>Issues </li></ul><ul><ul><li>Dynamic in nature </li></ul></ul><ul><ul><ul><li>Service arrive/disappear dynamically </li></ul></ul></ul><ul><ul><ul><li>Clients cope with it i.e. Notification </li></ul></ul></ul><ul><ul><li>Service dependencies are unreliable and ambiguous </li></ul></ul><ul><ul><ul><li>No service found or multiple found </li></ul></ul></ul><ul><ul><li>Service requesters do not directly instantiate service instances </li></ul></ul><ul><ul><ul><li>Common service or different instances </li></ul></ul></ul>10/19/10
    5. 5. Service-Oriented Model <ul><li>A service way to implement the functionality </li></ul><ul><li>Focus on service dynamics and substitutabilty </li></ul><ul><li>Jini, Web Service </li></ul>10/19/10 <ul><ul><li>Dynamics is very difficult to manage </li></ul></ul>
    6. 6. Component-Oriented Model <ul><li>Focus on application building block definition </li></ul><ul><li>Creating reusable software building blocks </li></ul><ul><li>Separation of concerns </li></ul><ul><ul><li>Avoid the mix between business code and non functional concerns. </li></ul></ul><ul><li>Avoid monolithic application </li></ul><ul><ul><li>An assembler uses (existing) components and put them together </li></ul></ul>10/19/10
    7. 7. Component-Oriented Model <ul><li>A component type </li></ul><ul><ul><li>consistent piece of code </li></ul></ul><ul><ul><li>non-functional concerns configuration </li></ul></ul><ul><ul><li>defined interfaces (required and provided) </li></ul></ul><ul><li>A component instance </li></ul><ul><ul><li>Content: business code </li></ul></ul><ul><ul><li>Container: manage non functional concerns </li></ul></ul><ul><ul><ul><li>Binding, Lifecycle, Persistence, Security, Transaction … </li></ul></ul></ul><ul><li>components interfaces <=> service interfaces </li></ul><ul><ul><li>Ideal candidate for implementing services </li></ul></ul>10/19/10
    8. 8. SOC Model <ul><li>Focus on both </li></ul><ul><ul><li>Component -implementation </li></ul></ul><ul><ul><li>Service </li></ul></ul><ul><li>Objectives </li></ul><ul><ul><li>Ease the development of application using services. </li></ul></ul><ul><ul><li>Separation of concerns separate business code and dynamism management code </li></ul></ul>10/19/10 Business code Dynamic management code
    9. 9. SOC Model 10/19/10 Resolved at runtime Syntax, Description, Behavior, Semantic <ul><ul><li>Provides a functionality </li></ul></ul>Applications are build by using available services OSGi framework manage the component lifecycle
    10. 10. OSGi Platform <ul><li>OSGi framework: excution environment </li></ul><ul><ul><li>Service platform </li></ul></ul><ul><ul><ul><li>Service-oriented interaction </li></ul></ul></ul><ul><ul><li>Deployment infrastructure </li></ul></ul><ul><ul><ul><li>Continuous deployment </li></ul></ul></ul><ul><li>A set of standard service definitions </li></ul><ul><ul><li>Bundle </li></ul></ul><ul><ul><ul><li>Physical unit </li></ul></ul></ul><ul><ul><ul><li>Logical concept for the service implements </li></ul></ul></ul><ul><ul><li>Installation, activation, deactivation… </li></ul></ul>10/19/10
    11. 11. OSGi Platform <ul><li>Activator </li></ul><ul><ul><li>Component </li></ul></ul><ul><ul><li>Register and use service </li></ul></ul><ul><ul><li>Managed by framework </li></ul></ul><ul><ul><li>Implement activation and deactivation methods </li></ul></ul><ul><ul><li>Receive a context object </li></ul></ul><ul><li>BundleContext </li></ul><ul><ul><li>Interact with the OSGi framework </li></ul></ul><ul><ul><ul><li>Service publication </li></ul></ul></ul><ul><ul><ul><li>Service discovery and invocation </li></ul></ul></ul><ul><ul><ul><li>Classes and resources loading </li></ul></ul></ul>10/19/10
    12. 12. OSGi Platform <ul><li>Dynamic feature </li></ul><ul><ul><li>Departure & arrival of services </li></ul></ul><ul><ul><li>Monitoring </li></ul></ul><ul><ul><ul><li>Dependency management </li></ul></ul></ul><ul><ul><ul><li>Only notifications </li></ul></ul></ul><ul><ul><li>Reconfiguration </li></ul></ul><ul><li>Example </li></ul><ul><ul><li>Service publication </li></ul></ul><ul><ul><li>Service discovery </li></ul></ul><ul><ul><li>Service invocation </li></ul></ul><ul><ul><li>Service dynamics </li></ul></ul>10/19/10
    13. 13. Example 10/19/10 <ul><li>... </li></ul><ul><li>import tutorial.example2.service.DictionaryService; </li></ul><ul><li>public class Activator implements BundleActivator, ServiceListener </li></ul><ul><li>{ </li></ul><ul><li>private BundleContext m_context = null; </li></ul><ul><li>private ServiceReference m_ref = null; </li></ul><ul><li>private DictionaryService m_dictionary = null; </li></ul><ul><li>public void start(BundleContext context) throws Exception </li></ul><ul><li>{ </li></ul><ul><li>m_context = context; </li></ul><ul><li>m_context.addServiceListener(this, </li></ul><ul><li>&quot;(&(objectClass=&quot; + DictionaryService.class.getName() + &quot;)&quot; + </li></ul><ul><li>&quot;(Language=*))&quot;); </li></ul><ul><li>ServiceReference[] refs = m_context.getServiceReferences( </li></ul><ul><li>DictionaryService.class.getName(), &quot;(Language=*)&quot;); </li></ul><ul><ul><li>..... </li></ul></ul><ul><li>} </li></ul><ul><li>public void stop(BundleContext context) </li></ul><ul><li>{ </li></ul><ul><li>} </li></ul><ul><li>public void serviceChanged(ServiceEvent event) </li></ul><ul><li>{ </li></ul><ul><li>String[] objectClass = </li></ul><ul><li>(String[]) event.getServiceReference().getProperty(&quot;objectClass&quot;); </li></ul><ul><li>....... </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>import tutorial.example2.service.DictionaryService; public class Activator implements BundleActivator { public void start(BundleContext context) { Properties props = new Properties(); props.put(&quot;Language&quot;, &quot;English&quot;); context.registerService( DictionaryService.class.getName(), new DictionaryImpl(), props); } public void stop(BundleContext context) { } private static class DictionaryImpl implements DictionaryService { String[] m_dictionary = { &quot;welcome&quot;, &quot;to&quot;, &quot;the&quot;, &quot;osgi&quot;, &quot;tutorial&quot; }; public boolean checkWord(String word) { .... } } } package tutorial.example2.service; public interface DictionaryService { public boolean checkWord(String word); } import org.osgi.framework.BundleActivator;import org.osgi.framework.BundleContext;import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceListener;import org.osgi.framework.ServiceEvent;
    14. 14. Motivation <ul><li>OSGi does not provide a very simple development model. </li></ul><ul><li>But it provides all the basics to manage dynamic </li></ul><ul><ul><li>Events management, service registry, dynamic rebinding … </li></ul></ul><ul><li>Listener pattern </li></ul><ul><ul><li>Originally design to enable asynchronous communication in object oriented language </li></ul></ul><ul><li>Dependencies management </li></ul><ul><ul><li>Complex and error-prone </li></ul></ul><ul><ul><li>Concurrency and synchronization </li></ul></ul>10/19/10 19/10/10 Automate service registration & service dependency management
    15. 15. Existing Models <ul><li>iPOJO 0.7(Clement Escoffier) </li></ul><ul><li>Service Binder 1.1 et 1.2 (Cervantes) </li></ul><ul><li>Declarative Service (OSGi R4) </li></ul><ul><li>Spring – OSGi (Adrian Colyer and all) </li></ul><ul><li>Dependency Manager (Offermans) </li></ul><ul><li>Service Component Architecture (IBM) </li></ul>10/19/10
    16. 16. History 10/19/10 Service Binder (Humberto Cervantes) GenSD Monolithic Approach close to ServiceBinder iPOJO 0.6 : Extensible component model, Hosted on APACHE iPOJO 0.7 : Refactoring, Composite … Declarative Service (OSGi™ R4) Dependency Manager (Marcel Offermans) Spring-OSGi™ (Interfaces 21) 2004 2005 2006 october june november february june september
    17. 17. 10/19/10 a service component framework
    18. 18. iPOJO Overview <ul><li>injected POJO </li></ul><ul><ul><li>Base on byte code manipulate </li></ul></ul><ul><li>iPOJO is a service component model </li></ul><ul><ul><li>Based on POJO </li></ul></ul><ul><ul><li>For dynamic environment </li></ul></ul><ul><ul><li>Extensible and Flexible </li></ul></ul><ul><li>Aims to ease the application development on the OSGi™ framework </li></ul><ul><ul><li>Hide non functional concerns inside the implementation </li></ul></ul><ul><ul><li>Hide service interactions </li></ul></ul><ul><ul><li>Manage dynamics </li></ul></ul><ul><ul><li>Component Factory management </li></ul></ul><ul><li>iPOJO 0.7 is hosted as a subproject of the APACHE Felix project </li></ul>10/19/10
    19. 19. iPOJO Overview <ul><li>POJO </li></ul><ul><ul><li>Plain Old Java Object </li></ul></ul><ul><ul><li>Simple Java class containing the business logic </li></ul></ul><ul><ul><li>No dependencies on its execution environment </li></ul></ul><ul><li>Container around component instance </li></ul><ul><ul><li>Non-func requirement be injected </li></ul></ul>10/19/10 OSGi™ iPOJO
    20. 20. Concepts: Component <ul><li>Component Type ( Component) </li></ul><ul><ul><li>Description of a component type </li></ul></ul><ul><ul><ul><li>Name, Factory </li></ul></ul></ul><ul><ul><ul><li>Define the container configuration </li></ul></ul></ul><ul><li>Component Instance ( Instance) </li></ul><ul><ul><li>Component Factories create instances </li></ul></ul><ul><ul><li>Instance characterization </li></ul></ul><ul><ul><ul><li>Name, Component Type, Configuration </li></ul></ul></ul>10/19/10
    21. 21. Concepts: Lifecycle <ul><li>A component instance is either VALID or INVALID </li></ul><ul><li>A component instance is VALID  All handlers are valid </li></ul>10/19/10 Configured Created INVALID Stopped VALID Destroyed
    22. 22. Concepts: Container <ul><li>Plugins </li></ul><ul><ul><li>The container is composed by a IM and Handlers </li></ul></ul><ul><ul><li>An handler manage one non functional concern </li></ul></ul><ul><ul><li>Possibility to implement others handlers without modifying iPOJO core (External Handlers) </li></ul></ul><ul><ul><li>The runtime plugs the needed handlers </li></ul></ul>10/19/10 Provided Service Lifecycle Configuration Architecture Dependency
    23. 23. Concepts: Handlers <ul><li>Manage non-func requirement </li></ul><ul><li>Plugged on the instance manager </li></ul><ul><ul><li>Each instance has its own handler set (defined in its type) </li></ul></ul><ul><li>Extends the component model </li></ul><ul><li>Two kinds of handlers </li></ul><ul><ul><li>Core handlers </li></ul></ul><ul><ul><ul><li>Contained inside iPOJO Runtime </li></ul></ul></ul><ul><ul><ul><li>Lifecycle, Dependency, Provided Service, Configuration, Architecture </li></ul></ul></ul><ul><ul><li>External handlers </li></ul></ul><ul><ul><ul><li>Developed and Deployed singly from iPOJO Core </li></ul></ul></ul><ul><ul><ul><li>Developed by using the OSGi™ programming model </li></ul></ul></ul><ul><ul><ul><li>Deployed inside bundle exporting the package of the handler </li></ul></ul></ul>10/19/10
    24. 24. Concepts: Handlers <ul><li>Handlers, plugged on an instance manager </li></ul><ul><ul><li>Participate to instance lifecycle vote </li></ul></ul><ul><ul><ul><li>Ask for a vote, Invalid the instance </li></ul></ul></ul><ul><ul><li>Interact with POJO fields </li></ul></ul><ul><ul><ul><li>Inject values, be notified when the value change </li></ul></ul></ul><ul><ul><li>Invoke methods on the POJO </li></ul></ul><ul><ul><li>Create POJO objects </li></ul></ul><ul><ul><li>Get the instance Bundle Context </li></ul></ul><ul><ul><li>… </li></ul></ul><ul><li>Manage the relations between “external world” and the POJO </li></ul>10/19/10
    25. 25. Dependency Handler <ul><li>Manage dependency elements </li></ul><ul><ul><li>Service lookup and the service invocation </li></ul></ul><ul><ul><li>Affects directly the component state </li></ul></ul><ul><ul><li>Manage correctly the dynamics of OSGi </li></ul></ul><ul><li>Dependency Manager </li></ul><ul><ul><li>Manager all the dependency </li></ul></ul><ul><ul><li>Register an OSGi service event listener </li></ul></ul><ul><ul><ul><li>When service arrive, store the reference </li></ul></ul></ul><ul><ul><ul><li>When used, obtain the service object and return component </li></ul></ul></ul><ul><ul><ul><li>When goes away, remove the reference and call unset </li></ul></ul></ul><ul><ul><ul><li>Simple vs Multiple </li></ul></ul></ul><ul><ul><li>Callback </li></ul></ul>10/19/10
    26. 26. Dependency Handler 10/19/10
    27. 27. Architecture Handler <ul><li>An architectural / component view of your systems </li></ul><ul><li>Reflection on the iPOJO containers </li></ul>10/19/10 Component : fr.imag.adele.escoffier.hello.impl.HelloServiceImpl - VALID Dependency : org.osgi.service.log.LogService - RESOLVED - Optional : true - Multiple : false Provides : fr.imag.adele.escoffier.hello.HelloService - REGISTERED Service Property : floor_ = 2 Service Property : coucou = coucou Service Property : empty = true Service Property : language = fr Component : fr.imag.adele.escoffier.hello.impl.HelloServiceImpl2 - VALID Dependency : org.osgi.service.log.LogService - RESOLVED - Optional : true - Multiple : false Provides : fr.imag.adele.escoffier.hello.HelloService - REGISTERED
    28. 28. iPOJO Core Model 10/19/10
    29. 29. As Service Component <ul><li>Using special (service-aware) handlers </li></ul><ul><ul><li>Provided service handler </li></ul></ul><ul><ul><ul><li>Publish and manage an OSGi™ service </li></ul></ul></ul><ul><ul><li>Dependency Handler </li></ul></ul><ul><ul><ul><li>Discover and Track an OSGi™ service </li></ul></ul></ul><ul><li>These handlers manage OSGi™ service dynamics </li></ul><ul><li>These handlers allow dynamic service composition </li></ul><ul><ul><li>Composition described in term of service specifications not in term of component type </li></ul></ul>10/19/10
    30. 30. Example <ul><li>A component requiring a service </li></ul><ul><ul><li>The needed service is mandatory </li></ul></ul><ul><ul><li>The component require only one service provider </li></ul></ul><ul><li>A component providing a service </li></ul>10/19/10
    31. 31. Step 1 : the POJO classes <ul><li>POJO are Java classes </li></ul><ul><li>Each provided service interfaces need to be implemented by the POJO </li></ul><ul><ul><li>To be sure that all method are implemented </li></ul></ul><ul><li>A POJO needs to declare a field for each required service </li></ul><ul><ul><li>Dependencies injection </li></ul></ul>10/19/10
    32. 32. Step 1 : the POJO classes <ul><li>public class MyFirstPOJO { </li></ul><ul><li>FooService myService; </li></ul><ul><li>public void doSomething() { </li></ul><ul><li> //Do something .... </li></ul><ul><li>; </li></ul><ul><li> //Do another thing… } </li></ul><ul><li>} </li></ul><ul><li>public class MySecondPOJO implements FooService { </li></ul><ul><li>public void foo() { …} </li></ul><ul><li>} </li></ul>10/19/10
    33. 33. Step 2 : the Component Types <ul><li>A component type is describe by a name, an implementation class and the handlers configuration. </li></ul><ul><li>iPOJO manages component factories to create component instance. </li></ul><ul><ul><li>One by component type </li></ul></ul><ul><ul><li>Can be public (service) or private. </li></ul></ul>10/19/10
    34. 34. Step 2 : the Component Types <ul><li><component </li></ul><ul><li>classname=“…MyFirstPOJO” </li></ul><ul><li>factory = “myFirstType” > </li></ul><ul><li><dependency field=”myService”/> </li></ul><ul><li></component> </li></ul><ul><li><component </li></ul><ul><li>classname=“…MySecondPOJO” </li></ul><ul><li>factory = “mySecondType” > </li></ul><ul><li><provides/> </li></ul><ul><li></component> </li></ul>10/19/10
    35. 35. Step 3 : Component Instances <ul><li>An instance has a name and can receive a configuration. </li></ul><ul><li>We can declare instances in the descriptor. These instances will be created when the bundle will be started. </li></ul><ul><li>Can create instances from an external factory. </li></ul><ul><ul><li>Inside another metadata file. </li></ul></ul><ul><ul><li>By using Factory and ManagedServiceFactory services. </li></ul></ul>10/19/10
    36. 36. Step 3 : Component Instances <ul><li><instance </li></ul><ul><li>component=“myFirstType” </li></ul><ul><li>name = “myFirstInstance” </li></ul><ul><li>/> </li></ul><ul><li><instance </li></ul><ul><li>component=“mySecondType” </li></ul><ul><li>name = “mySecondInstance” </li></ul><ul><li>/> </li></ul>10/19/10
    37. 37. Step 4 : Packaging and Deployment <ul><li>iPOJO Bundles are not simple bundles </li></ul><ul><ul><li>Bytecode Manipulation </li></ul></ul><ul><ul><li>Metadata exports </li></ul></ul><ul><li>How-to create an iPOJO Bundle </li></ul><ul><ul><li>With Maven </li></ul></ul><ul><ul><li>With the Eclipse plugin (experimental) </li></ul></ul>10/19/10 <meta> {meta + manipulation} POJO POJO POJO POJO POJO iPOJO
    38. 38. Step 5 : Runtime 10/19/10 myFirstType mySecondType 2.1 instance 1.1 instance FooService Factory Factory
    39. 39. iPOJO Composition Level <ul><li>Component Composition </li></ul><ul><ul><li>Horizontal Composition : Instances can be bound by linking consistent provided interfaces and required interfaces </li></ul></ul><ul><ul><li>Vertical Composition : Instances can contain other instances </li></ul></ul><ul><li>Service Flexibility </li></ul><ul><ul><li>Runtime / Late Binding </li></ul></ul><ul><ul><li>Service dynamics </li></ul></ul><ul><ul><li>Implementation evolution </li></ul></ul><ul><li>As Composition are mapped on iPOJO instance, the composition is extensible </li></ul><ul><ul><li>Possibility to implement “Composite Handlers” extending the composition model </li></ul></ul><ul><ul><li>Follow the same rules than “normal” handlers </li></ul></ul><ul><ul><ul><li>Sub-set of Handler methods </li></ul></ul></ul>10/19/10
    40. 40. Structural Service Composition <ul><li>A Composition can import and export services </li></ul><ul><ul><li>A Composition can contain internal services (sub-services) are instantiated for the composition </li></ul></ul><ul><ul><ul><li>Published only inside the composition </li></ul></ul></ul><ul><ul><ul><li>Hierarchical Composition </li></ul></ul></ul><ul><ul><li>Sub-services dependencies are resolved in the composition scope </li></ul></ul><ul><ul><li>Service Application are compositions </li></ul></ul>10/19/10
    41. 41. Conclusion of iPOJO <ul><li>Simple development model  </li></ul><ul><li>Service management  </li></ul><ul><li>Component lifecycle management  </li></ul><ul><li>Component factory  </li></ul><ul><li>Component type / Instance  </li></ul><ul><li>Composition, ADL, Hierarchic Model  </li></ul><ul><li>Extensibility of container  </li></ul><ul><li>Architecture service  </li></ul><ul><li>Performance   </li></ul><ul><li>Distribution  </li></ul>10/19/10
    42. 42. 10/19/10 Service Binder Simplifying application development on the OSGi services platform
    43. 43. Service Binder <ul><li>Automate the management of components and their service dependency </li></ul><ul><li>Extract service dependency management logic </li></ul><ul><ul><li>Configured by information contained in an XML component descriptor file </li></ul></ul><ul><ul><li>Inserted seamlessly into a bundle by creating an empty subclass from a generic activator class </li></ul></ul><ul><ul><li>Applications are assembled dynamically and are capable of adapting themselves autonomously </li></ul></ul><ul><ul><li>Say goodbye to OSGi API and isolate from OSGi </li></ul></ul><ul><li>A standard OSGi bundle </li></ul>10/19/10
    44. 44. Execution Environment <ul><li>Compatibility with standard' OSGi </li></ul><ul><li>Generic activator </li></ul><ul><ul><li>Parse component descriptor </li></ul></ul><ul><ul><li>creates the instance managers </li></ul></ul><ul><li>Architectural service </li></ul>10/19/10
    45. 45. Concepts 10/19/10 an external view for the component and are part of the application logic IOC pattern and execution environment can manage instance's lifecycle deployment dependencies or resources
    46. 46. Instance Manager <ul><li>Every component instance is managed independently by an instance manager </li></ul><ul><ul><li>Bind/unbind required services to/from the component instance when it is created/destroyed </li></ul></ul><ul><ul><li>Register/unregister any services provided by the component instance after its required services are bound/unbound </li></ul></ul><ul><ul><li>Dynamically monitor the component instance's service dependencies, </li></ul></ul><ul><ul><li>Create/destroy the component instance when its service dependencies are satisfied/unsatisfied, </li></ul></ul><ul><li>Manages the instance's life-cycle </li></ul><ul><ul><li>Control methods and interfaces </li></ul></ul><ul><ul><li>Inversion of Control </li></ul></ul><ul><li>Constantly maintain the validity of the instance it manages </li></ul>10/19/10
    47. 47. Instance Manager 10/19/10
    48. 48. Instance Property <ul><li>Cardinality </li></ul><ul><ul><li>0-1,0-n,1-1,1-n </li></ul></ul><ul><li>Policy </li></ul><ul><ul><li>How runtime service changes are handled </li></ul></ul><ul><ul><li>How component instance lifecycle is managed </li></ul></ul><ul><ul><ul><li>Static </li></ul></ul></ul><ul><ul><ul><li>Dynamic </li></ul></ul></ul><ul><li>Filter </li></ul><ul><li>Bind/unbind </li></ul><ul><li>Factory </li></ul><ul><ul><li>Register a special FactoryService to create instance </li></ul></ul>10/19/10
    49. 49. Instance Property =>Instance Manager <ul><li>1..1, static </li></ul><ul><ul><li>Configuration: The required service interface corresponds to a single binding that must be created for the instance to be validated. </li></ul></ul><ul><ul><li>Execution: The destruction of the binding invalidates the instance </li></ul></ul><ul><li>0..n, dynamic </li></ul><ul><ul><li>Configuration: The required service interface corresponds to a set of bindings that do not need to be created for the instance to be validated. The instance manager creates bindings with all the available service providers at the moment of configuration. </li></ul></ul><ul><ul><li>Execution: New bindings can be created and bindings can be destroyed. Instance invalidation only occurs when the instance is destroyed. </li></ul></ul>10/19/10
    50. 50. Example: Step1 <ul><li>1.- Component descriptor (metadata.xml) </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><bundle> </li></ul><ul><li><component class=&quot;org.simpleclient.impl.ClientImpl&quot;> </li></ul><ul><li><provides service=&quot;org.simpleclient.interfaces.SimpleClientService&quot;/> </li></ul><ul><li><property name=&quot;author&quot; value=&quot;Humberto&quot; type=&quot;string&quot;/> </li></ul><ul><li><requires </li></ul><ul><li>service=&quot;org.simpleservice.interfaces.SimpleService&quot; </li></ul><ul><li>filter=&quot;(version=*)&quot; </li></ul><ul><li>cardinality=&quot;1..n&quot; </li></ul><ul><li>policy=&quot;dynamic&quot; </li></ul><ul><li>bind-method=&quot;setSimpleServiceReference&quot; </li></ul><ul><li>unbind-method=&quot;unsetSimpleServiceReference&quot; </li></ul><ul><li>/> </li></ul><ul><li></component> </li></ul><ul><li></bundle>` </li></ul>10/19/10
    51. 51. Step2~4 <ul><li>2.- Manifest </li></ul><ul><li>Bundle-Activator: org.simpleclient.impl.Activator </li></ul><ul><li>Import-Package: </li></ul><ul><li>org.ungoverned.gravity.servicebinder; specification-version=&quot;1.1.0&quot;, </li></ul><ul><li>org.simpleservice.interfaces; specification-version=&quot;1.0.0&quot; </li></ul><ul><li>Bundle-Name: simpleclient.jar </li></ul><ul><li>Bundle-Description: A simple client. </li></ul><ul><li>Bundle-Vendor: Humberto Cervantes </li></ul><ul><li>Bundle-Version: 1.0.0 </li></ul><ul><li>Metadata-Location: org/simpleclient/res/metadata.xml </li></ul>10/19/10 3.- Activator package org.beanome.simpleclient.impl; import org.ungoverned.gravity.servicebinder.GenericActivator; public class Activator extends GenericActivator { } 4.- Service interfaces package org.simpleclient.interfaces; public interface SimpleClientService { ... }
    52. 52. Step5: Implement Class <ul><li>package org.simpleclient.impl; </li></ul><ul><li>import org.simpleclient.interfaces.SimpleClientService; </li></ul><ul><li>import org.simpleservice.interfaces.SimpleService; </li></ul><ul><li>import java.util.ArrayList; </li></ul><ul><li>public class ClientImpl implements SimpleClientService{ </li></ul><ul><li>ArrayList m_simpleServiceRefs = new ArrayList(); </li></ul><ul><li>public ServiceImpl() { } </li></ul><ul><li>public void setSimpleServiceReference(SimpleService ref) { </li></ul><ul><li>System.out.println(&quot;-> SimpleClient: Hello SimpleService !&quot;); </li></ul><ul><li>m_simpleServiceRefs.add(ref); </li></ul><ul><li>ref.Test(); </li></ul><ul><li>} </li></ul><ul><li>public void unsetSimpleServiceReference(SimpleService ref) { </li></ul><ul><li>System.out.println(&quot;-> SimpleClient: Goodbye SimpleService ...&quot;); </li></ul><ul><li>m_simpleServiceRefs.remove(ref); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>10/19/10
    53. 53. Further Concepts <ul><li>ServiceBinderContext </li></ul><ul><li>Lifecycle </li></ul><ul><li>Interceptors </li></ul><ul><ul><li>GenericActivator </li></ul></ul><ul><ul><li>protected Object proxyProvidedServiceObject(Object obj, InstanceMetadata metadata) </li></ul></ul><ul><ul><li>protected Object proxyRequiredServiceObject(Object obj, DependencyMetadata metadata) </li></ul></ul>10/19/10
    54. 54. Conclusion of Service Binder <ul><li>Simple development model  </li></ul><ul><ul><li>Binding methods </li></ul></ul><ul><li>Service management  </li></ul><ul><li>Component lifecycle management  </li></ul><ul><li>Component factory  </li></ul><ul><li>Component type / Instance  </li></ul><ul><li>Composition  </li></ul><ul><li>Extensibility of container  </li></ul><ul><li>Architecture service  </li></ul><ul><li>Performance  </li></ul><ul><li>Distribution  </li></ul>10/19/10
    55. 55. 10/19/10 Declarative Service
    56. 56. Declarative Service Overview <ul><li>Service Compedium(RC4) </li></ul><ul><ul><li>Chapter 112 </li></ul></ul><ul><ul><li>Version 1.0 </li></ul></ul><ul><li>Declarative Service is a Service Component Model.It uses a declarative model for publishing, finding and binding to OSGi services. </li></ul><ul><li>Goals </li></ul><ul><ul><li>Simplicity </li></ul></ul><ul><ul><li>High-Performance </li></ul></ul>10/19/10
    57. 57. Declarative Service Overview 10/19/10
    58. 58. Declarative Service Overview <ul><li>Immediate Component </li></ul><ul><ul><li>An immediate component is activated as soon as its dependencies are satisfied. </li></ul></ul><ul><li>Delayed Component </li></ul><ul><ul><li>A delayed component specifies a service, the activation of the component configuration is delayed until the registered service is requested. </li></ul></ul><ul><li>Factory Component </li></ul><ul><ul><li>A Factory Component supports multiple instances. </li></ul></ul>10/19/10
    59. 59. Declarative Service Overview <ul><li>LifeCycle </li></ul><ul><ul><li>Enabled </li></ul></ul>10/19/10 Immediate Component Delayed Component Factory Component
    60. 60. Declarative Service Overview <ul><li>Service Binding and Unbinding </li></ul><ul><ul><li>2 strategy:Event & Lookup </li></ul></ul><ul><ul><li>Action in Component LifeCycle </li></ul></ul><ul><ul><ul><li>Binding: </li></ul></ul></ul><ul><ul><ul><ul><li>while activating </li></ul></ul></ul></ul><ul><ul><ul><ul><li>the references are processed in the order in which they are specified in the component description. </li></ul></ul></ul></ul><ul><ul><ul><li>Unbinding: </li></ul></ul></ul><ul><ul><ul><ul><li>while deactivating </li></ul></ul></ul></ul><ul><ul><ul><ul><li>the references are processed in the reverse order in which they are specified in the component description. </li></ul></ul></ul></ul><ul><ul><li>Reference policy </li></ul></ul><ul><ul><ul><li>Static & Dynamic </li></ul></ul></ul>10/19/10
    61. 61. Declarative Service Examples <ul><li> </li></ul><ul><ul><li>No Activator Header. </li></ul></ul><ul><ul><li>Using Service-Component Header to indicate where the Componont Description are. </li></ul></ul>10/19/10 Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: ConfigFileValidatorBundle Bundle-SymbolicName: ConfigFileValidatorBundle Bundle-Version: 1.0.0 Bundle-ClassPath: bin/,lib/junit.jar Service-Component: OSGI-INF/component.xml Import-Package: org.osgi.framework;version=&quot;1.3.0 ……
    62. 62. Declarative Service Examples 10/19/10 <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <component name=&quot;example.immediate&quot;> <implementation class=&quot;com.acme.USBConnectionImpl&quot;/> <service> <provide interface=&quot;com.acme.USBConnection&quot;/> </service> </component> package com.acme; public class USBConnectionImpl implements USBConnection { protected void activate(ComponentContext ctxt) {...} protected void activate(ComponentContext ctxt) {...} ... } /* Factory Component */ factory=“usbfactory” /* Delay Component */ immediate=“false”
    63. 63. Declarative Service Examples 10/19/10 <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <component name=&quot;example.listen&quot;> <implementation class=&quot;com.acme.HttpResourceImpl&quot;/> <reference name=&quot;HTTP&quot; interface=&quot;org.osgi.service.http.HttpService&quot; cardinality=&quot;0..n&quot; bind=&quot;setPage&quot; unbind=&quot;unsetPage&quot;/> </component> package com.acme; public class HttpResourceImpl { protected void setPage(HttpService http) { http.registerResources(&quot;/src&quot;, &quot;src&quot;, null ); } protected void unsetPage(HttpService http) { http.unregister(&quot;/src&quot;); } } /* reference policy */ policy=“dynamic” /* filter */ taget=“(version=1.0)”
    64. 64. <ul><li>Spring-OSGi </li></ul>10/19/10
    65. 65. Spring-OSGi Overview <ul><li>SourceForge </li></ul><ul><ul><li>SubProject of Spring </li></ul></ul><ul><ul><li>Licence:APL </li></ul></ul><ul><li>Current-Version:1.0 M1 </li></ul><ul><ul><li>2006,September </li></ul></ul><ul><li>Goals </li></ul><ul><ul><li>Make it as easy as possible to write Spring applications that can be deployed in an OSGi execution environment. </li></ul></ul><ul><ul><li>Also make development of OSGi applications simpler and more productive by building on the ease-of-use and power of the Spring framework. </li></ul></ul>10/19/10
    66. 66. Spring-OSGi Overview 10/19/10 <ul><li> </li></ul><ul><ul><li>No Activator Header. </li></ul></ul><ul><ul><li>Using Spring-Context Header to indicate where the Componont Description are. </li></ul></ul>Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: ConfigFileValidatorBundle Bundle-SymbolicName: ConfigFileValidatorBundle Bundle-Version: 1.0.0 Bundle-ClassPath: bin/,lib/junit.jar Spring-Context: *;wait-for-dependencies=false Import-Package: org.osgi.framework;version=&quot;1.3.0 …… META-INF/spring
    67. 67. Spring-OSGi Overview <ul><li>Export Services </li></ul><ul><ul><li>ApplicationContext----Contains some number of beans(Components/Services) </li></ul></ul>10/19/10 <osgi:service interface =“;> <bean class=“MessageServiceProvider”/> </osgi:service> <bean id =“MessageServiceProvider“ class=“”/> </bean> lazy-init=“true”
    68. 68. Spring-OSGi Overview <ul><li>Using Services </li></ul><ul><ul><li>Using BundleContextAware interface </li></ul></ul><ul><ul><li>Inject Services </li></ul></ul>10/19/10 <osgi:reference id=“MessageService“ interface=“”/> <bean id=“MyBean” class=“SomeClass”> <property name=“messageService” ref=“MessageService”/> </bean> public class SomeClass { public void setMessageService(MessageService s) { … } } cardinality=&quot;0..n“ filter=“(version=1.0)”
    69. 69. Spring-OSGi Overview <ul><li>Using Services </li></ul><ul><ul><li>Binding and Unbinding Services </li></ul></ul>10/19/10 <osgi:reference id=“MessageService“ interface=“”> <osgi:listener ref=“listenerBean” bind-method=“bind” unbind-method=“bind”/> </osgi:reference> <bean id=“listenerBean” class=“SomeClass”/> public class SomeClass { public void bind( MessageService s) { … } public void unbind( MessageService s){ … } }
    70. 70. Spring-OSGi Overview <ul><li>Context ClassLoader Management </li></ul><ul><ul><li>OSGi doesn’t define what the context ClassLoader will be at any point in time.This means some useful 3rd-party libraries may not be able to find the types and resources they need. </li></ul></ul>10/19/10 <osgi:reference id=“MessageService“ interface=“” context-classloader=“client”> <osgi:listener ref=“listenerBean” bind-method=“bind” unbind-method=“bind”/> </osgi:reference> Service-provider Unmanaged(default)
    71. 71. Spring-OSGi Overview <ul><li>Web application Support </li></ul><ul><ul><li>Set the contextClass parameter of the listener declaration in web.xml file to “ WebApplicationContext” </li></ul></ul><ul><li>JMX Manament of OSGi applications </li></ul><ul><ul><li>Spring provide an OSGi bundle that enables JMX-based management of OSGi. </li></ul></ul>10/19/10
    72. 72. Comparison <ul><li>A development model simple and non intrusive </li></ul><ul><li>Dynamics management and component lifecycle management </li></ul><ul><li>Differentiation between component type / Instance </li></ul><ul><li>Composition, ADL, Hierarchic Model </li></ul><ul><li>Other non functional concerns management, extensibility, flexibility </li></ul><ul><li>Runtime representation </li></ul><ul><li>Performance </li></ul><ul><li>Distribution </li></ul>10/19/10
    73. 73. Comparison 10/19/10 ContextClassLoader Service Mngt Life Cycle Component Factory Composite Ext. & Open Container Arch. Service Binder 1.2 N Y Y Y Y N Y Declarative Service N Y Y Y N N N Spring-OSGi Y Y y N N N N iPOJO 0.7 N
    74. 74. References <ul><li>H. Cervantes and R.S. Hall. &quot;Automating Service Dependency Management in a Service-Oriented Component Model,&quot; Proceedings of the Sixth Component-Based Software Engineering Workshop, May 2003, pp. 91-96. </li></ul><ul><li>Clement Escoffier. “iPOJO Yet Another Service-Oriented Component Model”.ppt </li></ul><ul><li>Clement escoffier . </li></ul><ul><li>Humberto Cervantes, Richard S. Hall . </li></ul><ul><li>Martin Fowler.Inversion of Control Containers and the Dependency Injection pattern </li></ul><ul><li>Neil.A Comparison of Eclipse Extensions and OSGi Services </li></ul><ul><li>BlueDavy.Service-Oriented Component Model(SOCM) </li></ul><ul><li> </li></ul><ul><li> </li></ul>10/19/10
    75. 75. Click to edit company slogan . We can always do better than good. Thank You !