SlideShare a Scribd company logo
OSGi In Anger
   A Case Study
Aepona?

• Instil customer for 3 years
• Provider of products into Telco space
• Focus on ‘Network as a Service’
• Think abstractions over operator
  capabilities
Telecom Web Services
    (In a Nutshell)
• SOAP/REST web services offering
  simplified APIs over SMS, MMS, Location,
  Conference Calling, etc
• Endpoints provisioned on a per-partner
  basis
• Endpoints backed by per-partner runtime
  policy enforcement
And Much More
• Billing
• Reporting
• Alarms
• Fault Reporting
• System deployed with null implementations
  of optional features
Architecture
                                 container
                           SMS
                                 (i.e. JVM)

 Portal
                 OAM       TLX
(JBoss)
                           MMS
              nodeA              container
                                   group
DEVKIT
(Eclipse)                  MMS



                 OAM       TLX


                           SMS
              nodeB
Container Groups
           Load
          Balancer




    MMS              MMS


          Container Group
Runtime
• Equinox-based stack
• Initial bundles defined by config.ini
• Bundles can be remotely installed,
  uninstalled, activated, etc
• Managed by Eclipse RCP plug-in or
  command line (telnet & Command
  Provider)
A Potted History

• Project started in late 2006
• Began life as Artix-based stack
• Fairly large, ~10000 unit tests
• Evolved to OSGi 2007
The OAM
• Operations, Administration and
  Maintenance component spec’ed in 2007
• Used to create, delete, monitor & manage
  a multi-container (JVM) environment
• Two key requirements: (a) 99.999% uptime
  (b) ability to DYNAMICALLY install,
  uninstall and patch components
A Leap of Faith
• But for the wrong(ish) reasons
• OAM provided compelling reason for OSGi
• OSGi chosen mainly because it enabled
  hot-deploys
• Not because of enforced modularity or
  service-oriented design
Perceived Downside

• OSGi insists on everything being made
  ‘modular’
• But aren’t we already modular?
• Don’t we partition our software effectively?
  1000s of unit tests say we do!
Umm..NO!

• In retrospect, system far from modular
 • Layers not partitioned cleanly
 • Code not open for extension
 • Free-for-all on code base
Life Before OSGi

• Single source tree
• Spring Configuration Hell
• Extensibility issues - PS work polluting core
  product
• Build issues
Evolving to OSGi
• How do we develop? Tools?
• How do we build? Ant, Maven?
• What to do with Artix, Spring & Hibernate?
• How to modularise existing code stream?
• How much time ($) is this going to take?
• No prior OSGi experience
Eclipse PDE
• OSGi is first class citizen
• Single project defines ‘target platform’
• Per-customer PSF (Team Project Set) files
• Export bundles directly to TWS
• We like PDE - but we don’t know any
  better!
Ant Build
• build.xml copies projects into launcher-
  prescribed directory structure and then
  kicks off launcher
• Heavy use of Eclipse features
• Considerable effort migrating projects
  over, but minimal effort in maintaining
• 400+ projects, features, fragments
Baby Steps
• No big bang
• Artix converted to single bundle
• Common code refactored into core bundle
• Services deployed as mega-bundles, built
  from single source tree
• Gradual migration to OSGi services
Hibernate
• Used bnd to create hibernate bundle
• Used DynamicImport-Package: * to find all
  exported mapping files & pojos
• Added Antlr & all hibernate jar files to
  internal classpath
• Works, but less than ideal
Spring DM
• Consistent programming model with
  existing Spring infrastructure/knowledge
• No issues with proxy-based approach
• Outside of core, only use Spring DM
• Inside core, mixture of Spring DM and
  direct OSGi, but only when necessary
Early Mistakes
• Failed to appreciate beauty of whiteboard
  pattern: publish/subscribe really should be
  replaced with export/track
• Modules not delineated using OSGi
  services - services enable dynamism &
  enforce better design
• Forgetting to unget services
Gradual Modularisation
• Services migrated one at a time
• Initially, layers broken into modules with
  public and private parts
• Eventually, modules refactored to be
  service oriented
• Code base significantly cleaner
Life Before OSGi
                              Service
ParlayX                      (e.g. SMS)



          ICallback                        ISmsDao
                                                         SmsMessage

Adapter      ISmsActivityFactory


                             SmsActivity
                                                     * ALL PUBLIC


Gateway/Network
Life With OSGi
                     Service
ParlayX             (e.g. SMS)



Adapter - public    ISmsSender
                           OSGi service
                                           SmsMessage
                                                        POJO


                     SmsSender

Adapter - private                         ISmsDao
                                           ISmsDao
                                            ISmsDao
                    SmsActivity



Gateway
Note to Self

• OSGi did not make me this way!
• But it encouraged me to step back...
• And be even more clinical in my
  separations
Reality Check
• Developers rarely have the good grace to
  hide implementation details!
• Developers who struggle with partitioning
  and layering will struggle even more
  with OSGi
• OSGi requires that you think more & be
  more disciplined
Today

• Extensive use of services & properties
• Heavy use of Spring DM
• Moderate use of the OSGi API
• Little use of compendium services
Design
•   Layered               WebService
                           (e.g. SMS)
•   Service-Oriented
                           OSGi services

•   Event-Driven            Service
                           (e.g. SMS)
                                            Shared
                                             OSGi
                                           services
                                                      core




•   Loosely-Coupled
                           OSGi services

•   Dynamic/Modular!
                           Adapter
Overall Philosophy
• Avoid the API at all costs
 • Necessarily complex and wonderfully
    subtle - e.g. returning null from a tracker
 • Well documented but good practice hard
    to come by
 • Hard to unit test - especially trackers
• Instead use Spring DM wherever possible
Using the OSGi API
• Only 1 activator across 150 production
    bundles
•   BundleContext injected   via Spring DM
    BundleContextAware

• Primarily used to track & register services
• Also used to track bundles e.g. update
    property accessor when bundle installed,
    signal OAM when bundle fails to install
Idiomatic OSGi
    • What is good practice? A catalog of idioms/
       patterns would be useful, very useful
/**
 * Property accessor tracker that creates describer's associated
 * policy description based on properties extracted from exported
 * policy accessor service. Once created the service is immediately
 * 'untracked'.
 */
private class PropertyAccessorTracker implements ServiceTrackerCustomizer {

    public Object addingService(final ServiceReference serviceReference) {
        final IPropertyAccessor propertyAccessor = (IPropertyAccessor) bundleContext.getService(serviceReference);
        policyDescription = createPolicyDescription(propertyAccessor);
        bundleContext.ungetService(serviceReference);
        debug("Created policy description ", policyDescription);
        return null;
    }

    public void modifiedService(final ServiceReference serviceReference, final Object service) {
        // Do nothing
    }

    public void removedService(final ServiceReference serviceReference, final Object service) {
        // Do nothing - no need for unget
    }
}
Fragments
• Used extensively to configure bundles in
  customer specific ways
• Used to house unit tests (10000+)
• One test fragment for every production
  bundle
• Fragments containing code cannot be unit
  tested. Therefore avoid.
Testing
• Focus mostly on behavioural & interaction-
  based unit testing
• Unit tests live in fragments
• Dedicated team for end-to-end testing
• Many parts of API mockable, except for
  trackers. Grumble.
Features

• Eclipse features describe pre-canned
  applications/features
• Parsed into config.ini files at build time
• Deployed under <install-dir>/conf/
  apps/<feature>/config.ini

• Each feature in conf/apps presented as a
  deployable application on front-end
OSGi Services

• Modules (mostly) communicate through
  services
• Services enable ALL extension points
• Lower layers define and export interfaces;
  consumed by higher layers
• Lower layers define and track interfaces;
  implemented & exported by higher layers
Dynamic Method
               Interception
Exported OSGi service
With service properties:
order=1
targetMethods=sendSms




        IMethodInterceptor   IMethodInterceptor   IMethodInterceptor




                                 Method
   web service                Interceptor                     service
     proxy                      Invoker
IMethodInterceptor
import org.aopalliance.intercept.MethodInterceptor;

/**
  * Method interceptor that enables any bundle to intercept
  * a service invocation. Implementations of this interface
  * are expected to be exported as an OSGi, along with 2
  * properties:
  * <ul>
  *   <li>an 'order' property used to determine the order in which
  *       exported interceptors are invoked compared to each other</li>
  *   <li>an optional set of comma separated 'targetMethods' method
  *       names defining the method(s) that the interceptor should be
  *       applied to</li>
  * </ul>
  *
  * Typically implementations will extend {@link AbstractMethodInterceptor}
  * rather than implement this interface directly.
  *
  * @see AbstractMethodInterceptor
  */
public interface IMethodInterceptor extends MethodInterceptor {
}
Canned Method
       Interceptors
• Address Normalisation: Enables white &
  black listing
• Group Address Resolution: Send to
  ‘group:abc’ => send to many
• Reporting: On every system transaction
Policy Enforcement

Created using IPolicyDescriber
(an OSGi service)




         EnforceablePolicy       EnforceablePolicy   EnforceablePolicy




   web service                      Policy
                                   Enforcer                      service
     proxy
Tracking Lists
/**
 * Provider of policy descriptions ({@link PolicyDescription}s), derived
 * from their service policy description ({@link IPolicyDescriber})
 * counterpart.
 */
public class PolicyProvider implements IPolicyProvider {

    private List<IPolicyDescriber> describers;

   /**
     * Sets the list of policy describers being tracked.
     * The supplied list is expected to be a Spring-backed
     * list that automatically proxies and tracks the actual
     * policy describers.
     * @param describers a set of policy describers to be used
     */
   @Required
   public void setPolicyDescribers(final List<IPolicyDescriber> describers) {
        this.describers = describers;
   }
   ...



  <bean id="policyProvider" class="com.aepona.tws.core.policy.support.PolicyProvider">
      <property name="policyDescribers" ref="policyDescribers" />
  </bean>

  <osgi:list id="policyDescribers"
             interface="com.aepona.tws.core.policy.IPolicyDescriber"
             cardinality="0..N" />
Mobile Originated
          Events
• How to publish asynchronous SMS
  notifications and delivery receipts to third
  party applications?
• More generally - how do we publish events
  from lower layers to higher layers?
Mobile Originated
           Events

Third Party   Service   Network
Application




               ?
Back to the
          Whiteboard

• Lower layer defines and tracks ‘publisher’
  interface
• Higher layer implements and exports
  publisher
Whiteboard
                   Exported as OSGi service




                                              SmsNotificationPublisher        to TPA



                                                            <<implements>>

  from    SmsNotificationHandler               ISmsNotificationPublisher
network


                     Tracks ISmsNotificationPublisher
Lifecycle Events

• Web service endpoints come and go
• How do we inform interested parties of such
  events?
• They may need to stop ongoing transactions
  e.g. in the network layer
OSGi as an Event Bus
• Whiteboard pattern pervades system
• Core defines and tracks ‘listener’ services
• Bundles implement and export listener
  implementations
• Layers are massively decoupled from one
  another
Service Listener
/**
 * Interface to be implemented classes interested in service events.
 * Any instance of a type that implements this interface and that is
 * exported as an OSGi service will be informed of service lifecycle
 * events. Events are fired <i>asynchronously</i> but sequentially.
 * <p>
 * Implementations should not tie up the invoking thread. In other
 * words the {@link #serviceChanged(ServiceEvent)} method should
 * return as quickly as possible.
 */
public interface IServiceListener {

    /**
     * Receives notification that a service lifecycle event
     * has occurred.
     *
     * @param serviceEvent the service event
     */
    void serviceChanged(ServiceEvent serviceEvent);
}
Service Event
/**
 * A service event describing a service lifecycle change.
 * Service events are categorized as:
 * <pre>
 * create - signals that a service has been provisioned
 * update - signals that a service has been updated
 * dispose - signals that a service has been disposed
 * destroy - signals that a service has been destroyed
 * </pre>
 * An 'update' event signals that a service has been updated
 * without having to recreate the endpoint from scratch.
 * If an update requires that a service is re-provisioned
 * (because its service name has changed), then a 'destroy'
 * followed by a 'create' event will be emitted.
 */
public final class ServiceEvent {

      /**
        * Returns a service create event.
        * @param serviceName the newly created service name
        * @return a create service event
        */
      public static ServiceEvent createEvent(final ServiceName serviceName) {
           return new ServiceEvent(CREATE, serviceName);
      }
...
Handling Service Events
/**
 * Purges expired location notification requests from the system.
 * An expired notification is one that has sent the maximum number
 * of notifications or has reached its duration limit - both limits
 * are specified when the notification is created.
 */
public class LocationNotificationTerminator
    implements ILocationNotificationTerminator, IServiceListener, InitializingBean, DisposableBean {

      private ILocationNotificationCriteriaDao criteriaDao;

      /**
        * Deletes data associated with a destroyed service
        */
      public void serviceChanged(final ServiceEvent serviceEvent) {
           if (serviceEvent.isDestroyEvent()) {
               logger.debug("Stopping all notifications for " + serviceEvent.getServiceName());
               stopAll(criteriaDao.findByServiceName(serviceEvent.getServiceName()));
           }
      }
...
Service Adapters
• When deployed inside operator TWS talks
  to single CORBA-based adapter
• When deployed outside operator TWS
  proxies onto multiple operator APIs
• Goal is unified API - OneAPI
• Each operator has own service adapter
  OSGi service
Service Adapters
• Need to support new operator, simply drop
  new adapter bundle
             Exported as OSGi Service
             With ‘name’ property
             name=orange



 OneAPI                  Service        IServiceAdapter
WebService                                        orange


                                        IServiceAdapter
                                                 vodafone


                                        IServiceAdapter
                                                   sprint
Modularity Matters
• TWS is large - without OSGi it would, right
  now, be a mess
• Modularity enforces better discipline
• Modular designs are more extensible
• Modular designs are easier to test
• Modular designs are cheaper
Personal Opinion
• First I couldn’t live without Design By
  Contract
• Then I couldn’t live without BDD & DI
• Now I dread life without OSGi
• Enforced modularity and OSGi services are
  indispensable design tools

More Related Content

KEY
Practical OSGi Subsystems
PDF
Subsystems: For those occasions where bundles are just too small... - Graham ...
KEY
Ruby Plugins for Jenkins
PPTX
Java script nirvana in netbeans [con5679]
PDF
Multi-bundle Scoping in OSGi
KEY
Jug Poitou Charentes - Apache, OSGi and Karaf
PPT
PowerPoint Presentation
PPT
OSGi & Blueprint
Practical OSGi Subsystems
Subsystems: For those occasions where bundles are just too small... - Graham ...
Ruby Plugins for Jenkins
Java script nirvana in netbeans [con5679]
Multi-bundle Scoping in OSGi
Jug Poitou Charentes - Apache, OSGi and Karaf
PowerPoint Presentation
OSGi & Blueprint

What's hot (20)

PDF
Avik_RailsTutorial
PPTX
Developing in the Cloud
KEY
JavaScript Craftsmanship: Why JavaScript is Worthy of TDD
PDF
OUGF OSGi/Flex
PDF
Has code123
PPTX
Dependency injection
PDF
Don Schwarz App Engine Talk
PDF
Camel oneactivemq posta-final
PDF
Ajax In Enterprise Portals
PDF
Scalable Object Storage with Apache CloudStack and Apache Hadoop
PPTX
Scale11x : Virtualization with Xen and XCP
PPTX
Building node.js applications on windows azure
PPTX
Continuous Delivery in the AWS Cloud
PPT
Introduction to Apache CloudStack by David Nalley
PDF
The Kubernetes WebLogic revival (part 2)
PDF
Microservices and functional programming
PPTX
Containers, Serverless and Functions in a nutshell
KEY
An Eye for (Network) Design
PDF
Apache Camel Introduction
Avik_RailsTutorial
Developing in the Cloud
JavaScript Craftsmanship: Why JavaScript is Worthy of TDD
OUGF OSGi/Flex
Has code123
Dependency injection
Don Schwarz App Engine Talk
Camel oneactivemq posta-final
Ajax In Enterprise Portals
Scalable Object Storage with Apache CloudStack and Apache Hadoop
Scale11x : Virtualization with Xen and XCP
Building node.js applications on windows azure
Continuous Delivery in the AWS Cloud
Introduction to Apache CloudStack by David Nalley
The Kubernetes WebLogic revival (part 2)
Microservices and functional programming
Containers, Serverless and Functions in a nutshell
An Eye for (Network) Design
Apache Camel Introduction
Ad

Similar to OSGi In Anger - Tara Simpson (20)

PDF
Benefits of OSGi in Practise
PDF
Distributing OSGi
PDF
OSGi tech session
PDF
Enterprise Applications With OSGi and SpringSource dm Server
PPTX
EclipseCON2012 - Enterprise OSGi for Earthlings: Meet Eclipse Libra
PDF
OSGi Mars World in Action
PPT
Enabling modularization through OSGi and SpringDM
PDF
OUGF - OSGi / Flex
PPT
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
PDF
10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
PDF
OSGi user forum dc metro v1
PDF
OSGi User Forum US DC Metro
PDF
Distributed Services - OSGi 4.2 and possible future enhancements
PDF
TDC 2011: OSGi-enabled Java EE Application
KEY
Introduction to EclipseRT (JAX 2010)
KEY
Beyond OSGi Software Architecture
PDF
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
PDF
Introduction To OSGi
PDF
OSGi-enabled Java EE applications in GlassFish
PDF
OSGi-enabled Java EE Applications using GlassFish
Benefits of OSGi in Practise
Distributing OSGi
OSGi tech session
Enterprise Applications With OSGi and SpringSource dm Server
EclipseCON2012 - Enterprise OSGi for Earthlings: Meet Eclipse Libra
OSGi Mars World in Action
Enabling modularization through OSGi and SpringDM
OUGF - OSGi / Flex
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
OSGi user forum dc metro v1
OSGi User Forum US DC Metro
Distributed Services - OSGi 4.2 and possible future enhancements
TDC 2011: OSGi-enabled Java EE Application
Introduction to EclipseRT (JAX 2010)
Beyond OSGi Software Architecture
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
Introduction To OSGi
OSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE Applications using GlassFish
Ad

More from mfrancis (20)

PDF
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
PDF
OSGi and Java 9+ - BJ Hargrave (IBM)
PDF
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
PDF
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
PDF
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
PDF
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
PDF
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
PDF
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
PDF
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
PDF
OSGi CDI Integration Specification - Ray Augé (Liferay)
PDF
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
PDF
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
PDF
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
PDF
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
PDF
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
PDF
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
PDF
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
PDF
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
PDF
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
PDF
How to connect your OSGi application - Dirk Fauth (Bosch)
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
OSGi and Java 9+ - BJ Hargrave (IBM)
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
OSGi CDI Integration Specification - Ray Augé (Liferay)
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
How to connect your OSGi application - Dirk Fauth (Bosch)

Recently uploaded (20)

PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Modernizing your data center with Dell and AMD
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Cloud computing and distributed systems.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
Teaching material agriculture food technology
PPTX
MYSQL Presentation for SQL database connectivity
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Modernizing your data center with Dell and AMD
Chapter 3 Spatial Domain Image Processing.pdf
Machine learning based COVID-19 study performance prediction
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
Cloud computing and distributed systems.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Encapsulation_ Review paper, used for researhc scholars
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Review of recent advances in non-invasive hemoglobin estimation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
The AUB Centre for AI in Media Proposal.docx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Teaching material agriculture food technology
MYSQL Presentation for SQL database connectivity

OSGi In Anger - Tara Simpson

  • 1. OSGi In Anger A Case Study
  • 2. Aepona? • Instil customer for 3 years • Provider of products into Telco space • Focus on ‘Network as a Service’ • Think abstractions over operator capabilities
  • 3. Telecom Web Services (In a Nutshell) • SOAP/REST web services offering simplified APIs over SMS, MMS, Location, Conference Calling, etc • Endpoints provisioned on a per-partner basis • Endpoints backed by per-partner runtime policy enforcement
  • 4. And Much More • Billing • Reporting • Alarms • Fault Reporting • System deployed with null implementations of optional features
  • 5. Architecture container SMS (i.e. JVM) Portal OAM TLX (JBoss) MMS nodeA container group DEVKIT (Eclipse) MMS OAM TLX SMS nodeB
  • 6. Container Groups Load Balancer MMS MMS Container Group
  • 7. Runtime • Equinox-based stack • Initial bundles defined by config.ini • Bundles can be remotely installed, uninstalled, activated, etc • Managed by Eclipse RCP plug-in or command line (telnet & Command Provider)
  • 8. A Potted History • Project started in late 2006 • Began life as Artix-based stack • Fairly large, ~10000 unit tests • Evolved to OSGi 2007
  • 9. The OAM • Operations, Administration and Maintenance component spec’ed in 2007 • Used to create, delete, monitor & manage a multi-container (JVM) environment • Two key requirements: (a) 99.999% uptime (b) ability to DYNAMICALLY install, uninstall and patch components
  • 10. A Leap of Faith • But for the wrong(ish) reasons • OAM provided compelling reason for OSGi • OSGi chosen mainly because it enabled hot-deploys • Not because of enforced modularity or service-oriented design
  • 11. Perceived Downside • OSGi insists on everything being made ‘modular’ • But aren’t we already modular? • Don’t we partition our software effectively? 1000s of unit tests say we do!
  • 12. Umm..NO! • In retrospect, system far from modular • Layers not partitioned cleanly • Code not open for extension • Free-for-all on code base
  • 13. Life Before OSGi • Single source tree • Spring Configuration Hell • Extensibility issues - PS work polluting core product • Build issues
  • 14. Evolving to OSGi • How do we develop? Tools? • How do we build? Ant, Maven? • What to do with Artix, Spring & Hibernate? • How to modularise existing code stream? • How much time ($) is this going to take? • No prior OSGi experience
  • 15. Eclipse PDE • OSGi is first class citizen • Single project defines ‘target platform’ • Per-customer PSF (Team Project Set) files • Export bundles directly to TWS • We like PDE - but we don’t know any better!
  • 16. Ant Build • build.xml copies projects into launcher- prescribed directory structure and then kicks off launcher • Heavy use of Eclipse features • Considerable effort migrating projects over, but minimal effort in maintaining • 400+ projects, features, fragments
  • 17. Baby Steps • No big bang • Artix converted to single bundle • Common code refactored into core bundle • Services deployed as mega-bundles, built from single source tree • Gradual migration to OSGi services
  • 18. Hibernate • Used bnd to create hibernate bundle • Used DynamicImport-Package: * to find all exported mapping files & pojos • Added Antlr & all hibernate jar files to internal classpath • Works, but less than ideal
  • 19. Spring DM • Consistent programming model with existing Spring infrastructure/knowledge • No issues with proxy-based approach • Outside of core, only use Spring DM • Inside core, mixture of Spring DM and direct OSGi, but only when necessary
  • 20. Early Mistakes • Failed to appreciate beauty of whiteboard pattern: publish/subscribe really should be replaced with export/track • Modules not delineated using OSGi services - services enable dynamism & enforce better design • Forgetting to unget services
  • 21. Gradual Modularisation • Services migrated one at a time • Initially, layers broken into modules with public and private parts • Eventually, modules refactored to be service oriented • Code base significantly cleaner
  • 22. Life Before OSGi Service ParlayX (e.g. SMS) ICallback ISmsDao SmsMessage Adapter ISmsActivityFactory SmsActivity * ALL PUBLIC Gateway/Network
  • 23. Life With OSGi Service ParlayX (e.g. SMS) Adapter - public ISmsSender OSGi service SmsMessage POJO SmsSender Adapter - private ISmsDao ISmsDao ISmsDao SmsActivity Gateway
  • 24. Note to Self • OSGi did not make me this way! • But it encouraged me to step back... • And be even more clinical in my separations
  • 25. Reality Check • Developers rarely have the good grace to hide implementation details! • Developers who struggle with partitioning and layering will struggle even more with OSGi • OSGi requires that you think more & be more disciplined
  • 26. Today • Extensive use of services & properties • Heavy use of Spring DM • Moderate use of the OSGi API • Little use of compendium services
  • 27. Design • Layered WebService (e.g. SMS) • Service-Oriented OSGi services • Event-Driven Service (e.g. SMS) Shared OSGi services core • Loosely-Coupled OSGi services • Dynamic/Modular! Adapter
  • 28. Overall Philosophy • Avoid the API at all costs • Necessarily complex and wonderfully subtle - e.g. returning null from a tracker • Well documented but good practice hard to come by • Hard to unit test - especially trackers • Instead use Spring DM wherever possible
  • 29. Using the OSGi API • Only 1 activator across 150 production bundles • BundleContext injected via Spring DM BundleContextAware • Primarily used to track & register services • Also used to track bundles e.g. update property accessor when bundle installed, signal OAM when bundle fails to install
  • 30. Idiomatic OSGi • What is good practice? A catalog of idioms/ patterns would be useful, very useful /** * Property accessor tracker that creates describer's associated * policy description based on properties extracted from exported * policy accessor service. Once created the service is immediately * 'untracked'. */ private class PropertyAccessorTracker implements ServiceTrackerCustomizer { public Object addingService(final ServiceReference serviceReference) { final IPropertyAccessor propertyAccessor = (IPropertyAccessor) bundleContext.getService(serviceReference); policyDescription = createPolicyDescription(propertyAccessor); bundleContext.ungetService(serviceReference); debug("Created policy description ", policyDescription); return null; } public void modifiedService(final ServiceReference serviceReference, final Object service) { // Do nothing } public void removedService(final ServiceReference serviceReference, final Object service) { // Do nothing - no need for unget } }
  • 31. Fragments • Used extensively to configure bundles in customer specific ways • Used to house unit tests (10000+) • One test fragment for every production bundle • Fragments containing code cannot be unit tested. Therefore avoid.
  • 32. Testing • Focus mostly on behavioural & interaction- based unit testing • Unit tests live in fragments • Dedicated team for end-to-end testing • Many parts of API mockable, except for trackers. Grumble.
  • 33. Features • Eclipse features describe pre-canned applications/features • Parsed into config.ini files at build time • Deployed under <install-dir>/conf/ apps/<feature>/config.ini • Each feature in conf/apps presented as a deployable application on front-end
  • 34. OSGi Services • Modules (mostly) communicate through services • Services enable ALL extension points • Lower layers define and export interfaces; consumed by higher layers • Lower layers define and track interfaces; implemented & exported by higher layers
  • 35. Dynamic Method Interception Exported OSGi service With service properties: order=1 targetMethods=sendSms IMethodInterceptor IMethodInterceptor IMethodInterceptor Method web service Interceptor service proxy Invoker
  • 36. IMethodInterceptor import org.aopalliance.intercept.MethodInterceptor; /** * Method interceptor that enables any bundle to intercept * a service invocation. Implementations of this interface * are expected to be exported as an OSGi, along with 2 * properties: * <ul> * <li>an 'order' property used to determine the order in which * exported interceptors are invoked compared to each other</li> * <li>an optional set of comma separated 'targetMethods' method * names defining the method(s) that the interceptor should be * applied to</li> * </ul> * * Typically implementations will extend {@link AbstractMethodInterceptor} * rather than implement this interface directly. * * @see AbstractMethodInterceptor */ public interface IMethodInterceptor extends MethodInterceptor { }
  • 37. Canned Method Interceptors • Address Normalisation: Enables white & black listing • Group Address Resolution: Send to ‘group:abc’ => send to many • Reporting: On every system transaction
  • 38. Policy Enforcement Created using IPolicyDescriber (an OSGi service) EnforceablePolicy EnforceablePolicy EnforceablePolicy web service Policy Enforcer service proxy
  • 39. Tracking Lists /** * Provider of policy descriptions ({@link PolicyDescription}s), derived * from their service policy description ({@link IPolicyDescriber}) * counterpart. */ public class PolicyProvider implements IPolicyProvider { private List<IPolicyDescriber> describers; /** * Sets the list of policy describers being tracked. * The supplied list is expected to be a Spring-backed * list that automatically proxies and tracks the actual * policy describers. * @param describers a set of policy describers to be used */ @Required public void setPolicyDescribers(final List<IPolicyDescriber> describers) { this.describers = describers; } ... <bean id="policyProvider" class="com.aepona.tws.core.policy.support.PolicyProvider"> <property name="policyDescribers" ref="policyDescribers" /> </bean> <osgi:list id="policyDescribers" interface="com.aepona.tws.core.policy.IPolicyDescriber" cardinality="0..N" />
  • 40. Mobile Originated Events • How to publish asynchronous SMS notifications and delivery receipts to third party applications? • More generally - how do we publish events from lower layers to higher layers?
  • 41. Mobile Originated Events Third Party Service Network Application ?
  • 42. Back to the Whiteboard • Lower layer defines and tracks ‘publisher’ interface • Higher layer implements and exports publisher
  • 43. Whiteboard Exported as OSGi service SmsNotificationPublisher to TPA <<implements>> from SmsNotificationHandler ISmsNotificationPublisher network Tracks ISmsNotificationPublisher
  • 44. Lifecycle Events • Web service endpoints come and go • How do we inform interested parties of such events? • They may need to stop ongoing transactions e.g. in the network layer
  • 45. OSGi as an Event Bus • Whiteboard pattern pervades system • Core defines and tracks ‘listener’ services • Bundles implement and export listener implementations • Layers are massively decoupled from one another
  • 46. Service Listener /** * Interface to be implemented classes interested in service events. * Any instance of a type that implements this interface and that is * exported as an OSGi service will be informed of service lifecycle * events. Events are fired <i>asynchronously</i> but sequentially. * <p> * Implementations should not tie up the invoking thread. In other * words the {@link #serviceChanged(ServiceEvent)} method should * return as quickly as possible. */ public interface IServiceListener { /** * Receives notification that a service lifecycle event * has occurred. * * @param serviceEvent the service event */ void serviceChanged(ServiceEvent serviceEvent); }
  • 47. Service Event /** * A service event describing a service lifecycle change. * Service events are categorized as: * <pre> * create - signals that a service has been provisioned * update - signals that a service has been updated * dispose - signals that a service has been disposed * destroy - signals that a service has been destroyed * </pre> * An 'update' event signals that a service has been updated * without having to recreate the endpoint from scratch. * If an update requires that a service is re-provisioned * (because its service name has changed), then a 'destroy' * followed by a 'create' event will be emitted. */ public final class ServiceEvent { /** * Returns a service create event. * @param serviceName the newly created service name * @return a create service event */ public static ServiceEvent createEvent(final ServiceName serviceName) { return new ServiceEvent(CREATE, serviceName); } ...
  • 48. Handling Service Events /** * Purges expired location notification requests from the system. * An expired notification is one that has sent the maximum number * of notifications or has reached its duration limit - both limits * are specified when the notification is created. */ public class LocationNotificationTerminator implements ILocationNotificationTerminator, IServiceListener, InitializingBean, DisposableBean { private ILocationNotificationCriteriaDao criteriaDao; /** * Deletes data associated with a destroyed service */ public void serviceChanged(final ServiceEvent serviceEvent) { if (serviceEvent.isDestroyEvent()) { logger.debug("Stopping all notifications for " + serviceEvent.getServiceName()); stopAll(criteriaDao.findByServiceName(serviceEvent.getServiceName())); } } ...
  • 49. Service Adapters • When deployed inside operator TWS talks to single CORBA-based adapter • When deployed outside operator TWS proxies onto multiple operator APIs • Goal is unified API - OneAPI • Each operator has own service adapter OSGi service
  • 50. Service Adapters • Need to support new operator, simply drop new adapter bundle Exported as OSGi Service With ‘name’ property name=orange OneAPI Service IServiceAdapter WebService orange IServiceAdapter vodafone IServiceAdapter sprint
  • 51. Modularity Matters • TWS is large - without OSGi it would, right now, be a mess • Modularity enforces better discipline • Modular designs are more extensible • Modular designs are easier to test • Modular designs are cheaper
  • 52. Personal Opinion • First I couldn’t live without Design By Contract • Then I couldn’t live without BDD & DI • Now I dread life without OSGi • Enforced modularity and OSGi services are indispensable design tools