adding modularity afterward with embedded osgi

34
Adding Modularity Afterward with Embedded OSGi Adding Modularity Afterward with Embedded OSGi

Upload: bob-paulin

Post on 21-May-2015

349 views

Category:

Software


3 download

DESCRIPTION

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!

TRANSCRIPT

Page 1: Adding Modularity Afterward with Embedded OSGi

Adding Modularity Afterward with Embedded OSGi

Adding Modularity Afterward with Embedded OSGi

Page 2: Adding Modularity Afterward with Embedded OSGi

About Me – Bob Paulin• @bobpaulin/[email protected]/http://bobpaulin.com●Independent Consultant

• Web Centric Platforms• Business Enablement• Continuous Delivery

Chicago Java Users Group (CJUG) Community Leader• Need a Mentor? [email protected]• Want to Present in Chicago? [email protected]

Proud Father/Husband with 3 kids (and a Cat since Developers all seemed to like cats)

Page 3: Adding Modularity Afterward with Embedded OSGi

Regret

Page 4: Adding Modularity Afterward with Embedded OSGi

Application Development Cycle

Page 5: Adding Modularity Afterward with Embedded OSGi

Hope?

Page 6: Adding Modularity Afterward with Embedded OSGi

If we could start over what would we want?

Page 7: Adding Modularity Afterward with Embedded OSGi

Modularity

Page 8: Adding Modularity Afterward with Embedded OSGi

Options?

Page 9: Adding Modularity Afterward with Embedded OSGi

OSGi● Mature 10+ Years● Tools● Modularity is enforced● Versioning● Complex Classloading● Runtime

● Mature 10+ Years● Tools● Modularity is enforced● Versioning● Complex Classloading● Runtime

Page 10: Adding Modularity Afterward with Embedded OSGi

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

Page 11: Adding Modularity Afterward with Embedded OSGi

Jigsaw● Java 7....8...9??● Versioning● Interoperability with OSGi (Penrose)

● Java 7....8...9??● Versioning● Interoperability with OSGi (Penrose)

Page 12: Adding Modularity Afterward with Embedded OSGi

OSGi: Start with One big Bundle?

Page 13: Adding Modularity Afterward with Embedded OSGi

OSGi: When does embedding make sense?

Page 14: Adding Modularity Afterward with Embedded OSGi

Want an Isolated Third-Party Container

Page 15: Adding Modularity Afterward with Embedded OSGi

Working with OSGi unfriendly Libraries.

Page 16: Adding Modularity Afterward with Embedded OSGi

Licensing/Proprietary Code

Page 17: Adding Modularity Afterward with Embedded OSGi

No Budget/Time/Desire for full OSGi

Page 18: Adding Modularity Afterward with Embedded OSGi

Embedded Design/Implementation

Page 19: Adding Modularity Afterward with Embedded OSGi

Exposing packages to the framework via System Packages

Page 20: Adding Modularity Afterward with Embedded OSGi

Minimum required bundles

● Felix Framework● Felix Framework

Page 21: Adding Modularity Afterward with Embedded OSGi

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...

Page 22: Adding Modularity Afterward with Embedded OSGi

● Configuration● Factories● Resources

● Configuration● Factories● Resources

Good places to start

Page 23: Adding Modularity Afterward with Embedded OSGi

● 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

Page 24: Adding Modularity Afterward with Embedded OSGi

Talk is Cheap.

Time for an example.

Page 25: Adding Modularity Afterward with Embedded OSGi

● 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

Page 26: Adding Modularity Afterward with Embedded OSGi

Embedded Design/Implementation

Page 27: Adding Modularity Afterward with Embedded OSGi

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");

Page 28: Adding Modularity Afterward with Embedded OSGi

Setting up the Framework

//Yup it's that easy!m_felix = new Felix(configMap);

m_felix.start();

Page 29: Adding Modularity Afterward with Embedded OSGi

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);}

Page 30: Adding Modularity Afterward with Embedded OSGi

Supplying more than onepublic <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;}

Page 31: Adding Modularity Afterward with Embedded OSGi

DEMO!

Page 32: Adding Modularity Afterward with Embedded OSGi

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

Page 33: Adding Modularity Afterward with Embedded OSGi

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

Page 34: Adding Modularity Afterward with Embedded OSGi

Bob Paulin@bobpaulin/[email protected]/http://bobpaulin.com