Review: OSGi – a component framework for Java Bundle OSGi Framework Bundle Java Runtime Environment (JRE) Operating System (OS) Hardware “Dynamic Modules.

Slides:



Advertisements
Similar presentations
Testing Relational Database
Advertisements

AQute R4 By Peter Kriens CEO aQute OSGi Technology Officer and OSGi Fellow.
CPSC 875 John D. McGregor Architecture evolution.
10 Software Engineering Foundations of Computer Science ã Cengage Learning.
Component Models and Technologies Case Study: OSGI.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Architectural Modeling Notations.
Why OSGi matters for Enterprise Java Infrastructures
Packages and Class Visibility The objectives of this chapter are: To understand logical class groupings using packages To explain the environment variable.
Development Processes UML just is a modeling technique, yet for using it we need to know: »what do we model in an analysis model? »what do we model in.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Chapter 23: ARP, ICMP, DHCP IS333 Spring 2015.
Unit 051 Packages What is a Package? Why use Packages? Creating a Package Naming a Package Using Package Members Managing Source and Class Files Visibility.
Spring Dynamic Modules. Startlocation: Documentation: /1.2.1/reference/html/
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
 Proteus Framework Redefining the plugin. Why a new framework?  Present approaches (e.g. OSGi) use non-standard approaches that create too many breaking.
IBM Proof of Technology Discovering the Value of SOA with WebSphere Process Integration © 2005 IBM Corporation SOA on your terms and our expertise WebSphere.
Access Control Problem A primary consideration in object- oriented design is to “separate the things that change from the things that stay.
Lecture Roger Sutton CO530 Automation Tools 5: Class Libraries and Assemblies 1.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
OSGi.
1/151/15 ENT Metamodel Implementation & Applications ENT metamodel, prototype implementation Component substitutability checking, ENT based component comparison.
.NET Framework & C#.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics NPRG044: OSGi framework Michal Malohlava & Pavel Parízek
Implementation Yaodong Bi. Introduction to Implementation Purposes of Implementation – Plan the system integrations required in each iteration – Distribute.
CS378 - Mobile Computing Intents.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Comparing JavaBeans and OSGi Towards an Integration of Two Complementary Component Models HUMBERTO CERVANTES JEAN-MARIE FAVRE 09/02.
Object-Oriented Modeling Chapter 10 CSCI CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
OSGi Enablement for Tuscany Raymond Feng. Overview.
In Pieces Breaking down monolithic applications with Spring-DM and OSGi.
Migrating Desktop The graphical framework for running grid applications Bartek Palak Poznan Supercomputing and Networking Center The.
OSGi Service Platform Open Service Gateway initiative.
Open Service Gateway Initiative (OSGi) Reporter : 林學灝 侯承育 1.
Kuali Enterprise Workflow Kuali Days – November 2008 Scott Gibson, University of Maryland Bryan Hutchinson, Cornell University James Smith, University.
CPSC 875 John D. McGregor Architecture evolution.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering.
Plug-in Architectures Presented by Truc Nguyen. What’s a plug-in? “a type of program that tightly integrates with a larger application to add a special.
INFO 620Lecture #71 Information Systems Analysis and Design Design Class Diagrams and others INFO 620 Glenn Booker.
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
Programming in java Packages Access Protection Importing packages Java program structure Interfaces Why interface Defining interface Accessing impln thru.
Identifying classes, Packages and drawing class Diagrams, Object Diagrams and composite structure diagrams Week 07 1.
Win32 Programming Lesson 19: Introduction to DLLs.
Staffordshire UNIVERSITY School of Computing Version Jan 08 original by K.Ingram & J.Westlake1 Special Relationships between Use Cases Normally it is not.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Introduction to OSGi +ActorFrame Surya Bahadur Kathayat
Windows 2003 Architecture, Active Directory & DNS Lecture # 3 Hassan Shuja 02/14/2006.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
CPSC 875 John D. McGregor C22 - Architecture evolution.
1 An SDL Tutorial Two primary elements: –Structure –Identifies the various components of the system, and the communication paths among them. –Components:
Software Modelling Class Diagram. Class Diagrams The main building block in object oriented modeling They are used both for general conceptual modeling.
Data Abstraction: The Walls
OSGi: The Lifecycle Layer. The Extender Pattern
Chapter 3: Using Methods, Classes, and Objects
Software Life Cycle Models
Introduction to J2EE Architecture
CS212: Object Oriented Analysis and Design
Packages and Interfaces
Objectives In this lesson you will learn about: Need for servlets
CISC124 Assignment 4 on Inheritance due next Friday.
Enterprise Java Beans.
Software Testing.
Design Yaodong Bi.
Presentation transcript:

Review: OSGi – a component framework for Java Bundle OSGi Framework Bundle Java Runtime Environment (JRE) Operating System (OS) Hardware “Dynamic Modules for Java”

Review: OSGi Layered Architecture Each layer depends on the layers beneath it (It is possible to use lower OSGi layers without using upper ones, but not vice versa) Bundles are the unit of modularity. They further have an associated life cycle and are the providers of services. Service Lifecycle Modularity Execution Environment HW / OS Bundles

OSGi: The Modularity Layer

Reading Ch.1: OSGi revealed Ch 2: Mastering modularity Ch 3: Learning lifecycle Ch 4: Studying services Ch 11: Component models and frameworks

Logical vs Physical Modularity Logical modularity refers to a form of code visibility. A module defines a logical boundary in your application, which impacts code visibility in a fashion similar to access modifiers Physical modularity refers to how code is packaged and/or made available for deployment. Physical modules are sometimes also referred to as deployment modules or deployment units. In general, a physical module is not necessary equal to a logical module: it’s possible to have logical modularity without physical modularity or to package multiple logical modules into a single physical module

Limitations of Java Modularity 1.Low-level control of code visibility 2.Limited deployment and management support – The classpath problem

Limitations of Java Modularity (1) Low-level code visibility control What are Java modules ? Packages, jars ? Packages are in general too finegrained to be considered modules A module would be of a size of a group of packages (maybe in a jar – or not) Problem with this: –No relationships are defined between packages –jar files by themselves provide no visibility scoping. All the public classes in implementation packages are visible to everyone, not only to the other packages forming the module

Limitations of Java Modularity (2) The classpath problem

The “class path hell” arises when more than one JAR file provides a given set of classes Example scenario: –The jar file A.jar has a class pack.a.Test that needs pack.lib.Util. During testing it was compiled against this class in Lib.jar at version –However, during deployment the class is provided by the first jar found on the classpath that contains pack/lib/Util.class. –The class carries no version information, so there is no way to diagnose problems around using that class ! –The jar file also contains no version information, so even if the class came from Lib.jar it might be the wrong one (version 1.1.0) ! –This problem can be especially hard to diagnose when an OtherLib only accidentally contains pack.lib.Util where its primary classes it is meant to provide are in another package such as pack.other.

OSGi Modularity In OSGi, logical modularity is synonymous with physical modularity: both the logical module and the physical module is referred to as a bundle

OSGi Bundles A Bundle is: “ A physical unit of modularity in the form of a JAR file containing code, resources, and metadata, where the boundary of the JAR file also serves as the encapsulation boundary for logical modularity at execution time”.

Bundle’s role in logical modularity Packages (and therefore the classes in them) contained in a bundle are private to that bundle unless explicitly exported Only explicitly exported packages can be imported (used) by other bundles Bundles extend standard Java access modifiers with module private visibility (only visible in the module)

OSGi Bundle Metadata Metadata are contained in the Manifest file The OSGI manifest extends the classical jar file manifest The OSGI-related metadata contains the following categories of information about the bundle: –Human-readable information—Optional information intended purely as an aid to humans who are using the bundle –Bundle identification—Required information to identify a bundle –Code visibility—Required information for defining which code is internally visible and which internal code is externally visible

Bundle Manifest Example Bundle-ManifestVersion: 2 Bundle-Name: Hello Bundle-Description: A Greeting Bundle Bundle-Vendor: FooProducer Bundle-SymbolicName: org.foo.hello Bundle-Version: qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Export-Package: org.foo.hello Import-Package: org.osgi.framework;version="1.5.0" Bundle-Activator: org.foo.hello.Activator Human- readable info Bundle identificat ion Code visibility

Bundle Metadata: (1) Human-readable information the OSGi framework ignores this part, it is just for humans. Examples: –Bundle-Name –Bundle-Description –Bundle-Vendor –Bundle-Copyright

Bundle Metadata: (2) Bundle Identification Examples: –Bundle-SymbolicName: helps the OSGi framework to uniquely identify a bundle –Bundle-Version: an OSGI version-number, is taken together with the symbolic name for bundle identification

Bundle Metadata: (3) Code Visibility Internal bundle class path— bundle class path is a list of locations to search for classes. The difference from java class path is that the bundle class path refers to locations inside the bundle JAR file. –Bundle-ClassPath has a default value of. meaning that classes are searched in the root of the bundle jar file Exported internal code—Explicitly exposed code from the bundle class path for sharing with other bundles Imported external code—External code on which the bundle class path code depends

Bundle Metadata: Code Visibility – Exported code Export: Bundles may export packages Exported packages form the bundle's API Packages that not exported are private Packages are exported with their name and an optional version number (packages are versioned independently) Examples: –Export-Package: org.foo.hello –Export-Package: org.foo.hello, org.foo.other –Export-Package: org.foo.hello, org.foo.other; version=“2.0.0” You can also attach attributes to exported packages. Because it’s possible for different bundles to export the same packages, a given bundle can use custom attributes to differentiate its exports from other bundles. For example: –Export-Package: org.foo.hello, org.foo.other; vendor=“Manning”

Bundle Metadata: Code Visibility – Imported code Code is imported in form of: –Imported packages Bundles may use packages exported packages only if they explicitly import them using the package name Each import may be qualified with a version or a version range –Import-Package: org.osgi.framework; version="1.3.0“ –Import-Package: org.osgi.framework; version="[1.3.0,2.0.0)“ –Import-Package: org.foo.hello; vendor=“Manning” –Required bundles Bundles may specify a dependency on entire bundles Simplifies imports, but it is highly NOT recommended ! Better: “Depend on packages, not on bundles”

OSGi Class Search Order When a bundle needs a class at execution time, the framework searches for the class in the following order: 1.If the class is from a package starting with java., the parent class loader is asked for the class. If the class is found, it’s used. If there is no such class, the search ends with an exception. => ensures all bundles use the same core Java 2.If the class is from a package imported by the bundle, the framework asks the exporting bundle for the class. If the class is found, it’s used. If there is no such class, the search ends with an exception. => ensures that imported packages are not split 3.The bundle class path is searched for the class. If it’s found, it’s used. If there isno such class, the search ends with an exception.

OSGi Import-Package vs. Java import They serve different purposes: –The import keyword in Java is for namespace management: it allows you to use the short name of the imported classes instead of using its fully qualified class name the import statement itself doesn’t grant any visibility. you do not need to use import, because you can always use the fully qualified class name instead. –For OSGi, the metadata for importing external code is important, because it’s how the framework knows what your bundle needs.

Resolving dependencies automatically One of the most important tasks performed by the OSGi framework is automating dependency management, which is called bundle dependency resolution. A bundle’s dependencies must be resolved by the framework before the bundle can be used The OSGi framework uses a sophisticated dependency resolution algorithm

Resolving a Bundle RESOLVING = The process of matching a bundle’s imported packages to exported packages from other bundles and doing so in a consistent way so any given bundle only has access to a single version of any type. Resolving a bundle may cause the framework to resolve other bundles transitively, if exporting bundles themselves haven’t yet been resolved. The resulting set of resolved bundles are conceptually wired together If any dependency can’t be satisfied, then the resolve fails, and the instigating bundle can’t be used until its dependencies are satisfied.

Resolving dependencies The priority of dependency resolution candidate selection: –Highest priority is given to already-resolved candidates, where multiple matches of resolved candidates are sorted according to version and then installation order. –Next priority is given to unresolved candidates, where multiple matches of unresolved candidates are sorted according to version and then installation order. The resolve process is incremental ! –Dependencies are resolved taking into account the bundles that are installed at the moment –Bundles may be installed at any later moment – this may reset the resolve algorithm !

Consistency The dependencies are resolved in a consistent way if any given bundle only has access to a single version of any package. The bundle’s class space = its imported packages plus the packages accesible from its bundle classpath In order to be able to ensure consistency, sometimes uses contraints are necessary to be specified –The following example scenario illustrates this

Example package org.osgi.service.http; import javax.servlet.Servlet; public interface HttpService { void registerServlet(Sting alias, Servlet servlet, HttpContext ctx); } 1. Initial situation: two bundles installed and resolved

Example contd. The incremental dependency resolution leads to a situation that is NOT CONSISTENT ! The class spaces of the HTTP Client and HTTP service bundles are not consistent, since two different versions of javax.servlet.Servlet are reachable ! 2. Follow up: two more bundles are installed:

Example contd. 3. Solution: specifying intra-bundle dependencies The Uses Directive = A directive attached to exported packages whose value is a comma-delimited list of packages exposed by the associated exported package. It constrains the choices of the framework when resolving dependencies ! Export-Package: org.osgi.service.http; uses:="javax.servlet"; version="1.0.0" Import-Package: javax.servlet; version="2.3.0"

Example contd. For the incremental case, the framework can now detect inconsistencies in the class spaces, and resolution fails when you try to use the client bundle. Early detection is better than errors at execution time, because it alerts you to inconsistencies in the deployed set of bundles. The framework can be requested to re-resolve the bundle dependencies to remedy this situation 4. Resolution with Uses contraints:

Example contd. 5. Consistent resolution:

Summary Modularity is a form of separation of concerns that provides both logical and physical encapsulation of classes. Bundle is the name for a module in OSGi. It’s a JAR file containing code, resources, and modularity metadata. Modularity metadata details human-readable information, bundle identification, and code visibility. Bundle code visibility is composed of an internal class path, exported packages, and imported packages. The OSGi framework uses the metadata about imported and exported packages to automatically resolve bundle dependencies and ensure type consistency before a bundle can be used. Imported and exported packages capture inter-bundle package dependencies, but uses constraints are necessary to capture intra- bundle package dependencies to ensure complete type consistency.