Your SlideShare is downloading. ×
Frankenstein's IDE: NetBeans and 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

Frankenstein's IDE: NetBeans and OSGi

8,822
views

Published on

Using OSGi Bundles in NetBeans Modules and vice versa

Using OSGi Bundles in NetBeans Modules and vice versa

Published in: Technology

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

No Downloads
Views
Total Views
8,822
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
99
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

Transcript

  • 1. Frankenstein's IDE Anton Epple Eppleton IT Consulting http://www.eppleton.de Frankenstein's IDE: Running NetBeans on OSGi and vice versa
  • 2. Agenda
    • Module Systems
    • 3. Service Infrastructure
    • 4. Project netigso: bringing it all together
    • 5. Demos
  • 6. Modularity Recap: Why a module system? Standard Java doesn't support:
      • Versioning
      • 7. Plugins & Updates
      • 8. Dynamic Service Infrastructure
      • 9. Dependency management
      • 10. Controlled API export (information hiding)
    Module Systems like OSGi & NetBeans Module System add this
  • 11. Modularity NetBeans Module System? Started in 1996:
      • Foundation of the IDE ( first NetBeans release 1999 )
      • 12. Usable as independent platform for many years
      • 13. Used on client & server
      • 14. Many commercial and institutional users ( Nokia, Boeing, UNESCO, EADS, US Army ... )
  • 15. Duke's Choice Award 2009
  • 16. Duke's Choice Award 2009 What's the difference between OSGi and NB Platform?
  • 17. Module System How does the OSGi module system work?
    • Runtime Container manages Life cycle and dependencies of modules
    • 18. Basic Services provide reusable functionality
    • 19. API/SPI Modules provide Extension Points and Utility Classes
    • 20. User Modules provide application functionality
  • 21. Module System How does the NetBeans module system work?
    • Runtime Container manages Life cycle and dependencies of modules
    • 22. Basic Services provide reusable functionality
    • 23. API/SPI Modules provide Extension Points and Utility Classes
    • 24. User Modules provide application functionality
  • 25. Module System How does the OSGi module system work?
    • Runtime starts up reads meta information and sets up dependencies
    • 26. Starts the Modules
    • 27. ClassLoader: Every Module has it's own classloader. It can only load classes from other Modules if it has declared a dependency. Loading is then delegated to the other modules ClassLoader
  • 28. Module System How does the NetBeans module system work?
    • Runtime starts up reads meta information and sets up dependencies
    • 29. Starts the Modules
    • 30. ClassLoader: Every Module has it's own classloader. It can only load classes from other Modules if it has declared a dependency. Loading is then delegated to the other modules ClassLoader
    • 31. Tip : Cross-check mailing list for third-party lib problems
  • 32. Module System How is a OSGi bundle constructed?
    • Module is a JAR Archive containing:
      • META-INF/MANIFEST.MF
      • Service registration
  • 36. Module System How is a NetBeans module constructed?
    • Module is a JAR Archive containing:
      • META-INF/MANIFEST.MF
      • Service registration
  • 40. Module System Meta-Data: NetBeans OSGi Identifier OpenIDE-Module: X Bundle-SymbolicName: X Version number OpenIDE-Module-Specification-Version: 7.3 Bundle-Version: 7.3 Activator OpenIDE-Module-Install: x.y.z.Activator Bundle-Activator: x.y.z.Activator Exported Packages OpenIDE-Module-Public-Packages: x.y.z Export-Package: x.y.z Imported Dependencies OpenIDE-Module-Module-Dependencies: another.module > 2.1 Require-Bundle: another.module;bundle-version="(2.1 )"
  • 41. Module System Conclusion: Great minds think alike … but not always
  • 42. OSGi Specific to OSGi / Equinox:
    • Bundles have different states:
    • Eclipse: Buddy Policies ( dependent, global, app, ext, boot, registered = allow circular classloading dependencies for third party libs)
  • 45. OSGi Specific to NetBeans:
      • Tokens for declaring Service Dependencies:
        • Requires
        • 46. Provides...
      • Demo LookupSample:
    OpenIDE-Module-Requires: de.eppleton.extensionpointinterface.MessageProviderInterface OpenIDE-Module-Provides: de.eppleton.extensionpointinterface.MessageProviderInterface
  • 47. Agenda
    • Module Systems
    • 48. Service Infrastructure
    • 49. Project netigso: bringing it all together
    • 50. Demos
  • 51. Service Infrastructure
    • OSGi:
  • 56. Service Infrastructure NetBeans Platform :
      • Lookup
        • Registration based on Java Standards (JAR Spec & ServiceLoader)
        • 57. + Listening for Changes
        • 58. + Lazy Loading
        • 59. + Ordering
  • 60. Service Infrastructure NetBeans Platform :
      • Registry (System FileSystem)
        • Per module XML file
        • 61. Extension points are folders in the FileSystem
        • 62. Extensions are virtual files in the FileSystem
        • 63. Files can represent resources or instances
        • 64. Parametrized instantiation, Factory classes & methods
      • Lookups + SFS = NetBeans Service Infrastructure
  • 65. Service Infrastructure NetBeans Extension Points :
      • Extensions are declarations
      • 66. One extension can contribute to an indefinite number of Extension points
      • 67. Extension point definer queries registry when needed ( lazy loading )
      • 68. Extensions need not be associated with executable Java code
  • 69. Service Infrastructure
    • Comparison OSGi & NetBeans Services:
    • -> NB Services very flexible, but not self documented
    NetBeans Declarative Services Extension Points 1 Service can contribute to more than one Extension Point + + - No need to implement interface + - + Metadata for Documentation - ApiDoc + +
  • 70. Agenda
    • Modular Systems
    • 71. Service Infrastructure
    • 72. Project netigso: bringing it all together
    • 73. Demos
  • 74. Motivation Why would I want an additional Module System?
    • Use the same bundles on client and server
    • 75. OSGi 4.2 Distributed OSGi: Use the same code to work with local and remote services
  • 76. Project Netigso Netigso:
    • Felix OSGi container embedded in NetBeans
    • Interoperability for NetBeans Modules ↔ OSGi bundles
      • Dependency Management over system boundaries
    • Final target: Make platform interchangeable
    • 77. http://wiki.netbeans.org/OSGiAndNetBeans
  • 78. Project Netigso Netigso:
    • Creates Bundles/Modules in NetBeans (build harness)
  • 79. Demo Hello World Demo:
    • Creating a Bundle with Netigso
  • 80. Project Netigso Netigso:
    • NB understands both types of metadata: Setting dependencies between Modules and bundles possible
  • 81. Demo Interoperability Demo:
    • Creating a Module that uses classes from OSGi bundle
  • 82. Project Netigso Service Interoperability:
    • Bundles can contribute to NB Extension points
    • 83. XML registry & Lookup works
  • 84. Project Netigso Runtime: When a bundle is available, launch embedded felix: configMap.put(&quot;felix.cache.profiledir&quot;, cache); configMap.put(&quot;felix.cache.dir&quot;, cache); configMap.put(Constants.FRAMEWORK_STORAGE, cache); activator = new NetigsoActivator(); // listen to changes List<BundleActivator> activators = new ArrayList<BundleActivator>(); activators.add(activator); configMap.put(&quot;felix.systembundle.activators&quot;, activators); felix = new Felix(configMap); felix.init();
  • 85. Project Netigso Expose all Modules as bundles to felix: private static final InputStream fakeBundle(Module m) throws IOException { // create in memory jar containing manifest for OSGi container ByteArrayOutputStream os = new ByteArrayOutputStream(); Manifest man = new Manifest(); man.getMainAttributes().putValue(&quot;Manifest-Version&quot;, &quot;1.0&quot;); man.getMainAttributes().putValue(&quot;Bundle-ManifestVersion&quot;, &quot;2&quot;); .... JarOutputStream jos = new JarOutputStream(os, man); jos.close(); return new ByteArrayInputStream(os.toByteArray()); } // later inject the Module ClassLoader into the Bundle
  • 86. Project Netigso Expose all Bundles as Modules to Module system: final class NetigsoModule extends Module { final Bundle bundle; private NetigsoLoader loader; ... @Override public String getCodeName() { return bundle.getSymbolicName(); } @Override public String getCodeNameBase() { return bundle.getSymbolicName(); } ...
  • 87. Agenda
  • 92. Demo Importing Bundles Demo:
    • ant -f $NETIGSO/harness/suite.xml clusterize -Dcluster=plugins -Dincludes=modules/**
    • 93. Example: Felix Remote Shell
    • 94. Diagnosis and Management Tool
    • 95. telnet localhost 6666
    • 96. Installing and uninstalling bundles
  • 97. Demo Eclipse Equinox Bundles Demo:
    • Peter Kriens SUDOKU example:
    • 98. HTTPService serves SUDOKU game
    • 99. RPC Layer for communication between JavaScript frontend and server
    • 100. Based on Eclipse Equinox
    • 101. In Suite add to project.properties: run.args.extra=--nosplash -J-Dorg.osgi.service.http.port=8080
  • 102. Lessons Learned Lessons learned
    • OSGi & NB Module system are very similar and interoperable
    • 103. Problems:
      • Equinox core bundle contains helper classes
        • Package import vs required bundles
      • Services are standardized, but versioning isn't:
        • Two bundles implementing the same service can have totally independent version numbers in different OSGi containers => Service implementations not easily interchangeable
  • 104. Demo Distributed OSGi Hello World Demo:
      • Reference Implementation (Apache CFX)
  • 105. Status To run NB on OSGi:
    • We need to implement Lookup & System FileSystem in OSGI
      • Both systems need to access resources from all bundles
  • 106. Status Netigso is in early alpha state:
    • Netigso is actively developed
    • 107. Modules and Bundles can communicate & depend on each other
    • 108. Standard services are running without problems (J1)
    • 109. Advanced Examples run in NetBeans
    • 110. My next project: Running Glassfish
    • 111. Blog: http://eppleton.sharedhost.de/blog
  • 112. Q&A