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

Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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

Application Development for Mobile and Ubiquitous Computing

8. Platforms – Java ME and OSGi

Dr. Ing. Thomas Springer Technische Universität Dresden

Chair of Computer Networks

Page 2: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Lecture Structure

Dr. Thomas Springer Slide 2 Application Development - 8. Platforms - Java ME and OSGi

Adaptation and

Context-

awareness

Mobile Internet

Mobile Middleware

Application Development

Enabling Technologies and Challenges

Disconnected

Operations

Mobile

Databases

Location-

based

Services

Communication

Mechanisms

Android iOS

.Net Compact

Framework/

Windows

Phone 7

Java ME OSGi

Cross-Platform Development

Page 3: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Structure

Java ME

OSGi

Android

iOS

Windows Phone 7

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

Page 4: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

iOS accounts for more than half of the visits to Net Applications clients' 40,000 websites

Android, with 16.26%, is still trailing Java ME's 18.52%

Research in Motion's (RIMM) is holding steady at 3.29%

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

Mobile OS market share

Page 5: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

JAVA MICRO EDITION

Page 6: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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

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

Page 7: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Application Domains of Java ME

Designed for devices with restrictions concerning processor power, memory, display size and networking capabilities

Heterogeneous requirements for Java ME devices

• Personal, mobile, networked devices

o Mobile phones, PDA`s, Smart phones, pagers

o Characteristics: • Simple User Interfaces • Memory capacity: 128 – 512 kb • Wireless network connection (low bandwidth)

• Commonly used, stationary, networked devices

o 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 7 Application Development - 8. Platforms - Java ME and OSGi

Page 8: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 8 Application Development - 8. Platforms - Java ME and OSGi

Page 9: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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, no Introspection)

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 9 Application Development - 8. Platforms - Java ME and OSGi

Modular Architecture- Details

Page 10: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Configurations

Configuration defines

• language support of Java

• functionality of Virtual Machine (VM)

• basic programming libraries

o Usually subset of Java SE used

o 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 10 Application Development - 8. Platforms - Java ME and OSGi

Page 11: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Connected Device Configuration (CDC)

• 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 packets

o No graphical user interfaces possible

• Personal Basis Profile 1.1 (JSR-217)

o Graphical User Interfaces by subset of AWT

o 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 AWT

o including Heavy Weight components (Buttons, Lists)

Configurations - CDC

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

Page 12: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Connected Limited Device Configuration (CLDC)

• Currently available in Version 1.1 (JSR-139)

• Kilo Virtual Machine

o goal: 160 – 512 kb memory used

o Subset of Java VM features

- no floating point arithmetic (no float and double) (available for CLDC 1.1)

- no native functions (JNI)

- no user defined class loaders

- no introspection (no serialization, no RMI)

- no Thread groups and daemon threads

- limited Garbage Collector

• Characteristics

o Less powerful CPUs with 16-32 Bit

o Low memory resources: 192-512 k byte

o Short battery life time

o Low transmission data rates -> no permanent network connection

o Minimal operating system for managing hardware

Configurations - CLDC

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

Page 13: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Profiles of CLDC

Mobile Information Device Profile (MIDP) • Timer (delay of activities)

• Network connection by Generic Connection Framework (GCF)

• Persistent memory (Record Management System) o Mini database organized as record store

o Data operations (add, change, delete of records)

o Record store assigned to applications

• Application development o Generation of MIDlet-Suites

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

• Security o Trusted MIDlet Suites (MIDP 2.0)

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

Page 14: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Midlets are basic abstraction for application

• Lifecycle managed by Application Management Software (AMS) on mobile device

• Deployed as Midlet Suites

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

CLDC Application Development

Page 15: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

MIDP Applications (2)

MIDlet-Suites are running in a life cycle Installation, application cycle, de-installation Application 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 15 Application Development - 8. Platforms - Java ME and OSGi

Page 16: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

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

// Constructor – invocation of method initialize

public Flightbookingsystem() {

initialize();

}

public void startApp() {

}

public void pauseApp() {

}

public void destroyApp(boolean unconditional) {

}

}

MIDlet – Basic Structure

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

Page 17: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 17 Application Development - 8. Platforms - Java ME and OSGi

Page 18: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 • Low-level API

o 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

• High-level API o Elements for abstract form-based UI elements (button, textbox, date

field)

o abstract UI elements mapped to native elements

o High portability

o 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

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

Page 19: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

MIDP classes for GUI creation

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

Page 20: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

LCDUI - Example

Usage of High-Level API

Set display to main menu during initialization of MIDlet

For 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 20 Application Development - 8. Platforms - Java ME and OSGi

Page 21: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 21 Application Development - 8. Platforms - Java ME and OSGi

Page 22: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 22 Application Development - 8. Platforms - Java ME and OSGi

Page 23: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 class

o Connection provides homogeneous interface for accessing all types of connections

o particular connection/protocol implementation is subclass of Connection

Midlet network communication

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

Page 24: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Generic Connection Framework (2)

Mandatory

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

Page 25: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 HttpConnection

HTTPS https://java.sun.com HttpsConnection

Sockets (TCP) socket://time-a.nist.gov:13 SocketConnection

Serial comm:0;baudrate=2400; CommConnection

Datagrams (UDP) datagram://127.0.0.1 UDPDatagramConnection

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

Page 26: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 26 Application Development - 8. Platforms - Java ME and OSGi

Page 27: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 27 Application Development - 8. Platforms - Java ME and OSGi

Page 28: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

RMS – Example

// Create record store if it does not exist

RecordStore rs = RecordStore.openRecordStore(REC_STORE, true);

// read record

// Allocate space to hold each record

byte[] recData = new byte[50];

// Get data into the byte array

rs.getRecord(id, recData, 0);

//write record

// Write data into an internal byte array

ByteArrayOutputStream strmBytes = new ByteArrayOutputStream();

// Get stream data into byte array and write record

byte[] record = strmBytes.toByteArray();

rs.addRecord(record, 0, record.length);

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

Page 29: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

MIDP2.0 Security (1)

Concept of Trusted MIDlet-Suites

Check 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 30: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 30 Application Development - 8. Platforms - Java ME and OSGi

Page 31: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

OTA User Initiated Provisioning

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

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

Page 32: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Java ME - Integration

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

[Ref: java.sun.com]

Page 33: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Development Tools

Toolkits

• Oracle Java ME SDK 3.0

• Nokia SDK for Java

• MOTODEV Studio and SDK for Java ME

Integrated Developement Environments (IDE)

• Eclipse Mobile Tools for Java

• NetBeans IDE (Mobile and Embedded Applications)

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

Page 34: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Application Development for mobile devices with Java

Several Platforms specified

• CDC development similar to Java SE

• CLDC development varies significantly

Pro:

• Open, 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 34 Application Development - 8. Platforms - Java ME and OSGi

Java ME Summary

Page 35: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

OSGI

Page 36: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

OSGi - Overview

OSGi = Open Service Gateway Initiative Founded in 1999 Large consortium, BMW, German

Telecom, IBM, Siemens, VW

Definition of a specification of a open, standardized, component-based service platform

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 36 Application Development - 8. Platforms - Java ME and OSGi

Page 37: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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

runtime o 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 37 Application Development - 8. Platforms - Java ME and OSGi

Operating System

Java VM

Base Services

Service Registry

Life Cycle

Class Loading

Se

cu

rity

Applications/Bundles

Page 38: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Overview about OSGi Components

Components in OSGi are called Bundles • interface definition • java classes and further

resources • bundle description - manifest

file

Unit of composition is service Unit of deployment is bundle

Bundle compiled into JAR

• Class files • resources • Manifest

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

import and export of java packages for shared use

o Description of dependencies

OSGi Framework

Bundle A

{…}

= service, defined by

java interface

Bundle B

{…}

Bundle C

{…}

= bundle

Page 39: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 39 Application Development - 8. Platforms - Java ME and OSGi

Page 40: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

OSGi – Package Dependencies

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

org.osgi.framework • Export-Package:

de.vpe.firstservice

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

INSTALLED and RESOLVED states.

Bundle A

Export org.osgi.service.log

com.ibm.service.log

com.ibm.j9

Import org.osgi.service.http

javax.servlet.http

Framework

org.osgi.framework

org.osgi.service.http

Bundle B

Export ericsson.osgi

javax.servlet

javax.servlet.http

org.osgi.service.log

Import org.osgi.service.http

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

Page 41: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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, or o Publication of a new service.

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

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

Page 42: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Bundle – Lifecycle

Bundle lifecycle managed by OSGi runtime environment

Bundles 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

Installed

install

Resolved

resolve update

Uninstalled

uninstall

update

Started

Active

Stopped

start

stop

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

Page 43: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 43 Application Development - 8. Platforms - Java ME and OSGi

Page 44: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Example Bundle Implementation

2. Step: Implementation of Service Interface in Java Class

package Connector;

import java.io.IOException;

import Connector.EndToEndClient;

public class ConnectorBundle implements ConnectorService{

EndToEndClient client;

public String request(String url, char type,int flnr,int snr,String name,boolean

s,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 44 Application Development - 8. Platforms - Java ME and OSGi

Page 45: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Example Bundle

3.Step:

Manifest Manifest-Version: 1.0

Bundle-Name: ConnectorBundle

Bundle-Activator: Connector.Activator

Bundle-SymbolicName: Connector

Bundle-ClassPath: /j2me.jar,.

Bundle-Version: 1.0

export-Package: Connector

exports package Connector containing ConnectorBundle, Activator and ConnectorService to be available for other bundles

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

Page 46: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 ConnectorBundle();

ServiceRegistration registration=bc.registerService(

ConnectorService.class.getName(), connect, new Hashtable());

System.out.println("Service registered: Connector.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 46 Application Development - 8. Platforms - Java ME and OSGi

Page 47: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

OSGi – Assemblage

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

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

Page 48: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

OSGi Service Registry

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

Service Registry

ConnectorBundle

(Bundle providing a service)

Activator of bundle

using a service

Connector.ConnectorService Service properties

Activator

create

instance

ServiceRegistration(getReference, setProperties,

unregister)

register Service

1

2

3

Activator of bundle using

a service

getServiceReference

getService(reference)

... ... ...getServiceReference

getService(reference)

4

ServiceReference

ServiceReference

Page 49: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 49 Application Development - 8. Platforms - Java ME and OSGi

Page 50: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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(„Service is currently not available!");

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 51: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Service registry

Lifecycle management

Log Service (message logging)

HTTP Service

UPnP Service

Event Admin Service

Monitoring Service

Service Tracker

XML Parser

IO Connector Service (basic comm. Infrastructure)

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

OSGi Plaform Services

Page 52: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 OSGi platforms

• SFelix (INRIA, France)

o secure Version of Felix

o supports the publication of signed bundles

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

Page 53: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Example Equinox (Eclipse's OSGi console)

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

Page 54: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Example Equinox (Eclipse's OSGi console)

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

Page 55: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

Example Knopflerfish

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

Page 56: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

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 56 Application Development - 8. Platforms - Java ME and OSGi

OSGi Summary

Page 57: Application Development for Mobile and Ubiquitous ...ts2/admuc/lecture1112/8. Platfor… · Department of Computer Science Institute for System Architecture, Chair for Computer Networks

References

Java ME

• http://java.sun.com/javame/index.jsp

• http://today.java.net/pub/a/today/2005/02/09/j2me1.html

• http://developers.sun.com/learning/javaoneonline/j1online.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

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