• Save
Getting modular with OSGI
Upcoming SlideShare
Loading in...5
×
 

Getting modular with OSGI

on

  • 694 views

The presentation was shared on Lviv JUG meeting #21

The presentation was shared on Lviv JUG meeting #21

Statistics

Views

Total Views
694
Views on SlideShare
470
Embed Views
224

Actions

Likes
1
Downloads
0
Comments
0

8 Embeds 224

http://jug-lviv.blogspot.com 208
http://jug-lviv.blogspot.nl 5
http://www.jug-lviv.blogspot.com 3
http://jug-lviv.blogspot.ru 3
http://www.newsblur.com 2
http://jug-lviv.blogspot.de 1
http://jug-lviv.blogspot.hk 1
http://translate.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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

Getting modular with OSGI Getting modular with OSGI Presentation Transcript

  • GETTING MODULARWITH OSGI
  • Agenda› How to make my Java more modular› Discover and exploit OSGI› Tools, tools, tools…› Output
  • About meWho: Andrii KrokhmalnyiDomain: Java/Java EECompany: EPAM SystemsExperience in OSGI: about 2 years View slide
  • 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 View slide
  • 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) {...}
  • 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/
  • 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/
  • History & versioning
  • OSGI specification (version 4.3)Framework SpecificationFrameworkAPIStart LevelAPIRemoteServicesBundleWiringAPIAdditionalServicesSpecificationsSecurity LayerModule LayerLife Cycle LayerService Layer
  • 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
  • Core :: Bundles life-cycle
  • 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: *...
  • 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>
  • 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();}}
  • 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();...}}
  • 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
  • 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"...
  • Compendium servicesCompendiumOSGI ServicesPreferences UserAdmin Monitor AdminLog HTTPDeviceAccessConfigurationAdmin… and many more
  • OSGI and unit testingSpringDMMockBundleMockBundleContextMockServiceRegistrationMockServiceReferenceMockBundleActivator
  • 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());}}
  • BNDimage from http://freemarket.kiev.ua/CompiledclassesInstructionfileOSGIbundle
  • OSGI containers/frameworksApache Felix36%Equinox37%SpringSourcedm Server8%Knopflerfish8%Concierge8%ProSyst3%OSGI CONTAINERS POPULARITY(BYVOTES AT STACKOVERFLOW.COM)
  • Overview of Apache FelixApache License 2.0OSGI R4.2 compatibleProvides a web consoleProvides a Maven pluginActive developmentProved solutionGood documentation
  • Overview of Apache KarafApache License 2.0Supports both Felix and EquinoxLightweight and extensibleInteractive shell consoleHot deploymentNative OS integrationExtra management toolsActive development
  • OSGI in real world
  • Positives
  • Negatives