CS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu) (props to Dr. Hen-I Yang, CS415X) Feb. 3, 2011
Basic Concepts Service-oriented computing (SOC) Service-oriented architectures (SOA) OSGi and Web Services Knopflerfish OSGi implementation in SHL
Services in the Real World Specialization is a defining characteristic of modern society Narrow breadth and high depth of knowledge/skills Higher quality at lower cost with better availability Services in the real world are Interchangeable (functionally - individual goods/providers don t matter) Contract-driven (well-known interaction points) Mechanism independent (black box principle) Examples: Banking, healthcare, restaurants, etc.
Service-Oriented Computing Service-oriented computing (SOC) applies specialization and design by contract to design complex software systems Handles heterogeneous components (interoperability) Simpler design, reuse, and faster development time (composition) Improved fault tolerance and adaptation (interchangeability) A software service is an artifact that performs some meaningful function for its client Well-defined interface (set of methods) Meta-data to describe the service (set of properties) Implementation is hidden from clients What are some example software services and servicebased systems?
Canonical Exercise: ATM Service Interface (= methods)? Meta-data (= properties)? Possible applications?
Service-Oriented Architectures SOA is a framework and environment for managing and connecting services Platform independent API Execution environment for providers and clients Service registry - stores service descriptions and binding information (e.g. phone book) Providers publish services and descriptions (e.g. name, interface, endpoint, protocol, etc.) Clients query for services, filter meta-data, and obtain binding information for desired services Execution/invocation not included
SOA Components 2 1 3
SOA Specifications: OSGi and WS OGSi - The Open Service Gateway initiative Java-based, centralized SOA standard Targets dynamic, collaborative, reactive environments WS Web Services XML/HTTP based, decentralized SOA standard Composed of three standards: WSDL, SOAP, and UDDI Targets business activities and workflows
OSGi Layers Bundle, package, user permissions Publish, query, etc. service events Runtime bundle management Class loading policies and dependency resolution
Unpacking an OSGi Bundle Component Activator Manifest Service Resources Implementation Interface Bundle
Example Service Interface and package edu.iastate.cs.sh.atm; Metadata public interface ATM { int deposit(int account, int amount); int withdraw(int account, int amount); int checkbalance(int account) } /* Example property values ----------------- < Banks, WellsFargo, United Bank of Ryan > < CurrencyType, USD > < SOAP.service.name, ATM > < SOAP.service.methods deposit, withdraw, checkbalance > */
Example Manifest File /* Bundle information Bundle-Name: ATM /* Human readable */ Bundle-SymbolicName: edu.iastate.cs.sh.atm /*machinereadable*/ Bundle-Description: service for depositing, withdrawing, and querying from a bank account Bundle-Version: 1.0.0 /*Package dependencies */ Import-Packages: Export-Packages: edu.iastate.cs.sh.atm /* Bundle resources */ Bundle-Activator: edu.iastate.edu.sh.atmactivator Bundle-Classpath: /* resources inside the bundle */ /* Others... */
Example Activator package edu.iastate.cs.sh.atm; public ATMActivator implements BundleActivator { private ATM atm = null; private Dictionary props = null; private ServiceRegistration reg = null; public void start(bundlecontext bc){ atm = new ATM( ISU Savings ); props = new Dictionary(); props.add( BankName, ISU Savings ); props.add( Currency, USD ); } reg = bc.registerservice(atm.class.getname, atm, props); } public void stop(bundlecontext bc){ reg.unregister(); }
Lifecycle of an OSGi Bundle Unload Load Unload Activator
Lifecycle of an OSGi Service Register REGISTERED Unregister Modify MODIFIED UNREGISTERING Activator
Deploying a Bundle: CheapMovies ATM ATM Theater Registry?? Event: BUNDLE INSTALLED! RESOLVED!
Activating the Bundle getservicereference( ) ServiceReference CheapMovies ATM ATM Theater Registry getservice ( ) Service Object registerservice( ) filter Event: BUNDLE SERVICE REGISTERED! STARTING! STARTED!
Deactivating a Bundle ungetservice() CheapMovies ATM ATM Theater ungetservice() Registry unregister ( ) Event: BUNDLE SERVICE STOPPING! STOPPED! UNREGISTERING!
Review: Important Tasks Service providers Define service interface and metadata Develop an implementation (hidden) Register a service object with the OSGi framework Update a service s properties Unregister a service with the OSGi framework Service consumers Query the service registry Examine a service s properties Bind to the service object Invoke the service methods Release the service
What is Knopflerfish? Open source implementation of the OSGi standard Apache Felix, (Android), Equinox (Eclipse) Desktop application for graphical monitoring and controlling bundles Eclipse plug-in for facilitated development Generate/edit manifest files, compile source, Automatically build and package jar files
The Knopflerfish Desktop
Knopflerfish Desktop Walkthrough Starting the framework Monitor bundles/services Examining the manifest file Controlling bundles Refreshing the framework Exiting the framework
Questions? SOC/SOA www.google.com OSGi www.osgi.org Knopflerfish www.knopflerfish.org
Current Applications Current applications Home automation Health management Home security ADL support Possible extensions?
Possible New Applications Generic voice interface Prescription conformance monitor Exercise monitor Universal WebRemote EnergySaver
Existing Services (Javadocs soon!) Device services Temperature, humidity, pressure, light level, motion Touch sensor, pressure sensor, dial, microphone, speakers, barcode, RFID, network camera, LCD, [biomedical!] Lamp and appliance control, remote control, [door opener!] Fridge, microwave, blinds Data services Food, medication, health conditions, medical conflicts, user profile Utility services Speech, notification, [timer, calendar, logging] Monitoring services Diet, inventory, shopping list, expiration date, [prescription, physical activity,]