54
Department of Computer Science Institute for System Architecture, Chair for Computer Networks Application Development for Mobile and Ubiquitous Computing 9. Platforms – Java ME and OSGi Dr. Ing. Thomas Springer Technische Universität Dresden Chair of Computer Networks

Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Application Development for Mobile and Ubiquitous Computing

9. Platforms – Java ME and OSGi

Dr. Ing. Thomas SpringerTechnische Universität Dresden

Chair of Computer Networks

Page 2: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

JAVA MICRO EDITION

Page 3: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Java Micro Edition - Overview

Creation of Stand-alone applications for resource limited devices• Native programming limits portability and reusability• Java is a widely deployed platform • supports portability and reusability• issues with resource-limited devices for Java SE

Sun divides today the Java-technology into 3 domains:• Java SE (Standard Edition) ⇨ Desktop applications• Java ME (Micro Edition) ⇨ Resource restricted systems• Java EE (Enterprise Edition) ⇨ Server-side solution

Goals of Java ME• Portability of applications for large range of resource-limited devices• same (Java) programming model• Comfortable development of applications for mobile devices

Fast growing distribution of Java Micro Edition• Number of Java ME-enabled mobile phones:

o 2002: 31 Mio.o 2003: 88 Mio.o 2008: 592 Mio. (prognosis)

Dr. Thomas Springer 3Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 4: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Application Domains of Java ME

Designed for devices with restrictions concerning processorpower, memory, display size and networking capabilitiesHeterogeneous requirements for Java ME devices• Personal, mobile, networked devices

o Mobile phones, PDA`s, Smart phones, pagerso Characteristics:• Simple User Interfaces

• Memory capacity: 128 – 512 kb• Wireless network connection (low bandwidth)

• Commonly used, stationary, networked deviceso Set-Top-Boxes, video-phones, entertainment and navigation

systems…o Characteristics:• More complex user interfaces

• Memory capacity: 2 – 16 MB• Broadband network connection over TCP/IP

Dr. Thomas Springer 4Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 5: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Modular Architecture – Java ME Contents

Configurations

Profiles

Optional Packets

CVM

KVM … Kilo Virtual Machine, CVM … Compact Virtual Machine

Ref: [Schmatz, Java 2 Micro Edition]

Dr. Thomas Springer 5Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 6: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Modular Architecture- Details

CVM/KVM• Kernel of Java ME• CVM for more powerful devices (High-End PDA)• KVM for resource restricted devices (Mobile Phones)

o Restrictions compared to JVM (JNI, Class file-Verifier)

Configurations• Horizontal classification of Java ME• Smallest common basis of all devices of that category

Profiles• Vertical classification of Java ME• Adaptation to special devices (different display sizes)• Application development (MIDlets)

Optional packets• Extension by additional functionality (SMS, MMS,

Bluetooth)• support for device-specific functionality

Dr. Thomas Springer 6Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 7: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Configurations

Configuration defines• language support of Java• functionality of Virtual Machine (VM)• basic programming libraries

o Usually subset of Java SE usedo Alternative/additional functionality defined outside Java SE

Two configurations• Connected, Limited Device Configuration (CLDC)

o for personal, mobile, weakly-connected devices

• Connected Device Configuration (CDC)o for shared, stationary, network integrated devices

Different versions per configuration• Currently two versions (1.0 and 1.1) for CDC and CLDC

Dr. Thomas Springer 7Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 8: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Connected Device Configuration (CDC)• Currently available in Version 1.1 (JSR-218)• Characteristics

o Powerful CPUs (min. 32 Bit)o High memory resource (min. 4 Mbytes)o Good data transmission rates: permanent network

connection

Profiles are subsets of Java SE 1.4.2• Foundation Profile 1.1 (JSR – 219)

o Extension of CDC by security packetso No graphical user interfaces possible

• Personal Basis Profile 1.1 (JSR-217)o Graphical User Interfaces by subset of AWTo Only light-weight components (container, component)o Usage of X-lets

- Similar to MIDlets, States: Loaded, Active, Paused, Destroyed- Communication by Inter-Xlet-Communication(IXC)

• Personal Profile 1.1 (JSR-216)o Supports almost all components of AWTo including Heavy Weight components (Buttons, Lists)

Configurations - CDC

Dr. Thomas Springer 8Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 9: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Connected Limited Device Configuration (CLDC)• Currently available in Version 1.1 (JSR-139)• Kilo Virtual Machine

o goal: 160 – 512 kb memory usedo Subset of Java VM features

- no floating point arithmetic (no float and double) (available for CLDC 1.1)- no native functions- no user defined class loaders- no introspection (no serialization, no RMI)- no Thread groups and daemon threads- limited Garbage Collector (no finalize(), no weak references (available for

CLDC 1.1))

• Characteristicso Less powerful CPUs with 16-32 Bito Low memory resources: 192-512 k byteo Short battery life timeo Low transmission data rates -> no permanent network connectiono Minimal operating system for managing hardware

Configurations - CLDC

Dr. Thomas Springer 9Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 10: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Profiles of CLDC

Mobile Information Device Profile (MIDP)• Timer (delay of activities)• Network connection by Generic Connection Framework

(GCF)• Persistent memory (RMS)

o Mini database as record store organizedo Data operations (add, change, delete of records)o Record store assigned to applications

• Application developmento Generation of MIDlet-Suites

• Grafical User Interfaces o Lowest Common Denominator User Interface (LCDUI)

• Securityo Trusted MIDlet Suites (MIDP 2.0)

Dr. Thomas Springer 10Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 11: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Midlets are basic abstraction for application• Lifecycle managed by Application Management Software

(AMS) on mobile Device• Deployed as Midlet Suites

Dr. Thomas Springer 11Application Development - Lecture 9. Platforms - Java ME and OSGi

CLDC Application Development

Page 12: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

MIDP Applications (2)

MIDlet-Suites are running in a life cycleInstallation, application cycle, de-installationApplication cycle• MIDlets are in a state: Active, Paused, Destroyed• Paused in case of inactivity (break in case of other activities)• In state Destroyed: used resources are freed in case of ending the

application

destroyApp()

new()

pauseApp()

startApp()

destroyApp()

Dr. Thomas Springer 12Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 13: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

import javax.microedition.midlet.*;import javax.microedition.lcdui.*;

public class Fligbookingsystem extends MIDlet implements javax.microedition.lcdui.CommandListener {

// Constructor – invocation of method initializepublic Flightbookingsystem() {

initialize();}

public void startApp() {}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

}

MIDlet – Basic Structure

Dr. Thomas Springer 13Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 14: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Midlet Descriptions

Manifest • Part of .jar file• Contains information about the application as attribute

assignments• Mandatory attributes:

o MIDlet-Name, MIDlet-Version, Midlet-URL, o Configuration and Profile requirements

• Optional attributes: o MIDlet-Description, MIDlet-Icon

Java Application Descriptors (JAD)• External of .jar file• Delivers information about the application before the installation

on the device• Verification if available resources are sufficient, integrity of .jar

and trustability of vendor• Contains Attributes of Manifest and• Signature of Midlet Suite, certificates of vendor and certification

authorities, Access permissions

Dr. Thomas Springer 14Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 15: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Midlet GUI

No AWT supported in MIDP• Heterogeneous displays - small monochrome screens up to high

resolution, high color screens• Lowest Common Denominator (LCDUI) Approach – weakest

resources are reference Two variants for implementing graphical user interfaces• High-level API

o Elements for abstract form-based UI elements (button, textbox, date field)

o abstract UI elements mapped to native elementso High portabilityo Look-and-Feel depends on implementation

- MIDlets can‘t manipulate visualization of UI elements (shape, color, font)- Simple user interactions handled internally – without notifying the MIDlet

(e.g. navigation in dialog larger than display)- Abstraction of input devices and method

• Low-level APIo Basic graphic functions on Canvas addressing pixels (point, line,

rectangle)o handling of physical input elements (e.g. phone buttons)o low level events (e.g. button pressed, button released)o Used for Game-API

Dr. Thomas Springer 15Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 16: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

MIDP classes for GUI creation

Dr. Thomas Springer 16Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 17: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

LCDUI - Example

Usage of High-Level APISet display to main menu during initialization of MIDletFor each MIDlet one display is assigned

// This method initializes UI of the application. private void initialize() {

getDisplay().setCurrent(get_mainMenu());}

// This method should return an instance of the display.

public javax.microedition.lcdui.Display getDisplay () { return javax.microedition.lcdui.Display.getDisplay(this);

}

Dr. Thomas Springer 17Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 18: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

LCDUI – Example – Screens und Items

public javax.microedition.lcdui.Form createInputForm() {

Item items[]=new Item[5];items[0] = new javax.microedition.lcdui.Spacer(1000, 1);items[1] = new javax.microedition.lcdui.Spacer(1000, 1);items[2] = new javax.microedition.lcdui.TextField("*Name", null, 120, 0x0);items[3] = new javax.microedition.lcdui.TextField("*Flug", null, 120, 0x0);items[4] = new javax.microedition.lcdui.TextField("*Sitz", null, 120, 0x0);

FlightRequest_Storn_InputForm = new javax.microedition.lcdui.Form("Flug – Stornierung", items);

/* Commands of Formular */FlightRequest_Storn_InputForm.addCommand(createStornCommand());FlightRequest_Storn_InputForm.addCommand(createBackCommand()); FlightRequest_Storn_InputForm.setCommandListener(this);

return FlightRequest_Storn_InputForm;}

Dr. Thomas Springer 18Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 19: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

LCDUI – Example – Create Command

Create Navigation Command/*** Commands ***/

/* Storn */public javax.microedition.lcdui.Command createStornCommand() {

stornCommand = new javax.microedition.lcdui.Command("Stornierung", javax.microedition.lcdui.Command.OK, 1);

return stornCommand;}

public class Fligbookingsystem extends MIDlet implements javax.microedition.lcdui.CommandListener {…// called, if command was performed

public void commandAction(javax.microedition.lcdui.Command command, javax.microedition.lcdui.Displayable displayable) { }

}

Handle input events

Dr. Thomas Springer 19Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 20: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

No adoption of “java.net“ due to:• 27 classes in J2SE 1.4 >200 kB (> min. requirement for CLDC)• No consistent usage of protocols (Socket, InetAddress,

URLConnection)• Not flexible, because of direct class use, i.e. directly bound to

protocol implementation - no interfaces

Generic Connection Framework (GCF) • functional comparable alternative to „java.net“• Homogenous API for all network types• Contained in “javax.microedition.io“• Communication Protocols represented by

o generic Connection interface implemented by Connector classo Connection provides homogeneous interface for accessing all types

of connectionso particular connection/protocol implementation is subclass of

Connection

Midlet network communication

Dr. Thomas Springer 20Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 21: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Generic Connection Framework (2)

Mandatory

Dr. Thomas Springer 21Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 22: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Generic Connection Framework (3)

Producing a connecting object through :“Connector.open(String arg)“ arg=scheme:target[;parameters]

HTTP and HTTPS are suported by all MIDP 2.0 devices, all other types are optional

Protokolltyp Beispielparameter für arg Interface

HTTP http://java.sun.com HttpConnectionHTTPS https://java.sun.com HttpsConnectionSockets (TCP) socket://time-a.nist.gov:13 SocketConnectionSerial comm:0;baudrate=2400; CommConnectionDatagrams (UDP) datagram://127.0.0.1 UDPDatagramConnection

Dr. Thomas Springer 22Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 23: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Generic Connection Framework (4)

Example: HTTP- Connection

try {HttpConnection con =

(HttpConnection)Connector.open("http://www.tu-dresden.de");}catch (ConnectionNotFoundException ex) {

// connection with server can not be established

catch (IOException ex) {// general I/O error

}catch (SecurityException ex) {

// no rights for network access}

Dr. Thomas Springer 23Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 24: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Midlet data management

For MIDP min. 8kB persistent memory required

Record Management System (RMS)• Simple mechanism for storing persistent data• Device independent API• Not comparable to data base• Simple data store consisting of a set of non-typed data• Data sets are name, value pairs while name=id, variable

size

Dr. Thomas Springer 24Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 25: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

RMS – Example

// Create record store if it does not exist RecordStore rs = RecordStore.openRecordStore(REC_STORE, true);

// read record

// Allocate space to hold each recordbyte[] recData = new byte[50];

// Get data into the byte array rs.getRecord(id, recData, 0);

//write record

// Write data into an internal byte arrayByteArrayOutputStream strmBytes = new ByteArrayOutputStream();

// Get stream data into byte array and write recordbyte[] record = strmBytes.toByteArray();rs.addRecord(record, 0, record.length);

Dr. Thomas Springer 25Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 26: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

MIDP2.0 Security (1)

Concept of Trusted MIDlet-SuitesCheck trustability of vendor and integrity of .jar• Signature contains checksum signed by vendor• .jad contains certificate of vendor and certificate authorities• Root certificates on mobile device• certificate = public key – signed by certificate authority

No guaranty for secure transmissions

MIDlet-Suite.JAD

signing checksum using vendors private key

MIDlet-Suite.JAR

checksum

add signature to .JAD descriptor

Development Environment

validate signature

Mobile Device

validate vendors public key

root certificate of certificate

authority

Page 27: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Midlet provisioning

Over-the-air Provisioning (OTA) • Initiated by user

• Controlled by AMS (Application Management Software)

Installation process:• .JAD-Server ⇨ with .jad-file (application descriptor)• .JAR-Server ⇨ with .jar-archive• Notification Server ⇨ Gets feedback about installation success

- Often all 3 roles provided by one server

Dr. Thomas Springer 27Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 28: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

OTA User Initiated Provisioning

AMS = Application Management Software, part of Java Runtime on mobile device

Dr. Thomas Springer 28Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 29: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Java ME - Integration

Dr. Thomas Springer 29Application Development - Lecture 9. Platforms - Java ME and OSGi

[Ref: java.sun.com]

Page 30: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Development Tools

Toolkits• Sun Wireless Toolkit 2.3 Beta (WTK)• Carbide (formerly Nokia Developer Suite)• Siemens Mobile Toolkit 3.0 (SMTK)• Motorola iDEN SDK for J2ME (MSDK)

Integrated Developement Environments (IDE)• EclipseME 1.1.0• Sun NetBeans5.0 Mobility Pack5.0 (NMP)• JBuilder 2005 MobileSet3.0.1

Dr. Thomas Springer 30Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 31: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Application Development for mobile devices with Java

Several Platforms specified• CDC development similar to Java SE• CLDC development varies significantly

Pro:• Configurable platform• Supports large variety of mobile devices• Java development and portability• Web Service support

Contra:• Limited portability cased by large variety of configurations,

profiles and optional packets• Lowest common denominator approach limites use of device

features

Dr. Thomas Springer 31Application Development - Lecture 9. Platforms - Java ME and OSGi

Java ME Summary

Page 32: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

OSGI

Page 33: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

OSGi - Overview

OSGi = Open Service Gateway InitiativeFounded in 1999Large consortium, BMW, GermanTelecom, IBM, Siemens, VW

Definition of a specification of a open,standardized, component-based serviceplatform

Initial Application Domains• home and building automation• telematic platform

Increasing number of application areas• application platform for mobile devices• platform for dekstop applications (e.g. Eclipse)• embedded systems, e.g. entertainment systems by Philips

Dr. Thomas Springer 33Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 34: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

What is OSGi

Local component plattform based on Java• bundles as components• runtime environment for bundles• allows multiple applications running

on one Java VM• sharing of components and resources

between applications

Additional Features on top of Java Platform• management of bundle-lifecycle at

runtimeo Installation, Start, Stop, Update,

Deinstallation of Bundles• Provision of basic services• Service registry• Dynamic deployment and binding for

bundles• Remote bundle management (Remote

Management Architecture)• Packet and version management

Dr. Thomas Springer 34Application Development - Lecture 9. Platforms - Java ME and OSGi

Operating System

Java VM

Base Services

Service Registry

Life Cycle

Class Loading

Applications/Bundles

Page 35: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Overview about OSGi Components

Components in OSGi are calledBundles• interface definition• java classes and further

resources• bundle description - manifest

file

Unit of composition is serviceUnit of deployment is bundle

Bundle compiled into JAR• Class files• resources• Manifest

o describes contents of JARo deployment information, e.g.

import and export of javapackages for shared use

o Description of dependencies

OSGi Framework

Bundle A{…}

= service, defined by java interface

Bundle B{…}

Bundle C{…}

= bundle

Page 36: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

OSGi – Bundle dependencies

The dependencies of a bundle are:• Package dependencies,• Service dependencies, and• Runtime environment dependencies.

bundle

bundle

bundle

bundle

bundle

Dr. Thomas Springer 36Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 37: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

OSGi – Package Dependencies

Dependencies are defined through the manifest file• Import-Package:

org.osgi.framework• Export-Package:

de.vpe.firstserviceThe framework resolves these dependencies, statically, before starting the bundle.• This is the difference between

INSTALLED and RESOLVED states.

Bundle AExport org.osgi.service.log

com.ibm.service.logcom.ibm.j9

Import org.osgi.service.httpjavax.servlet.http

Frameworkorg.osgi.frameworkorg.osgi.service.http

Bundle BExport ericsson.osgi

javax.servletjavax.servlet.httporg.osgi.service.log

Import org.osgi.service.http

Dr. Thomas Springer 37Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 38: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

OSGi – Bundle Dependencies

Service Dependencies• The dependencies are expressed by bundle to service.• The dependencies can be declared in the manifest file.• A bundle manages dynamic connections between services.• At any time a bundle may display/remove a service interface or

require/release the use of a service interface.• The OSGi specification does not mention if every service must

handle the complexity about the dynamic addition or removal of external services.

Run-time Environment Dependencies• The framework commonly publishes events associated with:

o Insertion of a new bundle, oro Publication of a new service.

• Bundles constantly keep listening to these events.• Can take appropriate actions whenever an event happens.

Dr. Thomas Springer 38Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 39: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Bundle – Lifecycle

Bundle lifecycle managed by OSGi runtime environmentBundles my be installed and updated anytime

Install

• Evaluation of manifest file

• Checking availability of bundle classes and resources

• Persistent saving

Resolve

• Resolution of static dependencies to external bundles and java packages

Uninstall

• Must take place explicitly through the OSGi platform

• Removal of all persistently saved parts of the bundle

Dr. Thomas Springer 39Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 40: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Example Bundle

1. Step:Service Interface

package Connector;public interface ConnectorService {

public String request(String url,char type,int flnr,int snr,String name, boolean s,boolean sdc,boolean w, boolean wdc);

}

Dr. Thomas Springer 40Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 41: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Example Bundle Implementation

2. Step: Implementationof Service Interface in Java Class

package Connector;import java.io.IOException;import Connector.EndToEndClient;public class ConnectorServiceImpl implements ConnectorService{

EndToEndClient client;

public String request(String url, char type,int flnr,int snr,String name,booleans,boolean sdc,boolean w, boolean wdc) {

client = new EndToEndClient(url);String FlightRequest_returnValue="";try {

FlightRequest_returnValue = client.ejb_OfficeServlet_processFlightRequest(

type,flnr,snr,name,s,sdc,w,wdc);} catch (IOException e) {

e.printStackTrace();}return(FlightRequest_returnValue);

}}Dr. Thomas Springer 41Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 42: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Example Bundle

3.Step:Manifest

Manifest-Version: 1.0

Bundle-Name: Connector

Bundle-Activator: Connector.Activator

Bundle-SymbolicName: Connector

Bundle-ClassPath: /j2me.jar,.

Bundle-Version: 1.0

Export-Package: Connector, ConnectorService

exports packets Connector, ConnectorService to be availablefor other bundles

Dr. Thomas Springer 42Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 43: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

package Connector;import org.osgi.framework.BundleActivator;import org.osgi.framework.BundleContext;import org.osgi.framework.Constants;import org.osgi.framework.ServiceRegistration;

public class Activator implements BundleActivator {public static BundleContext bc=null;

public void start(BundleContext bc) throws Exception {System.out.println(bc.getBundle().getHeaders().get(Constants.BUNDLE_NAME)+" starting...");

Activator.bc=bc;ConnectorService connect=new ConnectorServiceImpl();ServiceRegistration registration=bc.registerService(

ConnectorService.class.getName(), connect, new Hashtable());System.out.println("Service registered: ConnectorService");

}

public void stop(BundleContext bc) throws Exception {System.out.println(bc.getBundle().getHeaders().get(

Constants.BUNDLE_NAME)+" stopping...");Activator.bc=null;

}}

Example Bundle

4. Step:Bundle-Activator

Dr. Thomas Springer 43Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 44: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

OSGi – Assemblage

At a given point in time, an OSGi system looks like the figure below:

Dr. Thomas Springer 44Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 45: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Overview of Service Registry

Dr. Thomas Springer 45Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 46: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

package Client;import org.osgi.framework.BundleActivator;import org.osgi.framework.BundleContext;import org.osgi.util.tracker.ServiceTracker;import org.osgi.util.tracker.ServiceTrackerCustomizer;import Connector.ConnectorService;public class Activator implements BundleActivator {

public static BundleContext bc=null;public ServiceTrackerCustomizer customizer;public ServiceTracker tracker;public FlightBookingClient fbc=null;

public void start(BundleContext bc) throws Exception {Activator.bc=bc; fbc=new FlightBookingClient();customizer=new MyServiceTrackerCustomizer(bc,fbc);tracker=new ServiceTracker(bc,ConnectorService.class.getName(),customizer);tracker.open();

}

public void stop(BundleContext bc) throws Exception {this.tracker.close();this.customizer=null;

this.tracker=null; Activator.bc=null;}

}

Example Bundle – Importing a service

Dr. Thomas Springer 46Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 47: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

package Client;import org.osgi.framework.BundleContext;import org.osgi.framework.ServiceReference;import org.osgi.util.tracker.ServiceTrackerCustomizer;import Connector.ConnectorService;public class MyServiceTrackerCustomizer implements ServiceTrackerCustomizer{

private BundleContext bc=null; private FlightBookingClient fbc=null;

public MyServiceTrackerCustomizer(BundleContext bc,FlightBookingClient fbc){this.bc=bc; this.fbc=fbc;

}public Object addingService (ServiceReference reference) {

ConnectorService connect=(ConnectorService)bc.getService(reference);fbc.handservice(connect);fbc.getSendRequestButton().setEnabled(true);fbc.getResultArea().setText("");return connect;

}public void modifiedService (ServiceReference reference, Object service) {

ConnectorService connect=(ConnectorService)bc.getService(reference);fbc.handservice(connect);

}public void removedService (ServiceReference reference, Object service) {

fbc.getSendRequestButton().setEnabled(false);fbc.getResultArea().setText("Der Service ist zur Zeit nicht verfügbar!");ConnectorService connect=null;fbc.handservice(connect);

}}

If tracked service is registered bind to service

rebind if tracked service is modified

unbind if tracked service is deregistered

Page 48: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Service registryLifecycle management

Log Service (message logging)HTTP ServiceUPnP ServiceEvent Admin ServiceMonitoring ServiceService TrackerXML ParserIO Connector Service (basic comm. Infrastructure)

Dr. Thomas Springer 48Application Development - Lecture 9. Platforms - Java ME and OSGi

OSGi Plaform Services

Page 49: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

OSGi Platforms

Open Source• Equinox (Eclipse's OSGi console)• Apache Felix• Knopflerfish• Oscar

Commercial• mbedded Server (Prosyst)• AveLink (Atinav)• Service Management Framework (IBM)

Extensions• R-OSGi (ETH Zurich, Swiss)

o provides a transparent way to access services on remote OSGiplatforms

• SFelix (INRIA, France)o secure Version of Felix o supports the publication of signed bundles

Dr. Thomas Springer 49Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 50: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Example Equinox (Eclipse's OSGi console)

Dr. Thomas Springer 50Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 51: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Example Equinox (Eclipse's OSGi console)

Dr. Thomas Springer 51Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 52: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Example Knopflerfish

Dr. Thomas Springer 52Application Development - Lecture 9. Platforms - Java ME and OSGi

Page 53: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Local, component-based Platform

Unique features• Multiple applications in one Java Environment• Configurable framework with services as bundles• Dynamic installation, update and discovery of bundles

Application areas• Home automation• Embedded systems• Mobile applications

Dr. Thomas Springer 53Application Development - Lecture 9. Platforms - Java ME and OSGi

OSGi Summary

Page 54: Application Development for Mobile and Ubiquitous Computing 5. …ts2/admuc/lecture0910/9... · 2010. 1. 15. · Midlet Descriptions Manifest • Part of .jar file • Contains information

Java ME• http://java.sun.com/javame/index.jsp• http://today.java.net/pub/a/today/2005/02/09/j2me1.ht

ml• http://developers.sun.com/learning/javaoneonline/j1onli

ne.jsp?track=4&yr=2007

OSGi• http://www.osgi.org/• http://wiki.easybeans.org/xwiki/bin/pdf/Main/OSGi• http://www.osgi.org/documents/• http://www.knopflerfish.org/osgi_service_tutorial.html• http://www.aqute.biz/OSGi/Tutorial• http://felix.apache.org/site/apache-felix-osgi-

tutorial.html

References

Dr. Thomas Springer 54Application Development - Lecture 9. Platforms - Java ME and OSGi