OSGiOSGi Yet another framework?Yet another framework? Jiří Harazim FI MU 2012 22. 11. 2012 Jiri HARAZIM: OSGi 2 AgendaAgenda Introduction Motivation OSGi Framework Demo Conclusion Discussion 22. 11. 2012 Jiri HARAZIM: OSGi 3 AgendaAgenda Introduction Motivation OSGi Framework Demo Conclusion Discussion 22. 11. 2012 Jiri HARAZIM: OSGi 4 IntroductionIntroduction Survey: Who has never heard of OSGi? OSGi = former Open Services Gateway initiative Who are members of this initiative? Adobe Systems, IBM, Oracle, Red Hat, Vmware, Siemens AG, TIBCO, Hitachi, Mitsubischi Electric, Telefonica S.A., Credit Suisse, Eclipse Foundation Inc. and many others 22. 11. 2012 Jiri HARAZIM: OSGi 5 AgendaAgenda Introduction Motivation OSGi Framework Demo Conclusion Discussion 22. 11. 2012 Jiri HARAZIM: OSGi 6 Beyond Java ModularityBeyond Java Modularity Java (1995) is cool, but: Lacks modularity support (jar hell) Hardly follows proved trends (dependency injection, services) Is only a tool actually Thus a bunch of proprietary solutions had emerged (JBoss, NetBeans, servers and others) Why? They address major pitfalls: Different unit of assembly (NetBeans Modules) Services support (Spring, Guice) Runtime/environment support 22. 11. 2012 Jiri HARAZIM: OSGi 7 AgendaAgenda Introduction Motivation OSGi Framework Demo Conclusion Discussion 22. 11. 2012 Jiri HARAZIM: OSGi 8 OSGi FrameworkOSGi Framework OSGi is a specification Defines runtime environment called OSGi Framework Examples: Apache Felix, Equinox, Knopflerfish Runs on top of Java Virtual Machine 22. 11. 2012 Jiri HARAZIM: OSGi 9 ModulesModules Bundle = unit of deployment, ordinary JAR file with META-INF/MANIFEST.MF Example of manifest file: 22. 11. 2012 Jiri HARAZIM: OSGi 10 Life-cycleLife-cycle Each bundle deployed into framework has its own lifecycle Header Bundle-Activator acts as Main-Class Lifecycle scheme: 22. 11. 2012 Jiri HARAZIM: OSGi 11 ServicesServices Service = element of interaction between bundles Binding is performed at runtime In R4 and R5 specs much easier (Declarative Service) 22. 11. 2012 Jiri HARAZIM: OSGi 12 Services and DynamismServices and Dynamism Handling dynamic services is difficult They can apper or leave anytime ServiceTracker was introduced to reduce the burden Event-based approach with listeners Much better but still a lot of effort required IPOJO Service-Oriented component framework, not specification Tackles dynamism as non-functional aspect – much easier! Predecessor of DS Declarative Services Service-Oriented component framework in R4.0 specification 22. 11. 2012 Jiri HARAZIM: OSGi 13 AgendaAgenda Introduction Motivation OSGi Framework Demo Conclusion Discussion 22. 11. 2012 Jiri HARAZIM: OSGi 14 DemoDemo Let's have a look at two bundles: Provider bundle – this one provides service into service registry Client bundle – this one queries registry for the service and uses it We use iPOJO to facilitate development Annotations are translated to manifest-headers by bnd tool We can also specify iPOJO components in XML We launch example in Apache Felix Framework Open Source, felix.apache.org Provider Bundle Client Bundle 22. 11. 2012 Jiri HARAZIM: OSGi 15 AgendaAgenda Introduction Motivation OSGi Framework Demo Conclusion Discussion 22. 11. 2012 Jiri HARAZIM: OSGi 16 ConclusionConclusion OSGi provides solid platform for developing pervasive applications Current release R5 introduces next benefits Provide-Capability header Replacement of OBR (Osgi Bundle Repository) rfc Used heavily in a lot of projects All of us know at least Eclipse and GlassFish Good support of tools Ant, Maven, Eclipse, WebConsole 22. 11. 2012 Jiri HARAZIM: OSGi 17 AgendaAgenda Introduction Motivation OSGi Framework Demo Conclusion Discussion 22. 11. 2012 Jiri HARAZIM: OSGi 18 DiscussionDiscussion Questions? Suggestions? Opinions? 22. 11. 2012 Jiri HARAZIM: OSGi 19 The EndThe End Thank you for your attention!