SlideShare a Scribd company logo
Weld-OSGi
Injecting easiness in OSGi
Mathieu ANCELIN

•Software engineer @SERLI
•Java & OSS guy
 •JOnAS, GlassFish, Weld, etc ...
 •Poitou-Charentes JUG crew member
•CDI 1.1 (JSR-346) expert group member
•What else?
•@TrevorReznik
A few words about SERLI

•Software engineering company based in France
•65 people
•80% of the business is Java-related
•Small company working for big ones
•OSS contribution : 10% of workforce
•www.serli.com @SerliFr
Before we start

#judcon


   #weld-osgi
Agenda
•CDI, the best part of Java EE 6
•OSGi, deep dive into modularity and dynamism
•Meet Weld-OSGi
 •How does it work?
 •Features and programming model
 •Pros and cons
•Back to the future
•Demo
•Conclusion
CDI
CDI
                                        @Any
@ApplicationScoped
                           @Model              @Default
        @Inject
                           @Observes   @Dispose
      @SessionScoped
                                       @Named
@RequestScoped         @Produces                  @Typed
              @Singleton            @Stereotype

  @Qualifier             @Scope            @New
CDI
                                        @Any
@ApplicationScoped
                           @Model              @Default
        @Inject
                           @Observes   @Dispose
      @SessionScoped
                                       @Named
@RequestScoped         @Produces                  @Typed
              @Singleton            @Stereotype

  @Qualifier             @Scope            @New
CDI
•The best part of Java EE 6 (coolest)
 •#annotationsEverywhere
•Basically there is no limite of what you can do
 •if you can think about it, you can do it
 •standard extensions :-)
•JBoss Weld is the reference implementation
 •pretty mature, good community
•Limited to Java EE 6?
 •well, not necessarily ...
Environnements for CDI/Weld
•You can boostrap Weld very easily outside Java EE
 environment
 •You can bootstrap it anywhere :-)
•For instance
 •Weld-Servlet
  •Jetty
  •Tomcat 6/7
 •Weld-SE
  •Good old Desktop Java apps.
 •You name it ?
OSGi
•An amazing modular and dynamic platform for Java
•Very stable and powerful but old APIs

                              Bundles

                               Service

                              Lifecycle

                              Module

                    Java environment
Modules / Bundles
                                                    Bundle-SymbolicName: com.sample.app
Bundle-SymbolicName: com.foo.bar




                    manifest                                   manifest




                                                              Export-Package: com.sample.app.api;
                                                                        version=1.2.0
              Import-Package: com.sample.app.api;
                     version=[1.2.0-2.0.0)
Lifecycle
                                              update
                                              refresh
                      install




                        Installed                               Starting
                                    update              start
            resolve                 refresh
uninstall




                                                                 Active
                        Resolved
                                                                           stop
                  uninstall
                                                                Stopping
                      Uninstalled
Services
                                   notify



                                            listener

           register    OSGI      lookup
Bundle A              service               Bundle B
                      registry
Weld-OSGi
•(try to be) the best of both worlds
 •dynamic, typesafe, annotations, etc ...
•CDI extension to use CDI programming model inside OSGi
•A JBoss Weld project
 •need to bootstrap Weld in an OSGi environment
•Developed by SERLI R&D team
 •Mathieu & Matthieu
•You don’t need to know OSGi
 •make the OSGi programming model disappear in favor
   of standard CDI
 •but still compatible
How does it work ?
Features

•Use Weld/CDI inside OSGi environment
•OSGi injection utilities
•Dynamic services publication
•Dynamic services injection
•Integration with OSGi events API
•Inter-bundles events
Using Weld / CDI in OSGi
  •Install a bundle with META-INF/beans.xml file
  •If you don’t need automatic startup
   •Specify that Weld-OSGi must not handle the bundle
      •entry in the bundle manifest : Embedded-
       CDIContainer: true
   •Specification of an embedded mode in CDI 1.1
   •Special Weld-OSGi events


public void start(@Observes BundleContainerInitialized event) {}

public void stop(@Observes BundleContainerShutdown event) {}
Embedding CDI
EmbeddedCDIContainer cdi = 
    new EmbeddedContainer(bundleContext).initialize();
MyService service = 
    cdi.instance().select(MyService.class).get();
service.doSomething();
cdi.stop();

or

WeldContainer weld = 
    new WeldContainer(bundleContext).initialize();
MyService service =
    weld.instance().select(MyService.class).get();
service.doSomething();
weld.stop();
OSGi injection utilities
•Easier access to OSGi APIs (if needed)
 •Injection of the current bundle
 •Injection of the current bundleContext
 •Injection of the current metadata
 •Injection bundle files (inside OSGi container)
•Other utilities are added while moving forward
OSGi injection utilities
 •Easier access to OSGi APIs (if needed)
  •Injection of the current bundle
  •Injection of the current bundleContext
  •Injection of the current metadata
  •Injection bundle files (inside OSGi container)
 •Other utilities are added while moving forward
 @Inject Bundle bundle;
 @Inject BundleContext context;
 @Inject @BundleHeaders Map<String, String> headers;
 @Inject @BundleHeader("Bundle-SymbolicName") String symbolicName;
 @Inject @BundleDataFile("text.txt") File text;
Services publication
Services publication
•Declarative publication
 @Publish
 @ApplicationScoped
 @Lang(EN)
 public class MyServiceImpl implements MyService {
     ...
 }
Services publication
•Declarative publication
 @Publish
 @ApplicationScoped
 @Lang(EN)
 public class MyServiceImpl implements MyService {
     ...
 }
•Dynamic publication
 @Inject Instance<MyService> instance;
 @Inject ServiceRegistry registry;
 MyService service = instance.get();
 Registration<MyService> reg = registry.register(service);
 ...
 reg.unregister();
Services injection
Services injection

•Dynamic injection
@Inject @OSGiService MyService service;
service.doSomething(); // fail if no services available
Services injection

   •Dynamic injection
    @Inject @OSGiService MyService service;
    service.doSomething(); // fail if no services available


                            P   get()              create()
                            R
@Inject @OSGiService
MyService service;          O           Provider              InjectionPoint

                            X
                            Y
Services injection

service.doSomething()                   get()
                        P
                        R
                        O   doSomething()                   OSGi
                        X
                                                 actual
                                                 service   service
                        Y                                  registry

                                       unget()
Services injection
•Programmatic injection - whiteboard pattern (like
 Instance<T>)
 @Inject Service<MyService> service;

 for (MyService actualService : service.first()) {
     actualService.doSomething(); // called on 0-1 service
 }
 for (MyService actualService : service) {
     actualService.doSomething(); // called on 0-n service(s)
 }
 service.get().doSomething(); // can fail, not dynamic
 service.size();
 service.isUnsatisfied();
 service.isAmbiguous();
Services injection - filters
@Publish
@Lang(EN) @Country(US)
public class MyServiceImpl implements MyService {
    ...
}
Services injection - filters
@Publish
@Lang(EN) @Country(US)
public class MyServiceImpl implements MyService {
    ...
}


@Inject @OSGiService 
           @Filter("(&(lang=*)(country=US))") MyService service;
Services injection - filters
@Publish
@Lang(EN) @Country(US)
public class MyServiceImpl implements MyService {
    ...
}


@Inject @Filter("(&(lang=*)(country=US))") 
                   Service<MyService> service;
Services injection - filters
@Publish
@Lang(EN) @Country(US)
public class MyServiceImpl implements MyService {
    ...
}


@Inject @Filter("(&(lang=*)(country=US))") 
                   Service<MyService> service;


@Inject @OSGiService @Lang(EN) @Country(US) MyService service;
Services injection - filters
@Publish
@Lang(EN) @Country(US)
public class MyServiceImpl implements MyService {
    ...
}


@Inject @Filter("(&(lang=*)(country=US))") 
                   Service<MyService> service;


@Inject @Lang(EN) @Country(US) Service<MyService> service;
Required services


•When you absolutely need specific service(s) at runtime
•Weld-OSGi tell you when required services are
 available
 •can work in an atomic fashion for the whole bundle
 •can target specific types of services
Required services
      @Inject @OSGiService
              Bean A
      @Required
      MyService service;
                                   public void start(
                                       @Observes Valid
required service                   evt) {}  Bean B
  registration                     public void stop(


                                dependencies validation events
       Weld-OSGi service
            registry
                     listener

                             OSGi service                       services
                               registry              registrations/unregistrations
Required services
@Inject @OSGiService @Required MyService service;
@Inject @OSGiService @Required MyBean bean;

public void start(@Observes Valid evt) {
    System.out.println("services are available");
    service.doSomething();
}

public void stop(@Observes Invalid evt) {
    System.out.println("services are unavailable");
}
Required services
@Inject @Required Service<MyService> service;
@Inject @Required Service<MyBean> bean;

public void start(@Observes Valid evt) {
    System.out.println("services are available");
    service.get().doSomething();
}

public void stop(@Observes Invalid evt) {
    System.out.println("services are unavailable");
}
Required services
                               le
                              d
@Inject @Required Service<MyService> service;


                             n
@Inject @Required Service<MyBean> bean;




                       b   u
public void start(@Observes Valid evt) {
    System.out.println("services are available");



      le
    service.get().doSomething();
}



   ho
public void stop(@Observes Invalid evt) {


 w
    System.out.println("services are unavailable");
}
Required services
@Inject @OSGiService @Required MyService service;

public void start(@Observes @Specification(MyService.class)
                                     ServiceAvailable evt) {
    System.out.println("service is available");
    service.doSomething();
}

public void stop(@Observes @Specification(MyService.class)
                                   ServiceUnavailable evt) {
    System.out.println("service is unavailable");
}
Required services
@Inject @Required Service<MyService> service;

public void start(@Observes @Specification(MyService.class)
                                      ServiceAvailable evt) {
    System.out.println("service is available");
    service.get().doSomething();
}

public void stop(@Observes @Specification(MyService.class)
                                   ServiceUnavailable evt) {
    System.out.println("service is unavailable");
}
OSGi events API
•OSGi generates a lot of events to let you interact with
 bundle and service layers
•Easier to handle dynamism with
 •bundle events
 •service events
OSGi events - Bundles
                                                             update
•Available events                                            refresh
                                            install
 •BundleInstalled
 •BundleResolved                            Installed                      Starting
 •BundleStarting                  resolve
                                                        update     start
                                                        refresh




                      uninstall
 •BundleStarted                                                             Active
                                            Resolved
 •BundleStopping                                                                 stop
                                      uninstall
 •BundleStopped                                                            Stopping
 •BundleUninstalled                    Uninstalled
 •BundleUpdated
 •BundleUnresolved
OSGi events - Bundles



public void bindBundle(@Observes BundleInstalled evt) {}
OSGi events - Bundles



public void bindBundle(@Observes @BundleVersion("1.2.3")
                                        BundleInstalled evt) {}
OSGi events - Bundles



public void bindBundle(@Observes @BundleName("com.foo.bar")
                                        BundleInstalled evt) {}
OSGi events - Bundles



public void bindBundle(@Observes @BundleName("com.foo.bar")
                @BundleVersion("1.2.3") BundleInstalled evt) {}
OSGi events - Services

•Available events
 •ServiceArrival
 •ServiceDeparture
 •ServiceChanged
OSGi events - Services

   •Available events
    •ServiceArrival
    •ServiceDeparture
    •ServiceChanged

void bindService(@Observes ServiceArrival evt) {}
OSGi events - Services

   •Available events
    •ServiceArrival
    •ServiceDeparture
    •ServiceChanged

void bindService(@Observes @Filter("(lang=US)") ServiceArrival evt) {}
OSGi events - Services

   •Available events
    •ServiceArrival
    •ServiceDeparture
    •ServiceChanged

void bindService(@Observes @Specification(MyService.class)
                                             ServiceArrival evt) {}
OSGi events - Services

   •Available events
    •ServiceArrival
    •ServiceDeparture
    •ServiceChanged

void bindService(@Observes @Specification(MyService.class)
                        @Filter("(lang=US)") ServiceArrival evt) {}
Inter-bundles events
•Communication between bundles (managed by Weld-
 OSGi) with standard CDI events

                                     Bundle B
                       broadcast()


                                        broadcast()
                       Weld-OSGi                      Bundle C
               fire()




    Bundle A
Inter-bundles events
@Inject Event<InterBundleEvent> event;
event.fire(new InterBundleEvent("Hello bundles"));
Inter-bundles events
@Inject Event<InterBundleEvent> event;
event.fire(new InterBundleEvent("Hello bundles"));
Inter-bundles events
@Inject Event<InterBundleEvent> event;
event.fire(new InterBundleEvent("Hello bundles"));



public void listen(@Observes InterBundleEvent event) {}
Inter-bundles events
@Inject Event<InterBundleEvent> event;
event.fire(new InterBundleEvent("Hello bundles"));



public void listen(@Observes @Sent InterBundleEvent event) {}
Inter-bundles events
@Inject Event<InterBundleEvent> event;
event.fire(new InterBundleEvent("Hello bundles"));



public void listen(@Observes @Specification(String.class)
                                    InterBundleEvent event) {}
Inter-bundles events
@Inject Event<InterBundleEvent> event;
event.fire(new InterBundleEvent("Hello bundles"));



public void listen(@Observes @Specification(String.class)
                              @Sent InterBundleEvent event) {}
Getting started !
•Get Weld-OSGi =>
•Write an OSGi bundle
 •Maven module + maven-bundle-plugin
 •bnd file for manifest customization
•Empty beans.xml file in META-INF
   <dependency>
       <groupId>org.jboss.weld.osgi</groupId>
       <artifactId>weld-osgi-core-api</artifactId>
       <version>1.1.3-SNAPSHOT</version>
   </dependency>   
   <dependency>
       <groupId>javax.enterprise</groupId>
       <artifactId>cdi-api</artifactId>
       <version>1.0-SP4</version>
   </dependency>
Pros and cons
•Pros
 •CDI programming model
 •really simplify OSGi (service layer)
   •don’t hide it though
 •fully compatible with existing OSGi bundles
   •mixed app (legacy, weld-osgi)
 •one Weld container per bundle
•Cons
 •one Weld container per bundle
 •new API to learn
Back to the future !

•Integration in Weld core (in progress)
•Forge plugin
 •integration with Weld-OSGi features
 •simplifying OSGi tests (arquillian OSGi)
 •generation of sample OSGi containers
•CDI Extension for hybrid Java EE app servers
 •using Weld-OSGi in Java EE apps
 •work in progress ;-)
•Integration with OSGi enterprise specs
Demo
Murphy’s law in action
Demo : the story
•Hotel booking webapp
 •business partners with hotels
•Avoid redeploying the app
 •when new partner is added
 •using OSGi dynamism
•Provide an API to partners
 •Hotel POJO
 •HotelProvider service contract
 •partners will provide an OSGi bundle to deal with
  their booking system
Conclusion

•Weld-OSGi is cool
 •let’s try it :-)
•Can help to change OSGi in people minds
•Enlarge CDI action scope
 •it’s not only about Java EE
•Don’t hesitate to give us feedback and fill issues
Questions?

More Related Content

What's hot

The Web on OSGi: Here's How
The Web on OSGi: Here's HowThe Web on OSGi: Here's How
The Web on OSGi: Here's How
mrdon
 
Benefits of OSGi in Practise
Benefits of OSGi in PractiseBenefits of OSGi in Practise
Benefits of OSGi in Practise
David Bosschaert
 
OSGi Presentation
OSGi PresentationOSGi Presentation
OSGi Presentation
Michal Malohlava
 
Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)
Peter R. Egli
 
OSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 IndiaOSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 India
Arun Gupta
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
Stephan Janssen
 
HowTo Build an OSGI EJB3 Server
HowTo Build an OSGI EJB3 ServerHowTo Build an OSGI EJB3 Server
HowTo Build an OSGI EJB3 Server
ekkehard gentz
 
Modular EJBs in OSGi - Tim Ward
Modular EJBs in OSGi - Tim WardModular EJBs in OSGi - Tim Ward
Modular EJBs in OSGi - Tim Ward
mfrancis
 
OSGi in 5 minutes
OSGi in 5 minutesOSGi in 5 minutes
OSGi in 5 minutes
Serge Huber
 
Spring - CDI Interop
Spring - CDI InteropSpring - CDI Interop
Spring - CDI Interop
Ray Ploski
 
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDIMigrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI
Mario-Leander Reimer
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
Antoine Sabot-Durand
 
Karaf ee-apachecon eu-2012
Karaf ee-apachecon eu-2012Karaf ee-apachecon eu-2012
Karaf ee-apachecon eu-2012
Charles Moulliard
 
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Peter Pilgrim
 
Intro to OSGi
Intro to OSGiIntro to OSGi
Intro to OSGi
Tricode (part of Dept)
 
Android MvRx Framework 介紹
Android MvRx Framework 介紹Android MvRx Framework 介紹
Android MvRx Framework 介紹
Kros Huang
 
Travelling Light for the Long Haul - Ian Robinson
Travelling Light for the Long Haul -  Ian RobinsonTravelling Light for the Long Haul -  Ian Robinson
Travelling Light for the Long Haul - Ian Robinson
mfrancis
 
Epoxy 介紹
Epoxy 介紹Epoxy 介紹
Epoxy 介紹
Kros Huang
 

What's hot (20)

The Web on OSGi: Here's How
The Web on OSGi: Here's HowThe Web on OSGi: Here's How
The Web on OSGi: Here's How
 
Benefits of OSGi in Practise
Benefits of OSGi in PractiseBenefits of OSGi in Practise
Benefits of OSGi in Practise
 
OSGi Presentation
OSGi PresentationOSGi Presentation
OSGi Presentation
 
OSGi Blueprint Services
OSGi Blueprint ServicesOSGi Blueprint Services
OSGi Blueprint Services
 
Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)
 
Polyglot OSGi
Polyglot OSGiPolyglot OSGi
Polyglot OSGi
 
OSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 IndiaOSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 India
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
 
HowTo Build an OSGI EJB3 Server
HowTo Build an OSGI EJB3 ServerHowTo Build an OSGI EJB3 Server
HowTo Build an OSGI EJB3 Server
 
Modular EJBs in OSGi - Tim Ward
Modular EJBs in OSGi - Tim WardModular EJBs in OSGi - Tim Ward
Modular EJBs in OSGi - Tim Ward
 
OSGi in 5 minutes
OSGi in 5 minutesOSGi in 5 minutes
OSGi in 5 minutes
 
Spring - CDI Interop
Spring - CDI InteropSpring - CDI Interop
Spring - CDI Interop
 
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDIMigrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
Karaf ee-apachecon eu-2012
Karaf ee-apachecon eu-2012Karaf ee-apachecon eu-2012
Karaf ee-apachecon eu-2012
 
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
 
Intro to OSGi
Intro to OSGiIntro to OSGi
Intro to OSGi
 
Android MvRx Framework 介紹
Android MvRx Framework 介紹Android MvRx Framework 介紹
Android MvRx Framework 介紹
 
Travelling Light for the Long Haul - Ian Robinson
Travelling Light for the Long Haul -  Ian RobinsonTravelling Light for the Long Haul -  Ian Robinson
Travelling Light for the Long Haul - Ian Robinson
 
Epoxy 介紹
Epoxy 介紹Epoxy 介紹
Epoxy 介紹
 

Similar to Weld-OSGi, injecting easiness in OSGi

OSGi DevCon 2009 Review
OSGi DevCon 2009 ReviewOSGi DevCon 2009 Review
OSGi DevCon 2009 Review
njbartlett
 
Beyond OSGi Software Architecture
Beyond OSGi Software ArchitectureBeyond OSGi Software Architecture
Beyond OSGi Software Architecture
Jeroen van Grondelle
 
Hybrid Applications
Hybrid ApplicationsHybrid Applications
Hybrid Applications
Andreas Enbohm
 
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OpenBlend society
 
Osgi
OsgiOsgi
OSGi In Anger - Tara Simpson
OSGi In Anger - Tara SimpsonOSGi In Anger - Tara Simpson
OSGi In Anger - Tara Simpsonmfrancis
 
Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM
ICF CIRCUIT
 
RESTful Services and Distributed OSGi - 04/2009
RESTful Services and Distributed OSGi - 04/2009RESTful Services and Distributed OSGi - 04/2009
RESTful Services and Distributed OSGi - 04/2009
Roland Tritsch
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0
Michael Vorburger
 
AngularJSTO presentation
AngularJSTO presentationAngularJSTO presentation
AngularJSTO presentationAlan Hietala
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 
Process Matters (Cloud2Days / Java2Days conference))
Process Matters (Cloud2Days / Java2Days conference))Process Matters (Cloud2Days / Java2Days conference))
Process Matters (Cloud2Days / Java2Days conference))
dev2ops
 
OSGi User Forum US DC Metro
OSGi User Forum US DC MetroOSGi User Forum US DC Metro
OSGi User Forum US DC Metro
pjhInovex
 
OSGi user forum dc metro v1
OSGi user forum dc metro v1OSGi user forum dc metro v1
OSGi user forum dc metro v1pjhInovex
 
AWS CodeDeploy
AWS CodeDeployAWS CodeDeploy
AWS CodeDeploy
TO THE NEW | Technology
 
OSGi enRoute Unveiled - P Kriens
OSGi enRoute Unveiled - P KriensOSGi enRoute Unveiled - P Kriens
OSGi enRoute Unveiled - P Kriens
mfrancis
 
Developing Azure Functions for Flow and Nintex SPS SD 2018
Developing Azure Functions for Flow and Nintex SPS SD 2018Developing Azure Functions for Flow and Nintex SPS SD 2018
Developing Azure Functions for Flow and Nintex SPS SD 2018
DocFluix, LLC
 
Developing Azure Functions as custom connectors for Flow and Nintex
Developing Azure Functions as custom connectors for Flow and NintexDeveloping Azure Functions as custom connectors for Flow and Nintex
Developing Azure Functions as custom connectors for Flow and Nintex
DocFluix, LLC
 
Eclipse the Rich Client Platform - Jeff McAffer, Eclipse Architect, IBM
Eclipse the Rich Client Platform - Jeff McAffer, Eclipse Architect, IBMEclipse the Rich Client Platform - Jeff McAffer, Eclipse Architect, IBM
Eclipse the Rich Client Platform - Jeff McAffer, Eclipse Architect, IBM
mfrancis
 

Similar to Weld-OSGi, injecting easiness in OSGi (20)

OSGi DevCon 2009 Review
OSGi DevCon 2009 ReviewOSGi DevCon 2009 Review
OSGi DevCon 2009 Review
 
Beyond OSGi Software Architecture
Beyond OSGi Software ArchitectureBeyond OSGi Software Architecture
Beyond OSGi Software Architecture
 
Hybrid Applications
Hybrid ApplicationsHybrid Applications
Hybrid Applications
 
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
 
Osgi
OsgiOsgi
Osgi
 
OSGi In Anger - Tara Simpson
OSGi In Anger - Tara SimpsonOSGi In Anger - Tara Simpson
OSGi In Anger - Tara Simpson
 
Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM
 
RESTful Services and Distributed OSGi - 04/2009
RESTful Services and Distributed OSGi - 04/2009RESTful Services and Distributed OSGi - 04/2009
RESTful Services and Distributed OSGi - 04/2009
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0
 
AngularJSTO presentation
AngularJSTO presentationAngularJSTO presentation
AngularJSTO presentation
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Process Matters (Cloud2Days / Java2Days conference))
Process Matters (Cloud2Days / Java2Days conference))Process Matters (Cloud2Days / Java2Days conference))
Process Matters (Cloud2Days / Java2Days conference))
 
OSGi User Forum US DC Metro
OSGi User Forum US DC MetroOSGi User Forum US DC Metro
OSGi User Forum US DC Metro
 
OSGi user forum dc metro v1
OSGi user forum dc metro v1OSGi user forum dc metro v1
OSGi user forum dc metro v1
 
AWS CodeDeploy
AWS CodeDeployAWS CodeDeploy
AWS CodeDeploy
 
OSGi enRoute Unveiled - P Kriens
OSGi enRoute Unveiled - P KriensOSGi enRoute Unveiled - P Kriens
OSGi enRoute Unveiled - P Kriens
 
Developing Azure Functions for Flow and Nintex SPS SD 2018
Developing Azure Functions for Flow and Nintex SPS SD 2018Developing Azure Functions for Flow and Nintex SPS SD 2018
Developing Azure Functions for Flow and Nintex SPS SD 2018
 
OSGi
OSGiOSGi
OSGi
 
Developing Azure Functions as custom connectors for Flow and Nintex
Developing Azure Functions as custom connectors for Flow and NintexDeveloping Azure Functions as custom connectors for Flow and Nintex
Developing Azure Functions as custom connectors for Flow and Nintex
 
Eclipse the Rich Client Platform - Jeff McAffer, Eclipse Architect, IBM
Eclipse the Rich Client Platform - Jeff McAffer, Eclipse Architect, IBMEclipse the Rich Client Platform - Jeff McAffer, Eclipse Architect, IBM
Eclipse the Rich Client Platform - Jeff McAffer, Eclipse Architect, IBM
 

Recently uploaded

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 

Weld-OSGi, injecting easiness in OSGi

  • 1.
  • 3. Mathieu ANCELIN •Software engineer @SERLI •Java & OSS guy •JOnAS, GlassFish, Weld, etc ... •Poitou-Charentes JUG crew member •CDI 1.1 (JSR-346) expert group member •What else? •@TrevorReznik
  • 4. A few words about SERLI •Software engineering company based in France •65 people •80% of the business is Java-related •Small company working for big ones •OSS contribution : 10% of workforce •www.serli.com @SerliFr
  • 6. Agenda •CDI, the best part of Java EE 6 •OSGi, deep dive into modularity and dynamism •Meet Weld-OSGi •How does it work? •Features and programming model •Pros and cons •Back to the future •Demo •Conclusion
  • 7. CDI
  • 8. CDI @Any @ApplicationScoped @Model @Default @Inject @Observes @Dispose @SessionScoped @Named @RequestScoped @Produces @Typed @Singleton @Stereotype @Qualifier @Scope @New
  • 9. CDI @Any @ApplicationScoped @Model @Default @Inject @Observes @Dispose @SessionScoped @Named @RequestScoped @Produces @Typed @Singleton @Stereotype @Qualifier @Scope @New
  • 10. CDI •The best part of Java EE 6 (coolest) •#annotationsEverywhere •Basically there is no limite of what you can do •if you can think about it, you can do it •standard extensions :-) •JBoss Weld is the reference implementation •pretty mature, good community •Limited to Java EE 6? •well, not necessarily ...
  • 11. Environnements for CDI/Weld •You can boostrap Weld very easily outside Java EE environment •You can bootstrap it anywhere :-) •For instance •Weld-Servlet •Jetty •Tomcat 6/7 •Weld-SE •Good old Desktop Java apps. •You name it ?
  • 12. OSGi •An amazing modular and dynamic platform for Java •Very stable and powerful but old APIs Bundles Service Lifecycle Module Java environment
  • 13. Modules / Bundles Bundle-SymbolicName: com.sample.app Bundle-SymbolicName: com.foo.bar manifest manifest Export-Package: com.sample.app.api; version=1.2.0 Import-Package: com.sample.app.api; version=[1.2.0-2.0.0)
  • 14. Lifecycle update refresh install Installed Starting update start resolve refresh uninstall Active Resolved stop uninstall Stopping Uninstalled
  • 15. Services notify listener register OSGI lookup Bundle A service Bundle B registry
  • 16. Weld-OSGi •(try to be) the best of both worlds •dynamic, typesafe, annotations, etc ... •CDI extension to use CDI programming model inside OSGi •A JBoss Weld project •need to bootstrap Weld in an OSGi environment •Developed by SERLI R&D team •Mathieu & Matthieu •You don’t need to know OSGi •make the OSGi programming model disappear in favor of standard CDI •but still compatible
  • 17. How does it work ?
  • 18. Features •Use Weld/CDI inside OSGi environment •OSGi injection utilities •Dynamic services publication •Dynamic services injection •Integration with OSGi events API •Inter-bundles events
  • 19. Using Weld / CDI in OSGi •Install a bundle with META-INF/beans.xml file •If you don’t need automatic startup •Specify that Weld-OSGi must not handle the bundle •entry in the bundle manifest : Embedded- CDIContainer: true •Specification of an embedded mode in CDI 1.1 •Special Weld-OSGi events public void start(@Observes BundleContainerInitialized event) {} public void stop(@Observes BundleContainerShutdown event) {}
  • 20. Embedding CDI EmbeddedCDIContainer cdi =  new EmbeddedContainer(bundleContext).initialize(); MyService service =  cdi.instance().select(MyService.class).get(); service.doSomething(); cdi.stop(); or WeldContainer weld =  new WeldContainer(bundleContext).initialize(); MyService service = weld.instance().select(MyService.class).get(); service.doSomething(); weld.stop();
  • 21. OSGi injection utilities •Easier access to OSGi APIs (if needed) •Injection of the current bundle •Injection of the current bundleContext •Injection of the current metadata •Injection bundle files (inside OSGi container) •Other utilities are added while moving forward
  • 22. OSGi injection utilities •Easier access to OSGi APIs (if needed) •Injection of the current bundle •Injection of the current bundleContext •Injection of the current metadata •Injection bundle files (inside OSGi container) •Other utilities are added while moving forward  @Inject Bundle bundle;  @Inject BundleContext context;  @Inject @BundleHeaders Map<String, String> headers;  @Inject @BundleHeader("Bundle-SymbolicName") String symbolicName;  @Inject @BundleDataFile("text.txt") File text;
  • 24. Services publication •Declarative publication @Publish @ApplicationScoped @Lang(EN) public class MyServiceImpl implements MyService {     ... }
  • 25. Services publication •Declarative publication @Publish @ApplicationScoped @Lang(EN) public class MyServiceImpl implements MyService {     ... } •Dynamic publication @Inject Instance<MyService> instance; @Inject ServiceRegistry registry; MyService service = instance.get(); Registration<MyService> reg = registry.register(service); ... reg.unregister();
  • 27. Services injection •Dynamic injection @Inject @OSGiService MyService service; service.doSomething(); // fail if no services available
  • 28. Services injection •Dynamic injection @Inject @OSGiService MyService service; service.doSomething(); // fail if no services available P get() create() R @Inject @OSGiService MyService service; O Provider InjectionPoint X Y
  • 29. Services injection service.doSomething() get() P R O doSomething() OSGi X actual service service Y registry unget()
  • 30. Services injection •Programmatic injection - whiteboard pattern (like Instance<T>) @Inject Service<MyService> service; for (MyService actualService : service.first()) {     actualService.doSomething(); // called on 0-1 service } for (MyService actualService : service) {     actualService.doSomething(); // called on 0-n service(s) } service.get().doSomething(); // can fail, not dynamic service.size(); service.isUnsatisfied(); service.isAmbiguous();
  • 31. Services injection - filters @Publish @Lang(EN) @Country(US) public class MyServiceImpl implements MyService {     ... }
  • 32. Services injection - filters @Publish @Lang(EN) @Country(US) public class MyServiceImpl implements MyService {     ... } @Inject @OSGiService  @Filter("(&(lang=*)(country=US))") MyService service;
  • 33. Services injection - filters @Publish @Lang(EN) @Country(US) public class MyServiceImpl implements MyService {     ... } @Inject @Filter("(&(lang=*)(country=US))")  Service<MyService> service;
  • 34. Services injection - filters @Publish @Lang(EN) @Country(US) public class MyServiceImpl implements MyService {     ... } @Inject @Filter("(&(lang=*)(country=US))")  Service<MyService> service; @Inject @OSGiService @Lang(EN) @Country(US) MyService service;
  • 35. Services injection - filters @Publish @Lang(EN) @Country(US) public class MyServiceImpl implements MyService {     ... } @Inject @Filter("(&(lang=*)(country=US))")  Service<MyService> service; @Inject @Lang(EN) @Country(US) Service<MyService> service;
  • 36. Required services •When you absolutely need specific service(s) at runtime •Weld-OSGi tell you when required services are available •can work in an atomic fashion for the whole bundle •can target specific types of services
  • 37. Required services @Inject @OSGiService Bean A @Required MyService service; public void start( @Observes Valid required service evt) {} Bean B registration public void stop( dependencies validation events Weld-OSGi service registry listener OSGi service services registry registrations/unregistrations
  • 38. Required services @Inject @OSGiService @Required MyService service; @Inject @OSGiService @Required MyBean bean; public void start(@Observes Valid evt) {     System.out.println("services are available");     service.doSomething(); } public void stop(@Observes Invalid evt) {     System.out.println("services are unavailable"); }
  • 39. Required services @Inject @Required Service<MyService> service; @Inject @Required Service<MyBean> bean; public void start(@Observes Valid evt) {     System.out.println("services are available");     service.get().doSomething(); } public void stop(@Observes Invalid evt) {     System.out.println("services are unavailable"); }
  • 40. Required services le d @Inject @Required Service<MyService> service; n @Inject @Required Service<MyBean> bean; b u public void start(@Observes Valid evt) {     System.out.println("services are available"); le     service.get().doSomething(); } ho public void stop(@Observes Invalid evt) { w     System.out.println("services are unavailable"); }
  • 41. Required services @Inject @OSGiService @Required MyService service; public void start(@Observes @Specification(MyService.class) ServiceAvailable evt) {     System.out.println("service is available");     service.doSomething(); } public void stop(@Observes @Specification(MyService.class) ServiceUnavailable evt) {     System.out.println("service is unavailable"); }
  • 42. Required services @Inject @Required Service<MyService> service; public void start(@Observes @Specification(MyService.class) ServiceAvailable evt) {     System.out.println("service is available");     service.get().doSomething(); } public void stop(@Observes @Specification(MyService.class) ServiceUnavailable evt) {     System.out.println("service is unavailable"); }
  • 43. OSGi events API •OSGi generates a lot of events to let you interact with bundle and service layers •Easier to handle dynamism with •bundle events •service events
  • 44. OSGi events - Bundles update •Available events refresh install •BundleInstalled •BundleResolved Installed Starting •BundleStarting resolve update start refresh uninstall •BundleStarted Active Resolved •BundleStopping stop uninstall •BundleStopped Stopping •BundleUninstalled Uninstalled •BundleUpdated •BundleUnresolved
  • 45. OSGi events - Bundles public void bindBundle(@Observes BundleInstalled evt) {}
  • 46. OSGi events - Bundles public void bindBundle(@Observes @BundleVersion("1.2.3") BundleInstalled evt) {}
  • 47. OSGi events - Bundles public void bindBundle(@Observes @BundleName("com.foo.bar") BundleInstalled evt) {}
  • 48. OSGi events - Bundles public void bindBundle(@Observes @BundleName("com.foo.bar") @BundleVersion("1.2.3") BundleInstalled evt) {}
  • 49. OSGi events - Services •Available events •ServiceArrival •ServiceDeparture •ServiceChanged
  • 50. OSGi events - Services •Available events •ServiceArrival •ServiceDeparture •ServiceChanged void bindService(@Observes ServiceArrival evt) {}
  • 51. OSGi events - Services •Available events •ServiceArrival •ServiceDeparture •ServiceChanged void bindService(@Observes @Filter("(lang=US)") ServiceArrival evt) {}
  • 52. OSGi events - Services •Available events •ServiceArrival •ServiceDeparture •ServiceChanged void bindService(@Observes @Specification(MyService.class) ServiceArrival evt) {}
  • 53. OSGi events - Services •Available events •ServiceArrival •ServiceDeparture •ServiceChanged void bindService(@Observes @Specification(MyService.class) @Filter("(lang=US)") ServiceArrival evt) {}
  • 54. Inter-bundles events •Communication between bundles (managed by Weld- OSGi) with standard CDI events Bundle B broadcast() broadcast() Weld-OSGi Bundle C fire() Bundle A
  • 55. Inter-bundles events @Inject Event<InterBundleEvent> event; event.fire(new InterBundleEvent("Hello bundles"));
  • 56. Inter-bundles events @Inject Event<InterBundleEvent> event; event.fire(new InterBundleEvent("Hello bundles"));
  • 57. Inter-bundles events @Inject Event<InterBundleEvent> event; event.fire(new InterBundleEvent("Hello bundles")); public void listen(@Observes InterBundleEvent event) {}
  • 58. Inter-bundles events @Inject Event<InterBundleEvent> event; event.fire(new InterBundleEvent("Hello bundles")); public void listen(@Observes @Sent InterBundleEvent event) {}
  • 59. Inter-bundles events @Inject Event<InterBundleEvent> event; event.fire(new InterBundleEvent("Hello bundles")); public void listen(@Observes @Specification(String.class) InterBundleEvent event) {}
  • 60. Inter-bundles events @Inject Event<InterBundleEvent> event; event.fire(new InterBundleEvent("Hello bundles")); public void listen(@Observes @Specification(String.class) @Sent InterBundleEvent event) {}
  • 61. Getting started ! •Get Weld-OSGi => •Write an OSGi bundle •Maven module + maven-bundle-plugin •bnd file for manifest customization •Empty beans.xml file in META-INF <dependency> <groupId>org.jboss.weld.osgi</groupId>     <artifactId>weld-osgi-core-api</artifactId>     <version>1.1.3-SNAPSHOT</version> </dependency>    <dependency>     <groupId>javax.enterprise</groupId>     <artifactId>cdi-api</artifactId>     <version>1.0-SP4</version> </dependency>
  • 62. Pros and cons •Pros •CDI programming model •really simplify OSGi (service layer) •don’t hide it though •fully compatible with existing OSGi bundles •mixed app (legacy, weld-osgi) •one Weld container per bundle •Cons •one Weld container per bundle •new API to learn
  • 63. Back to the future ! •Integration in Weld core (in progress) •Forge plugin •integration with Weld-OSGi features •simplifying OSGi tests (arquillian OSGi) •generation of sample OSGi containers •CDI Extension for hybrid Java EE app servers •using Weld-OSGi in Java EE apps •work in progress ;-) •Integration with OSGi enterprise specs
  • 65. Demo : the story •Hotel booking webapp •business partners with hotels •Avoid redeploying the app •when new partner is added •using OSGi dynamism •Provide an API to partners •Hotel POJO •HotelProvider service contract •partners will provide an OSGi bundle to deal with their booking system
  • 66. Conclusion •Weld-OSGi is cool •let’s try it :-) •Can help to change OSGi in people minds •Enlarge CDI action scope •it’s not only about Java EE •Don’t hesitate to give us feedback and fill issues