1 / 17

Modularity…

Modularity…. ‘Modularity’ includes…. packaging/bundles, access and visibility discovery classloading instantiation (including deferred or lazy) managing dependencies - dependency injection vs. service locator declarative approaches (i.e. using annotations) life cycle management

neena
Download Presentation

Modularity…

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Modularity…

  2. ‘Modularity’ includes… • packaging/bundles, access and visibility • discovery • classloading • instantiation (including deferred or lazy) • managing dependencies - dependency injection vs. service locator • declarative approaches (i.e. using annotations) • life cycle management • registration • deployment and execution • resource loading

  3. Modules • Aggregates of classes • Contain one or more packages • Have their own visibility rules • Have a version tag • Declare versioned dependencies • No more global classpath with modules!

  4. Modular Applications • Discover their components at runtime • Modules (bundles) • Handles the lifecycle • Dynamic loading / reloading • May add/remove/reload components at runtime • Service Registry • Must satisfy dependencies between components • Have API contracts between components • Light container / framework • Run inside a runtime container

  5. Modularity Approaches/Options • Classloader • JDK ServiceLoader • NetBeans Lookup API • OSGi

  6. Lookup – NetBeans Modularity Solution • Small, NetBeans independent library • Part of NetBeans org-openide-util.jar • org.openide.util.Lookup • Works with any version of Java (unlike JDK's ServiceLoader) • A Lookup is dynamic • Can fire changes • A Lookup is instantiable • You can make one and use it • Lookups are composable • ProxyLookup can combine and switch between other lookups and fire changes

  7. Similarities between Lookup and OSGi • Runtime container manages lifecycle and dependencies of modules • Both are packaged as JAR, metadata stored in META-INF/MANIFEST.MF and some other information • Runtime starts up, read meta information and sets up dependencies • Every module has its own classloader loading explicitly declared dependencies only • Dynamic

  8. OSGi & NetBeans • http://wiki.apidesign.org/wiki/OSGiAndNetBeans • As of NetBeans 6.9, much support for OSGi. • A Service Registry for OSGi Using NetBeans Lookup API • http://kenai.com/projects/osgilookups ServiceLookupForPath BundleWrapperClassLoader

  9. Looking at Lookup • Specific uses of this API: • As a Service loader • Lookup.getDefault() • Communication among components... • LookupListener • Global Selection Management • Utilities.actionsGlobalContext() • Selections, Actions, enablement

  10. Service Registry - Separating API and SPI public interface MyService { ... } MyService s = Lookup.getDefault().lookup(MyService.class); • Would return an implementation class • Possibly from a different module Collection<? extends MyService> s = Lookup.getDefault().lookupAll(MyService.class);

  11. META-INF/services mechanism • (Since JDK 1.3) • Somewhere in classpath the file: META-INF/services/mypackage.MyClass • with a single line containing the name of the implementation class; for instance: myotherpackage.MyClassImpl

  12. @ServiceProvider Annotation package my.module; import org.netbeans.spi.whatever.Thing; import org.openide.util.lookup.ServiceProvider; @ServiceProvider(service=Thing.class) public class MyThing implements Thing {...} would result in a resource file META-INF/services/org.netbeans.spi.whatever.Thing containing the single line of text: my.module.MyThing • Declarative Registration Using Annotations • See: http://wiki.netbeans.org/DeclarativeRegistrationUsingAnnotations

  13. org.imagejdev.image.convertservice.ImageConverter

  14. OSGi Service Infrastructures

More Related