Your SlideShare is downloading. ×
Getting modular with OSGI
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Getting modular with OSGI

530
views

Published on

The presentation was shared on Lviv JUG meeting #21

The presentation was shared on Lviv JUG meeting #21

Published in: Technology, Education

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
530
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • permits = friendly modules list (current module is accessible only for those)class = entry class
  • Framework API:org.osgi.framework packageBundle Wiring API: for wiring bundles (requirements and capabilities), classes BundleRevision, BundleWiring, FrameworkWiringStart Level API:describes how to enable a management agent to control the relative starting and stopping order of bundles in an OSGi Service Platform (setting start level, in Karafosgi:bundle-level, osgi:start-level).Remote Services: setup of remote access for the services
  • Class loading: “uses” marks packages that exported API use (method signatures, parent classes), so the framework can check if those don’t conflict with imported packagesif java.* => parentif in Import-Package => exportersearch in Require-Bundlesearch in Bundle-ClassPathif in DynamicImport-Package => wiring
  • Web-ContextPath: OSGI 4.2 specWebapp-Context: PAX Web specific
  • Device Access specification supports the coordination of automatic detection and attachment ofexisting devices on an OSGi Service Platform, facilitates hot-plugging and -unplugging of newdevices, and downloads and installs device drivers on demand.Preferences = system or user-specific data storageUser Admin = authentication/authorizationMonitor Admin = status variables get/set/reset from administrative bundles
  • Management tools: configuration (property files), logging, security, etc
  • Transcript

    • 1. GETTING MODULARWITH OSGI
    • 2. Agenda› How to make my Java more modular› Discover and exploit OSGI› Tools, tools, tools…› Output
    • 3. About meWho: Andrii KrokhmalnyiDomain: Java/Java EECompany: EPAM SystemsExperience in OSGI: about 2 years
    • 4. Modular design› Separates functionality into distinct isolated sections (modules)› Defines a standard interface for modules› Adds ability to replace modules transparently for users of the system› Improves scalability and robustness of the system› Makes functional parts of the system reusable and easily updatable› …But adds some extent of complexity in overall system orchestration
    • 5. Modularity in Java: Service Provider InterfaceMETA-INF/services/com.foo.logging.LogRenderercom.foo.logging.impl.ConsoleLogRenderercom.foo.service.MyService.javapublic static void main(String[] args) {ServiceLoader<LogRenderer> renderers =ServiceLoader.load(LogRenderer.class);for (LogRenderer renderer : renderers) {...}
    • 6. Modularity in Java: OSGIMANIFEST.MFMETA-INF/MANIFEST.MFManifest-Version: 1.0Bundle-SymbolicName: foo-serviceBundle-Activator: com.foo.service.ActivatorExport-Package: com.foo.dao,com.foo.domain,com.foo.serviceImport-Package: com.foo.logging;version="[2.0,3)"image from http://wallpapersus.com/
    • 7. Project Jigsawsrc/main/java/com/foo/service/module-info.javamodule foo-service @ 1.2 {requires jdk.base;requires optional jdk.jaxp;exports com.foo.bar;permits foo-ui;permits foo-console;class com.foo.service.Main;view dao {exports com.foo.dao;}}image from http://wallpapersgroup.net/
    • 8. History & versioning
    • 9. OSGI specification (version 4.3)Framework SpecificationFrameworkAPIStart LevelAPIRemoteServicesBundleWiringAPIAdditionalServicesSpecificationsSecurity LayerModule LayerLife Cycle LayerService Layer
    • 10. Core :: Container and bundlesimage from http://www.osgi.orgOSGI ContainerClass Loader #1Bundle #1Class Loader #2Bundle #2Class Loader #NBundle #N(modules)a regular jar archive with tweaked manifest
    • 11. Core :: Bundles life-cycle
    • 12. Core :: MANIFEST.MF headersfoo-service.jar/META-INF/MANIFEST.MF...Bundle-ManifestVersion: 2Bundle-SymbolicName: com.foo.serviceBundle-Name: Foo ServiceBundle-Description: Foo Service ModuleBundle-Version: 1.0Bundle-Activator: com.foo.service.BundleActivatorRequire-Bundle: com.foo.loggingExport-Package: com.foo.domain,com.foo.dao,com.foo.service;uses:=“org.apache.log4j”Import-Package: com.foo.logging;version=“[1.0,2)”,org.apache.log4j;version=“[2.0,3)”DynamicImport-Package: *...
    • 13. Core :: MANIFEST.MF and Mavenpom.xml<build><plugins><plugin><groupId>org.apache.felix</groupId><artifactId>maven-bundle-plugin</artifactId><configuration><instructions><Bundle-Activator>com.foo.service.BundleActivator</Bundle-Activator><Export-Package>com.foo.service</Export-Package><Import-Package>com.foo.domain,com.foo.dao,*</Import-Package><DynamicImport-Package>*</DynamicImport-Package><Require-Bundle>org.apache.commons.io</Require-Bundle></instructions></configuration></plugin></plugins></build>
    • 14. OSGI Services :: Service producerServiceProducerBundleActivator.javapublic class ServiceProducerBundleActivator implements BundleActivator {private ServiceRegistration registration;public void start(BundleContext context) throws Exception {registration = context.registerService(CustomService.class.getName(),new CustomServiceImpl(), null);}public void stop(BundleContext context) throws Exception {registration.unregister();}}
    • 15. OSGI Services :: Service consumerServiceConsumerBundleActivator.javapublic class ServiceConsumerBundleActivator implements BundleActivator {public void start(BundleContext context) throws Exception {ServiceReference ref =context.getServiceReference(CustomService.class.getName());CustomService customService = (CustomService) context.getService(ref);customService.customMethod();...}}
    • 16. OSGI Services :: Spring version/META-INF/spring/spring-osgi.xml<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="..."xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="..."><osgi:service ref="customService" interface="com.foo.service.CustomService"/></beans>Producer/META-INF/spring/spring-osgi.xml<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="..."xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="..."><osgi:reference id="customService" interface="com.foo.service.CustomService"/></beans>Consumer
    • 17. WhereWAR becomesWABfoo-web.war/META-INF/MANIFEST.MF...Bundle-ManifestVersion: 2Bundle-SymbolicName: com.foo.webBundle-Version: 1.0Bundle-Activator: com.foo.web.BundleActivatorWeb-ContextPath: mainapp/fooWebapp-Context: mainapp/fooBundle-ClassPath: WEB-INF/classes,.Import-Package: com.foo.service;version=“[1.0,2)”,com.foo.logging;version=“[1.0,2)”;resolution:="optional"...
    • 18. Compendium servicesCompendiumOSGI ServicesPreferences UserAdmin Monitor AdminLog HTTPDeviceAccessConfigurationAdmin… and many more
    • 19. OSGI and unit testingSpringDMMockBundleMockBundleContextMockServiceRegistrationMockServiceReferenceMockBundleActivator
    • 20. OSGI and integration testingCustomServiceIntegrationTest.java@RunWith(PaxExam.class)@ExamReactorStrategy(PerMethod.class)public class CustomServiceIntegrationTest {@InjectCustomService customService;@Configurationpublic Option[] config() {return options(mavenBundle("com.foo", "foo-service", "1.0"), junitBundles());}}
    • 21. BNDimage from http://freemarket.kiev.ua/CompiledclassesInstructionfileOSGIbundle
    • 22. OSGI containers/frameworksApache Felix36%Equinox37%SpringSourcedm Server8%Knopflerfish8%Concierge8%ProSyst3%OSGI CONTAINERS POPULARITY(BYVOTES AT STACKOVERFLOW.COM)
    • 23. Overview of Apache FelixApache License 2.0OSGI R4.2 compatibleProvides a web consoleProvides a Maven pluginActive developmentProved solutionGood documentation
    • 24. Overview of Apache KarafApache License 2.0Supports both Felix and EquinoxLightweight and extensibleInteractive shell consoleHot deploymentNative OS integrationExtra management toolsActive development
    • 25. OSGI in real world
    • 26. Positives
    • 27. Negatives

    ×