Adding Modularity Afterward with Embedded OSGi

1,229 views

Published on

Many useful software products are started with tightly coupled “spaghetti” code that just works. As lines of code and complexity increase, teams often struggle to make modifications and add new features without impacting the entire application. As a result, previously successful applications start missing dates and suffering from degrading quality. OSGi can help by introducing a modular design that decouples the architecture, separates concerns, and manages dependencies. Unfortunately it often takes a few missed dates before a team realizes how important modularity is. Don’t let your existing product become a victim of its own success. Learn how to introduce modularity to existing software projects using Apache Felix. Discover how your application can evolve into a pluggable standards driven framework. It’s never too late to reap the benefits of modularity!

Published in: Software
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total views
1,229
On SlideShare
0
From Embeds
0
Number of Embeds
22
Actions
Shares
0
Downloads
12
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Adding Modularity Afterward with Embedded OSGi

  1. 1. Adding Modularity Afterward with Embedded OSGi Adding Modularity Afterward with Embedded OSGi
  2. 2. About Me – Bob Paulin • @bobpaulin/bob@bobpaulin.com/http://bobpaulin.com ● Independent Consultant • Web Centric Platforms • Business Enablement • Continuous Delivery Chicago Java Users Group (CJUG) Community Leader • Need a Mentor? mentors@cjug.org • Want to Present in Chicago? present@cjug.org Proud Father/Husband with 3 kids (and a Cat since Developers all seemed to like cats)
  3. 3. Regret
  4. 4. Application Development Cycle
  5. 5. Hope?
  6. 6. If we could start over what would we want?
  7. 7. Modularity
  8. 8. Options?
  9. 9. OSGi ● Mature 10+ Years ● Tools ● Modularity is enforced ● Versioning ● Complex Classloading ● Runtime ● Mature 10+ Years ● Tools ● Modularity is enforced ● Versioning ● Complex Classloading ● Runtime
  10. 10. Inversion of Control (IoC) ● Lightweight ● Easily added to existing systems ● Tools ● Modularity not enforced (DIY) ● No Versioning ● Lightweight ● Easily added to existing systems ● Tools ● Modularity not enforced (DIY) ● No Versioning
  11. 11. Jigsaw ● Java 7....8...9?? ● Versioning ● Interoperability with OSGi (Penrose) ● Java 7....8...9?? ● Versioning ● Interoperability with OSGi (Penrose)
  12. 12. OSGi: Start with One big Bundle?
  13. 13. OSGi: When does embedding make sense?
  14. 14. Want an Isolated Third-Party Container
  15. 15. Working with OSGi unfriendly Libraries.
  16. 16. Licensing/Proprietary Code
  17. 17. No Budget/Time/Desire for full OSGi
  18. 18. Embedded Design/Implementation
  19. 19. Exposing packages to the framework via System Packages
  20. 20. Minimum required bundles ● Felix Framework● Felix Framework
  21. 21. A few more to consider... ● Felix Config Admin ● Gogo Shell ● Web Console + HTTP ● SCR + Annotations ● Apache ACE Management Agent ● Felix Config Admin ● Gogo Shell ● Web Console + HTTP ● SCR + Annotations ● Apache ACE Management Agent A few more to consider...
  22. 22. ● Configuration ● Factories ● Resources ● Configuration ● Factories ● Resources Good places to start
  23. 23. ● Framework creates threads ● Use only one Framework Instance ● Requires some IDE tricks ● Package Tangling may get worse before it gets better (Use Sonar) ● Framework creates threads ● Use only one Framework Instance ● Requires some IDE tricks ● Package Tangling may get worse before it gets better (Use Sonar) Caveats
  24. 24. Talk is Cheap. Time for an example.
  25. 25. ● SOAR 2D Grid Game ● Written in C++ with Java Bindings ● Code is Coupled ● SWT ● Multiple Games ● SOAR 2D Grid Game ● Written in C++ with Java Bindings ● Code is Coupled ● SWT ● Multiple Games An Embedded Usecase With Tanks
  26. 26. Embedded Design/Implementation
  27. 27. Exposing packages to the framework via System Packages configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "edu.umich.soar,edu.umich.soar.gridmap2d.config," + "edu.umich.soar.gridmap2d,edu.umich.soar.gridmap2d.world," + "edu.umich.soar.gridmap2d.visuals," + "org.eclipse.swt.widgets,org.eclipse.swt.graphics; version=0.0.1");
  28. 28. Setting up the Framework //Yup it's that easy! m_felix = new Felix(configMap); m_felix.start();
  29. 29. Supplying Services to the Non- OSGi code public <S> S getService(Class<S> serviceClass) { ServiceReference<S> ref = m_activator.getContext() .getServiceReference(serviceClass); return m_activator.getContext().getService(ref); }
  30. 30. Supplying more than one public <S> List<S> getServices(Class<S> serviceClass, String filter) { Collection<ServiceReference<S>> refCollection = null; try { refCollection = hostActivator.getContext().getServiceReferences(serviceClass, filter); } catch (InvalidSyntaxException e) { LOGGER.error("Invalid Syntax", e); } List<S> result = new ArrayList<S>(); if(refCollection == null) { throw new ModuleException("No services References Could be found for the given class"); } for(ServiceReference<S> currentRef : refCollection) { result.add(hostActivator.getContext().getService(currentRef)); } return result; }
  31. 31. DEMO!
  32. 32. Summary ● Modularity is often an afterthought ● Some projects have difficulty being fully OSGi ● Embedding OSGi can provide many of the same benefits ● Modularity is often an afterthought ● Some projects have difficulty being fully OSGi ● Embedding OSGi can provide many of the same benefits
  33. 33. References ● Adding Modularity Afterwards with Embedded OSGi (Talk and Code) ● Felix Embedded Documentation ● Adding Modularity Afterwards with Embedded OSGi (Talk and Code) ● Felix Embedded Documentation
  34. 34. Bob Paulin @bobpaulin/bob@bobpaulin.com/http://bobpaulin.com

×