cs486: tutorial on soc, osgi, and...

26
CS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt ([email protected]) (props to Dr. Hen-I Yang, CS415X) Feb. 3, 2011

Upload: others

Post on 19-Mar-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

CS486: Tutorial on SOC, OSGi, and Knopflerfish

Ryan Babbitt ([email protected])

(props to Dr. Hen-I Yang, CS415X)

Feb. 3, 2011

Page 2: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Basic Concepts

• Service-oriented computing (SOC)

• Service-oriented architectures (SOA)

– OSGi and Web Services

• Knopflerfish – OSGi implementation in SHL

Page 3: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

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.

Page 4: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

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 service-based systems?

Page 5: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Canonical Exercise: ATM Service

• Interface (= methods)?

• Meta-data (= properties)?

• Possible applications?

Page 6: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

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

Page 7: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

SOA Components

12

3

Page 8: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

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

Page 9: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

OSGi Layers

Class loading policies and dependency resolution

Runtime bundle management

Publish, query, etc. service events

Bundle, package, user permissions

Page 10: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Unpacking an OSGi Bundle

Bundle

Activator

Service Implementation

ManifestComponent ResourcesService

Interface

Page 11: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Example Service Interface and Metadata

package edu.iastate.cs.sh.atm;

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

*/

Page 12: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Example Manifest File/* Bundle information

Bundle-Name: ATM /* Human readable */

Bundle-SymbolicName: edu.iastate.cs.sh.atm /*machine-

readable*/

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

Page 13: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Example Activatorpackage 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();

}

}

Page 14: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Lifecycle of an OSGi Bundle

Load

Unload

Unload

Activator

Page 15: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Lifecycle of an OSGi Service

REGISTERED MODIFIED

UNREGISTERING

RegisterModify

Unregister

Activator

Page 16: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Deploying a Bundle: CheapMovies

Registry

?

Event: BUNDLE INSTALLED!

?

BUNDLE RESOLVED!

ATM

ATM

Theater

Page 17: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Activating the Bundle

Registry

Event: BUNDLE STARTING!

getServiceReference(…)

ServiceReference

BUNDLE STARTED!

getService (…)

Service Object

registerService(…)

SERVICE REGISTERED!

“filter”

ATM

ATM

TheaterCheapMovies

Page 18: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Deactivating a Bundle

Registry

Event: BUNDLE STOPPING!

ungetService()

BUNDLE STOPPED!

unregister (…)

SERVICE UNREGISTERING!

ungetService()

ATM

ATM

TheaterCheapMovies

Page 19: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

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

Page 20: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

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

Page 21: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

The Knopflerfish Desktop

Page 22: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Knopflerfish Desktop Walkthrough

• Starting the framework…

• Monitor bundles/services …

• Examining the manifest file…

• Controlling bundles …

• Refreshing the framework…

• Exiting the framework…

Page 23: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Questions?

• SOC/SOA – www.google.com

• OSGi – www.osgi.org

• Knopflerfish – www.knopflerfish.org

Page 24: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Current Applications

• Current applications

– Home automation

– Health management

– Home security

– ADL support

• Possible extensions?

Page 25: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

Possible New Applications

• Generic voice interface

• Prescription conformance monitor

• Exercise monitor

• Universal WebRemote

• EnergySaver

Page 26: CS486: Tutorial on SOC, OSGi, and Knopflerfishweb.cs.iastate.edu/~cs486/notes/OSGi-tutorial-486-S11.pdfCS486: Tutorial on SOC, OSGi, and Knopflerfish Ryan Babbitt (rbabbitt@iastate.edu)

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,]