SlideShare ist ein Scribd-Unternehmen logo
1 von 88
Introduction to OSGi
Sameera Jayasoma
Technical Lead and Product Manager
WSO2 Inc.
The Dynamic Module System for Java
Pradeep Fernando
Software Engineer
WSO2 Inc.
WSO2
 Founded in 2005 by pioneers in XML and Web services technologies &
standards as well as open source.
 Founders & leading contributors to all key Apache Web services projects.
 Offering complete SOA platform, 100% free and open source.
 Business model based on providing training, consultancy and support for
the software.
 Global corporation with R&D center in Sri Lanka and offices in US & UK.
Modular Systems..
Modular Systems
 No doubt, a computer is complex system.
 How do you handle this complexity, when designing large systems?
Modular Systems
 Break the large system into more
smaller, understandable units
 These small units are called modules.
 Benefits of modular systems
 Reuse
 Abstraction
 ..
Modular Systems
 Same theories can be applied to the software world also.
 Dividing a complex software system into small parts/modules.
•Allows us to understand the system easily.
•Allows us to develop part by part by different team.
•Allows us to reuse already developed modules.
 Does Java supports building true modular systems?
Java for building modular systems..
Java for Modular Systems
 Java is one of the popular OOP languages for
developing large enterprise applications.
 Java provides some level of modularity.
 Consider a Java class
•The unit of information hiding in Java.
•Public methods, expose a defined contract.
Class Loading
 In a standard Java application.
JAR Files
 JAR is unit of deployment in Java.
 Typical Java application consists a set of JAR files.
 At runtime contents of all JAR files are treated as a single, ordered and global list
which is called the class path
 Consider the following command.
java -classpath log4j.jar:statx-
api.jar:woodstox.jar:axis2.jar:
carbon.jar:utils.jar:target/classes
org.sample.HelloWorld
org/sample/HelloWorld
....
org/wso2/carbon/utils/CarbonUtils
....
org/wso2/carbon/core/Activator
....
org/apache/axis2/AxisFault
....
com/ctc/wstx/api/ReaderConfig
....
javax/xml/stream/XMLStreamReader
....
JAR Files and Class Loading
org/apache/log4j/Appender
....
Search order
log4j.jar
stax-
api.jar
woodstox.ja
r
axis2.jar
carbon-
core.jar
carbon-
utils.jar
target/clas
ses
org/sample/HelloWorld
....
org/apache/log4j/Appender
.... log4j-
2.0.jar
org/wso2/carbon/utils/CarbonUtils
....
org/wso2/carbon/core/Activator
....
org/apache/axis2/AxisFault
....
com/ctc/wstx/api/ReaderConfig
....
javax/xml/stream/XMLStreamReader
....
org/apache/log4j/Appender
.... log4j-
1.0.jar
stax-
api.jar
woodstox.ja
r
axis2.jar
carbon-
core.jar
carbon-
utils.jar
target/clas
ses
 HelloWorld class has a
dependency on log4j version
2.0.
 What version of the
Appender class is loaded?
Depends on log4j 2.0
version
JAR Files and Class Loading
Search order
Problem with JARs
 No runtime representation
 Multiple versions of JAR files cannot be loaded simultaneously
 A JAR cannot declare dependencies on other JARs.
 No mechanism for information hiding
 Hence, JARs cannot be considered as modules
Java for Modular Systems
 Can you update a part(can be a JAR file) of a running Java application?
 Can you add new functionality to a new Java application at runtime?
 The answer is NO.
 If you need to add new functionality or update existing functionality, JVM needed
to be restarted.
 Java lacks dynamism
Java alone cannot be used to build true
Modular Systems..
But Java has given a great flexibility to build a
powerful module system on top of it.
That is..
OSGi
The Dynamic Module System for Java
OSGi
The Dynamic Module System for Java
 Defines a way to create true modules and a way for those modules to
interact at runtime
 Modules(Bundles) in OSGi can be installed, updated and uninstalled without
restarting the JVM.
Bundle
 The unit of modularization in OSGi.
 Standard Java application is a collection of Jars. In the same way OSGi based
application can be considered as a collection of Bundle.
 A Java package is the unit of Information hiding.
 Bundles can share packages with other bundles and hide packages from other
bundles
 Bundle is just a Jar file with some additional metadata(manifest headers) in the
MANIFEST.MF file.
Bundle
 Sample MANIFEST.MF file of a bundle.
Bundle-ManifestVersion : 2
Bundle-Name : My First OSGi Bundle
Bundle-SymbolicName: HelloWorldBundle
Bundle-Version: 1.0.0
Export-Package: org.helloworld
Import-package: org.osgi.framework
 Bundle-SymbolicName and Bundle-Version is used to uniquely identify a
bundle.
 Bundle-Version header is optional.
 By default packages in a bundle are considered as private. Other bundles
cannot see them.
 If a bundle needs to share packages, it needs to explicitly export
packages using the manifest header Export-Package.
Export-Package: org.helloworld
 The way to use classes/packages in other bundles is to import them
explicitly using Import-Package manifest header.
Import-package: org.osgi.framework
Bundles & Java packages
Bundle A
Exported Packages
Private Packages
Imported Packages
Bundle B
Exported Packages
Private Packages
Imported Packages
Bundle C
Exported Packages
Private Packages
Imported Packages
Bundles & Java packages
 How does OSGi achieve this level of information hiding...?
Imports
Imports
Bundles & Class Loaders
 Hierarchical class loading architecture in Java results in a global, flat and
ordered class path.
 Root cause for most of the issues in Java
 OSGi eliminates these issues by introducing a separate class path for
bundles. i.e a separate class loaders per bundle
 Bundle class loader can load classes from
 System class loader
 Other bundle class loaders.(imported packages)
 Its own bundle's jar file.
 This delegation forms a class loader delegation network.
Bundles & Class Loaders
 Represents the framework.
 OSGi Core framework implementation classes reside in the system
bundle.
 Registers system services.
 Exports packages that are loaded from the system classpath.
The System Bundle
Demo
 Mechanism where bundles can be directly wired to other bundles.
Require-Bundle: sample−api
 This header allows a bundle to import all exported packages from another
bundle.
 Consider the following set of headers of the bundle sample-impl.
Bundle-SymbolicName: sample-impl
Require-Bundle: sample−api;
visibility=reexport
 bundles that require this bundle(sample-impl) will transitively have access to
the required bundle’s(sample-api) exported packages.
 The use of Require-Bundle is strongly discouraged. why?
Require Bundles
Require Bundles
 Split Packages – Classes from the same package can come from different bundles
with Require bundle, such a package is called a split package.
 Say bundle A requires bundle B. What if bundle B changes over time?
 Bundle B stops exporting certain packages on which bundle A depends on.
 Bundle B is spited into several bundles.
 Require bundles chain can occur.
 Bundle A requires bundle B.
 Bundle B requires bundle C.
 Bundle C requires bundle D and so on.
 Bundle A may depends on a small portion of bundle B. Yet Bundle A has to bring all
the bundles in the chain.
 This can result in us bringing in a large amount of functionality when only a small
amount is really required.
 Fragments are bundles that are attached to a host bundle by the framework.
 Fragments are treated as part of the host, including any permitted headers.
 All class or resource loading of a fragment is handled through the host’s class
loader, a fragment must never have its own class loader.
 Fragment-Host manifest header is used to specify the host bundle of the
fragment bundle
Bundle-SymbolicName: child-bundle
Fragment-Host: parent-bundle
Usage:
1) To provide translation files for different locales
2) To provide some platform specify code.
Fragment Bundles
Runtime Class Loading
 Core specification
 Specifies the framework and the system services
 Service Compendium
 Specifies several OSGi services which are relevant for different markets
such as vehicle and mobile.
 OSGi Alliance, a non profit organization.
 Develop OSGi specifications.
 Latest released version of the OSGi platform is 4.3
OSGi Specifications
Java & OSGi
Functionality of the framework is divided up into several layers
Layering Model
 Provides an API to manage bundles at runtime.
 This API can be used to install, uninstall, update, start, stop bundles.
 Provides a runtime model for bundles.
Life Cycle Layer
Bundle States
A bundle can be in one of the following states:
 INSTALLED – The bundle has been successfully installed.
 RESOLVED – All Java classes that the bundle needs are available. This state
indicates that the bundle is either ready to be started or has stopped.
 STARTING – The bundle is being started, the BundleActivator.start method will
be called, and this method has not yet returned.
 ACTIVE – The bundle has been successfully activated and is running; its Bundle
Activator start method has been called and returned.
 STOPPING – The bundle is being stopped. The BundleActivator.stop method has
been called but the stop method has not yet returned.
 UNINSTALLED – The bundle has been uninstalled. It cannot move into another
state.
Bundle States
Bundle Activator
 Bundle is activated by calling its Bundle Activator object(if any).
 BundleActivator interface defines methods that the framework invokes when it
starts and stops the bundle.
 Bundle developer should declare Bundle-Activator manifest header in the
manifest file, in order to inform the framework.
 The value of the header should be the fully qualified class name of the class
which implements the BundleActivator interface
Bundle-Activator: org.sample.Activator
Public interface BundleActivator {
/**
* Invoked when this bundle is started
*/
public void start(BundleContext context)
throws Exception;
/**
* Invoked when this bundle is stopped
*/
public void stop(BundleContext context)
throws Excecption;
}
Bundle Context
 Represents the execution context of a single bundle within the OSGi platform.
 Act as a proxy between to the underlying framework.
 BundleContext object is created by the framework when a bundle is started.
 BundleContext object can be used to,
 Install new bundles
 Obtain registered services by other bundles,
 Register services in the framework.
 Subscribe or unsubscribe to events broadcast by the Framework
Demo
Service Layer
Specifies a mechanism for bundles to collaborate at runtime by
sharing objects.
OSGi provides a in-VM publish-find-bind model for plain
old Java objects(POJO).
 Introduces the OSGi service registry.
 A service is Java object published in the framework service registry.
 Bundles can register Java objects(services) with this service registry under one
or more interfaces.
 A Java interface as the type of the service is strongly recommended.
 All these operations are dynamic.
Service Layer
• A bundle publishing a service in the framework registry supplies.
1. A string or string array, with fully qualified class name(s) that the service
implements.
2. Actual Java object (i.e service)
3. A dictionary with additional service properties
Registering a Service
public class Activator implements BundleActivator
{
public void start(BundleContext bc) {
Hashtable props = new Hashtable();
props.put("language", "en");
//Registering the HelloWorld service
bc.registerService(
HelloService.class.getName(),
new HelloServiceImpl(),
props);
}
public void stop(BundleContext bc) {
}
}
Registering a Service
Using a Service
• Use framework to find a ServiceReference for the actual service. The
ServiceReference,
 avoid unnecessary dynamic service dependencies between bundles.
 encapsulate the properties and other meta-date about the service object it
represents.
 Use ServiceReference to get the service object.
1)Cast the service object to appropriate Java type.
2)Use the service.
• If you do not need the service anymore, use ServiceReference to unget the
service object.
public void start(BundleContext bc) {
//Get the service reference for HelloService
serviceRef =
bc.getServiceReference(HelloService.class.getName()
);
//service reference can be null, if the service is not
registered.
if (serviceRef != null) {
helloService = (HelloService)
bc.getService(serviceRef);
} else {
System.err.println("service reference not
found.");
}
//service can be null..
if (helloService != null) {
helloService.sayHello();
} else {
System.err.println("No HelloService found!");
}
Using a Service
Once the bundle finished utilizing the service, It should release service using
the following mechanism.
public void stop(BundleContext bc) {
if (helloService!=null) {
bc.ungetService(serviceRef);
helloService = null;
serviceRef = null;
} else {
System.err.println("HelloService is
null!");
}
}
Using a Service
Demo
 Framework fires ServiceEvents for following actions related to services.
 Registering a service.
 Unregistering a service.
 Modifying service properties.
 It is highly recommended for bundles which uses services, to listen to
these events and carefully handle them.
 Why?
Events and Listeners
Stale References
Services are Dynamic
 Stale reference is reference to a Java object that
 belongs to the class loader of a bundle that is stopped
 is associated with a service object that is unregistered.
 Potential harmful because they may result in significantly increased memory
usage.
 Removing stale references is a responsibility of the bundle developer.
 Bundles should listen to the service events of obtained services and act
accordingly.
Stale References
 A service can come and go at any time.
 A bundle developer must not assume the availability of the service at any
moment.
 Bundle can decide to withdraw its service from the registry while other
bundles are still using this service.
 A Service may not be registered at the other bundles trying to use it.
 this depends on the start order of bundles.
 it is highly recommended not do depend on the starting order of
bundles.
 Bundle developer should write code to handle this dynamic behavior of
services.
Services are Dynamic
 Monitoring services or listening to service events is the only way to handle
dynamic behavior of services.
 Following mechanisms can be used for this purposes
 Service Listeners
 Service Trackers
 Declarative Service
 iPOJO
 Blueprint services
Monitoring Services
 Introduced in R1 → from the beginning of OSGi
 ServiceListener is a listener interface that may be implemented by a
bundle developer.
Public interface ServiceListener{
public void serviceChanged(ServiceEvent
event);
}
 When a ServiceEvent is fired, it is synchronously delivered to a
ServiceListener.
Service Listener
public class HelloServiceListener implements
ServiceListener{
public void start(BundleContext context) throws
Exception {
context.addServiceListener(this);
}
public void stop(BundleContext context) throws
Exception {
context.removeServiceListener(this);
}
public void serviceChanged(ServiceEvent event) {
switch (event.getType()) {
case ServiceEvent.UNREGISTERING:
break;
case ServiceEvent.REGISTERED:
break;
case ServiceEvent.MODIFIED:
break;
}
}
}
Service Listener
Demo
If the service is registered before adding the listener,
listener will not get the REGISTERED event.
Now what?
public class HelloServiceListener implements
ServiceListener{
public void start(BundleContext context) throws
Exception {
ref =
context.getServiceReference(HelloService.class.getN
ame());
if(ref != null){
helloService =
(HelloService)context.getService(ref);
}
context.addServiceListener(this);
}
}
• First try to get the service, then register the listener.
• We still have a problem here..
• Race conditions.
Service Listener
 Service listeners
 race conditions
 listener leaks.
 Service Trackers
 must be closed otherwise listener leaks occur.
 Writing a customizer to handle more than one service is
complicated.
 Working with the OSGi service model using the programmatic API can
be complex and error prone.
 Bundle developers tend to make optimistic assumptions regarding the
availability of services in an attempt to simplify their code.
Services are Dynamic
Declarative Services
 Introduced in R4.
 Alternative approach for using OSGi services programming API.
 Is a way for a bundle to declare, in an XML file, the services it registers
and acquires.
 Provides a simplified programming model for developers. They need to
write less code.
 Runtime portion of the declarative service is called Service Component
Runtime(SCR).
 Allows developers to keep OSGi code away from domain logic.
Declarative Services
 A service component contains a description that is interpreted at run time
to create and dispose objects depending on the
 availability of other services
 need for such an object
 available configuration data.
 Can optionally provide as OSGi service.
 DS specification uses the generic term component to refer to a service
component
 Component is a normal Java class(POJO) and it is declared in an XML
document.
Services Component
Component Description – The declaration of a service component. It is contained
within an XML document in a bundle.
Component Properties – A set of properties which can be specified by the
component description, Configuration Admin service and from the component
factory.
Component Configuration – A component configuration represents a component
description parameterized by component properties. It is the entity that tracks the
component dependencies and manages a component instance. An activated
component configuration has a component context.
Component Instance – An instance of the component implementation class. A
component instance is created when a component configuration is activated and
discarded when the component configuration is deactivated. A component instance
is associated with exactly one component configuration.
Concepts
A component requires the following artifacts in the bundle:
1) An XML document that contains the component description.
/OSGI-INF/example.xml
2) The Service-Component manifest header which names the XML
documents that contain the component descriptions.
Service-Component: OSGI-INF/example.xml
3) An implementation class that is specified in the component description.
Declaring a Service
Description of a component which reference a service.
<?xml version="1.0" encoding="UTF-8"?>
<component name="helloservice.listen">
<implementation class="org.sample.HelloComponent”/>
<reference name="HS"
interface="org.helloworld.HelloService"
bind="setHelloService"
unbind="unsetHelloService” />
</component>
Example 1
Component implementation class.
public class HelloComponent {
HelloService hs;
protected void setHelloService(HelloService s) {
hs = s; }
protected void setHelloService(HelloService s) {
hs = null; }
protected void activate(ComponentContext ctxt)
{...}
protected void deactivate(ComponentContext ctxt)
{...}
}
Example 1
Description of a component which publish a service.
<?xml version="1.0" encoding="UTF-8"?>
<component name="example.handler">
<implementation
class="org.helloworld.HelloServiceImpl"/>
<service>
<provide
interface="org.helloworld.HelloService"/>
</service>
<component>
Example 2
Demo
 The actor/implementation that manages the components and their life
cycle.
 Listens for bundles that become active(Active state) and detects
Component Descriptions
 The SCR is responsible for activating and deactivating Component
Configurations
SCR
Service Component Runtime
Component Life Cycle
Enabled
 Life cycle of a component contained within the life cycle of its bundle.
 Initial enabled state of a component is specified in the component
description, using the enabled attribute.
 A component is enabled if the bundle is started and the enabled attribute
is set to true. The default value is “true”.
 A component should become enabled before it can be used.
Component Life Cycle
Satisfied
 A component can become satisfied, if the following conditions are met
 The component is enabled.
 Using the component properties of the component configuration, all the
component’s references are satisfied. A reference is satisfied when the
reference specifies optional cardinality or there is at least one target
service for the reference.
 SCR must activate a component configuration when the component
is enabled and the component configuration is satisfied and a
component configuration is needed. During the life time of a
component configuration, SCR can notify the component of changes
in its bound references.
 SCR will deactivate a previously activated component configuration
when the component becomes disabled, the component
configuration becomes unsatisfied, or the component configuration is
no longer needed.
Activation and Deactivation
 Delayed Component
 A component whose component configurations are activated when
their service is requested.
 Immediate Component
 A component whose component configurations are activated
immediately upon becoming satisfied.
 Factory Component
 A component whose component configurations are created and
activated through the componentʼscomponent factory.
Types of Components
 A component is an immediate component if it is not a factory component
and either does not specify a service or specifies a service and the
immediate attribute of the component element set to true.
 An immediate component is activated as soon as its dependencies are
satisfied.
 If an immediate component has no dependencies, it is activated
immediately.
Immediate Component
Component description
<?xml version="1.0" encoding="UTF-8"?>
<component name="example.activator">
<implementation
class="org.sample.HelloComponent"/>
</component>
Component implementation class
public class HelloComponent {
protected void activate(ComponentContext
ctxt) {...}
protected void deactivate(ComponentContext
ctxt) {...}
}
Immediate Component
 A delayed component
 specifies a service
 is not specified to be a factory component
 does not have the immediate attribute of the component
element set to true.
 If a delayed component configuration is satisfied, SCR must register the
component configuration as a service in the service registry but the
activation of the component configuration is delayed until the registered
service is requested.
 This is achieved by using a ServiceFactory
Delayed Component
Component description
<?xml version="1.0" encoding="UTF-8"?>
<component name="example.handler">
<implementation
class="org.helloworld.HelloServiceImpl"/>
<service>
<provide
interface="org.helloworld.HelloService"/>
</service>
<component>
Component implementation class
public class HelloServiceImpl implements
HelloService {
public void sayHello() {...}
}
Delayed Component
Component description.
<?xml version="1.0" encoding="UTF-8"?>
<component name="helloservice.listen">
<implementation class="org.sample.HelloComponent”/>
<reference name="HS"
interface="org.helloworld.HelloService"
bind="setHelloService"
unbind="unsetHelloService” />
</component>
Component implementation class.
public class HelloComponent {
HelloService hs;
protected void setHelloService(HelloService s) {
hs = s; }
protected void setHelloService(HelloService s) {
hs = null; }
protected void activate(ComponentContext ctxt)
{...}
protected void deactivate(ComponentContext ctxt)
{...}
}
Accessing Services
 cardinality for a referenced service
 0..1 – optional and unary,
 1..1 – mandatory and unary (Default) ,
 0..n – optional and multiple,
 1..n – mandatory and multiple.
 Reference policy
 static
 dynamic
 selecting target services
 By specifying a filter in the target property, the set of services
that should be part of the target services can be constrained
References to Services
<?xml version="1.0" encoding="UTF-8"?>
<component name="helloservice.listen">
<implementation
class="org.sample.HelloComponent"/>
<reference name="HS"
interface="org.sample.HelloService"
cardinality="0..n"
policy="dynamic"
target="(language=en)"
bind="setHelloService"
unbind="setHelloService" />
</component>
References to Services
Demo
OSGi Compendium Services
OSGi Alliance defines standard API s for some of the heavily used services.
 HTTPService
 Logging Service
 ComponentFactory
Eg: There are several vendor implementations of HTTPService.
Jetty servlet container
Tomcat servlet container yet provide this capability
P2 - Provisioning
 P2 is the provisioning platform used by eclipse.
 P2 is executed within a OSGi runtime, but not specific to eclipse/java or
OSGi
 Carbon uses P2 provisioning while building carbon products.
 Carbon has a inbuilt P2 runtime. (feature manager)
Questions ??
Thank you

Weitere ähnliche Inhalte

Was ist angesagt?

Java SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionJava SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionStephen Colebourne
 
OSGi Enablement For Apache Tuscany
OSGi Enablement For Apache TuscanyOSGi Enablement For Apache Tuscany
OSGi Enablement For Apache TuscanyRaymond Feng
 
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Edureka!
 
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration IssuesJava 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration IssuesGlobalLogic Ukraine
 
Basics of java programming language
Basics of java programming languageBasics of java programming language
Basics of java programming languagemasud33bd
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers GuideDaisyWatson5
 
Java - OOPS and Java Basics
Java - OOPS and Java BasicsJava - OOPS and Java Basics
Java - OOPS and Java BasicsVicter Paul
 
Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Peter R. Egli
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The FactLuciano Resende
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overviewJong Soon Bok
 
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos SanchezMaven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos Sanchezmfrancis
 
Top 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed AnswersTop 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed AnswersWhizlabs
 
Introduction to Loops in Java | For, While, Do While, Infinite Loops | Edureka
Introduction to Loops in Java | For, While, Do While, Infinite Loops | EdurekaIntroduction to Loops in Java | For, While, Do While, Infinite Loops | Edureka
Introduction to Loops in Java | For, While, Do While, Infinite Loops | EdurekaEdureka!
 
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaWhat Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaEdureka!
 
Java SE 9 modules - an introduction (July 2018)
Java SE 9 modules - an introduction (July 2018)Java SE 9 modules - an introduction (July 2018)
Java SE 9 modules - an introduction (July 2018)Stephen Colebourne
 

Was ist angesagt? (20)

Intro to OSGi
Intro to OSGiIntro to OSGi
Intro to OSGi
 
Java SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionJava SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introduction
 
OSGi Enablement For Apache Tuscany
OSGi Enablement For Apache TuscanyOSGi Enablement For Apache Tuscany
OSGi Enablement For Apache Tuscany
 
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
 
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration IssuesJava 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
 
Basics of java programming language
Basics of java programming languageBasics of java programming language
Basics of java programming language
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers Guide
 
Java - OOPS and Java Basics
Java - OOPS and Java BasicsJava - OOPS and Java Basics
Java - OOPS and Java Basics
 
Basics of java
Basics of javaBasics of java
Basics of java
 
Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)
 
Java Programming - 01 intro to java
Java Programming - 01 intro to javaJava Programming - 01 intro to java
Java Programming - 01 intro to java
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The Fact
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overview
 
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos SanchezMaven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
 
Learn Java Part 1
Learn Java Part 1Learn Java Part 1
Learn Java Part 1
 
Introducing Java 7
Introducing Java 7Introducing Java 7
Introducing Java 7
 
Top 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed AnswersTop 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed Answers
 
Introduction to Loops in Java | For, While, Do While, Infinite Loops | Edureka
Introduction to Loops in Java | For, While, Do While, Infinite Loops | EdurekaIntroduction to Loops in Java | For, While, Do While, Infinite Loops | Edureka
Introduction to Loops in Java | For, While, Do While, Infinite Loops | Edureka
 
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaWhat Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
 
Java SE 9 modules - an introduction (July 2018)
Java SE 9 modules - an introduction (July 2018)Java SE 9 modules - an introduction (July 2018)
Java SE 9 modules - an introduction (July 2018)
 

Andere mochten auch

OSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishOSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishArun Gupta
 
Deep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle LayerDeep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle LayerAruna Karunarathna
 
The Web on OSGi: Here's How
The Web on OSGi: Here's HowThe Web on OSGi: Here's How
The Web on OSGi: Here's Howmrdon
 
OSGi Web Development in Action
OSGi Web Development in Action	OSGi Web Development in Action
OSGi Web Development in Action OSGiUsers
 
Building LinkedIn's Next Generation Architecture with OSGi
Building LinkedIn's Next Generation  Architecture with OSGiBuilding LinkedIn's Next Generation  Architecture with OSGi
Building LinkedIn's Next Generation Architecture with OSGiLinkedIn
 
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)Savita Marwal
 

Andere mochten auch (6)

OSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishOSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFish
 
Deep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle LayerDeep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle Layer
 
The Web on OSGi: Here's How
The Web on OSGi: Here's HowThe Web on OSGi: Here's How
The Web on OSGi: Here's How
 
OSGi Web Development in Action
OSGi Web Development in Action	OSGi Web Development in Action
OSGi Web Development in Action
 
Building LinkedIn's Next Generation Architecture with OSGi
Building LinkedIn's Next Generation  Architecture with OSGiBuilding LinkedIn's Next Generation  Architecture with OSGi
Building LinkedIn's Next Generation Architecture with OSGi
 
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)
 

Ähnlich wie Introduction to the Dynamic Module System for Java - OSGi

Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC teamOs gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC teamThuy_Dang
 
CQCON CQ Maven Methods
CQCON CQ Maven MethodsCQCON CQ Maven Methods
CQCON CQ Maven MethodsAndrew Savory
 
Making Applications Work Together In Eclipse
Making Applications Work Together In EclipseMaking Applications Work Together In Eclipse
Making Applications Work Together In EclipseKaniska Mandal
 
Java Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily JiangJava Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily JiangJAX London
 
OSGi Training for Carbon Developers
OSGi Training for Carbon DevelopersOSGi Training for Carbon Developers
OSGi Training for Carbon DevelopersAruna Karunarathna
 
Third party libraries and OSGi - a complicated relationship
Third party libraries and OSGi - a complicated relationshipThird party libraries and OSGi - a complicated relationship
Third party libraries and OSGi - a complicated relationshipSascha Brinkmann
 
Eclipse_Building_Blocks
Eclipse_Building_BlocksEclipse_Building_Blocks
Eclipse_Building_BlocksRahul Shukla
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1kshanth2101
 
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Martin Toshev
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Martin Toshev
 
Osgi Webinar
Osgi WebinarOsgi Webinar
Osgi WebinarWSO2
 
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...mfrancis
 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in javaVishnu Suresh
 

Ähnlich wie Introduction to the Dynamic Module System for Java - OSGi (20)

Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC teamOs gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
 
CQ Maven Methods
CQ Maven MethodsCQ Maven Methods
CQ Maven Methods
 
CQCON CQ Maven Methods
CQCON CQ Maven MethodsCQCON CQ Maven Methods
CQCON CQ Maven Methods
 
Making Applications Work Together In Eclipse
Making Applications Work Together In EclipseMaking Applications Work Together In Eclipse
Making Applications Work Together In Eclipse
 
Java Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily JiangJava Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily Jiang
 
OSGi Training for Carbon Developers
OSGi Training for Carbon DevelopersOSGi Training for Carbon Developers
OSGi Training for Carbon Developers
 
Third party libraries and OSGi - a complicated relationship
Third party libraries and OSGi - a complicated relationshipThird party libraries and OSGi - a complicated relationship
Third party libraries and OSGi - a complicated relationship
 
Osgi
OsgiOsgi
Osgi
 
Eclipse_Building_Blocks
Eclipse_Building_BlocksEclipse_Building_Blocks
Eclipse_Building_Blocks
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1
 
Modular Java
Modular JavaModular Java
Modular Java
 
Java packages oop
Java packages oopJava packages oop
Java packages oop
 
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
 
Unit 2 notes.pdf
Unit 2 notes.pdfUnit 2 notes.pdf
Unit 2 notes.pdf
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
 
Packages
PackagesPackages
Packages
 
Osgi Webinar
Osgi WebinarOsgi Webinar
Osgi Webinar
 
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...
 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in java
 

Kürzlich hochgeladen

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Kürzlich hochgeladen (20)

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

Introduction to the Dynamic Module System for Java - OSGi

  • 1. Introduction to OSGi Sameera Jayasoma Technical Lead and Product Manager WSO2 Inc. The Dynamic Module System for Java Pradeep Fernando Software Engineer WSO2 Inc.
  • 2. WSO2  Founded in 2005 by pioneers in XML and Web services technologies & standards as well as open source.  Founders & leading contributors to all key Apache Web services projects.  Offering complete SOA platform, 100% free and open source.  Business model based on providing training, consultancy and support for the software.  Global corporation with R&D center in Sri Lanka and offices in US & UK.
  • 4. Modular Systems  No doubt, a computer is complex system.  How do you handle this complexity, when designing large systems?
  • 5. Modular Systems  Break the large system into more smaller, understandable units  These small units are called modules.  Benefits of modular systems  Reuse  Abstraction  ..
  • 6. Modular Systems  Same theories can be applied to the software world also.  Dividing a complex software system into small parts/modules. •Allows us to understand the system easily. •Allows us to develop part by part by different team. •Allows us to reuse already developed modules.  Does Java supports building true modular systems?
  • 7. Java for building modular systems..
  • 8. Java for Modular Systems  Java is one of the popular OOP languages for developing large enterprise applications.  Java provides some level of modularity.  Consider a Java class •The unit of information hiding in Java. •Public methods, expose a defined contract.
  • 9. Class Loading  In a standard Java application.
  • 10. JAR Files  JAR is unit of deployment in Java.  Typical Java application consists a set of JAR files.  At runtime contents of all JAR files are treated as a single, ordered and global list which is called the class path  Consider the following command. java -classpath log4j.jar:statx- api.jar:woodstox.jar:axis2.jar: carbon.jar:utils.jar:target/classes org.sample.HelloWorld
  • 11. org/sample/HelloWorld .... org/wso2/carbon/utils/CarbonUtils .... org/wso2/carbon/core/Activator .... org/apache/axis2/AxisFault .... com/ctc/wstx/api/ReaderConfig .... javax/xml/stream/XMLStreamReader .... JAR Files and Class Loading org/apache/log4j/Appender .... Search order log4j.jar stax- api.jar woodstox.ja r axis2.jar carbon- core.jar carbon- utils.jar target/clas ses
  • 13. Problem with JARs  No runtime representation  Multiple versions of JAR files cannot be loaded simultaneously  A JAR cannot declare dependencies on other JARs.  No mechanism for information hiding  Hence, JARs cannot be considered as modules
  • 14. Java for Modular Systems  Can you update a part(can be a JAR file) of a running Java application?  Can you add new functionality to a new Java application at runtime?  The answer is NO.  If you need to add new functionality or update existing functionality, JVM needed to be restarted.  Java lacks dynamism
  • 15. Java alone cannot be used to build true Modular Systems..
  • 16. But Java has given a great flexibility to build a powerful module system on top of it. That is..
  • 17. OSGi The Dynamic Module System for Java
  • 18. OSGi The Dynamic Module System for Java  Defines a way to create true modules and a way for those modules to interact at runtime  Modules(Bundles) in OSGi can be installed, updated and uninstalled without restarting the JVM.
  • 19. Bundle  The unit of modularization in OSGi.  Standard Java application is a collection of Jars. In the same way OSGi based application can be considered as a collection of Bundle.  A Java package is the unit of Information hiding.  Bundles can share packages with other bundles and hide packages from other bundles  Bundle is just a Jar file with some additional metadata(manifest headers) in the MANIFEST.MF file.
  • 20. Bundle  Sample MANIFEST.MF file of a bundle. Bundle-ManifestVersion : 2 Bundle-Name : My First OSGi Bundle Bundle-SymbolicName: HelloWorldBundle Bundle-Version: 1.0.0 Export-Package: org.helloworld Import-package: org.osgi.framework  Bundle-SymbolicName and Bundle-Version is used to uniquely identify a bundle.  Bundle-Version header is optional.
  • 21.  By default packages in a bundle are considered as private. Other bundles cannot see them.  If a bundle needs to share packages, it needs to explicitly export packages using the manifest header Export-Package. Export-Package: org.helloworld  The way to use classes/packages in other bundles is to import them explicitly using Import-Package manifest header. Import-package: org.osgi.framework Bundles & Java packages
  • 22. Bundle A Exported Packages Private Packages Imported Packages Bundle B Exported Packages Private Packages Imported Packages Bundle C Exported Packages Private Packages Imported Packages Bundles & Java packages  How does OSGi achieve this level of information hiding...? Imports Imports
  • 23. Bundles & Class Loaders  Hierarchical class loading architecture in Java results in a global, flat and ordered class path.  Root cause for most of the issues in Java  OSGi eliminates these issues by introducing a separate class path for bundles. i.e a separate class loaders per bundle  Bundle class loader can load classes from  System class loader  Other bundle class loaders.(imported packages)  Its own bundle's jar file.  This delegation forms a class loader delegation network.
  • 24. Bundles & Class Loaders
  • 25.  Represents the framework.  OSGi Core framework implementation classes reside in the system bundle.  Registers system services.  Exports packages that are loaded from the system classpath. The System Bundle
  • 26. Demo
  • 27.  Mechanism where bundles can be directly wired to other bundles. Require-Bundle: sample−api  This header allows a bundle to import all exported packages from another bundle.  Consider the following set of headers of the bundle sample-impl. Bundle-SymbolicName: sample-impl Require-Bundle: sample−api; visibility=reexport  bundles that require this bundle(sample-impl) will transitively have access to the required bundle’s(sample-api) exported packages.  The use of Require-Bundle is strongly discouraged. why? Require Bundles
  • 28. Require Bundles  Split Packages – Classes from the same package can come from different bundles with Require bundle, such a package is called a split package.  Say bundle A requires bundle B. What if bundle B changes over time?  Bundle B stops exporting certain packages on which bundle A depends on.  Bundle B is spited into several bundles.  Require bundles chain can occur.  Bundle A requires bundle B.  Bundle B requires bundle C.  Bundle C requires bundle D and so on.  Bundle A may depends on a small portion of bundle B. Yet Bundle A has to bring all the bundles in the chain.  This can result in us bringing in a large amount of functionality when only a small amount is really required.
  • 29.  Fragments are bundles that are attached to a host bundle by the framework.  Fragments are treated as part of the host, including any permitted headers.  All class or resource loading of a fragment is handled through the host’s class loader, a fragment must never have its own class loader.  Fragment-Host manifest header is used to specify the host bundle of the fragment bundle Bundle-SymbolicName: child-bundle Fragment-Host: parent-bundle Usage: 1) To provide translation files for different locales 2) To provide some platform specify code. Fragment Bundles
  • 31.  Core specification  Specifies the framework and the system services  Service Compendium  Specifies several OSGi services which are relevant for different markets such as vehicle and mobile.  OSGi Alliance, a non profit organization.  Develop OSGi specifications.  Latest released version of the OSGi platform is 4.3 OSGi Specifications
  • 33. Functionality of the framework is divided up into several layers Layering Model
  • 34.  Provides an API to manage bundles at runtime.  This API can be used to install, uninstall, update, start, stop bundles.  Provides a runtime model for bundles. Life Cycle Layer
  • 35. Bundle States A bundle can be in one of the following states:  INSTALLED – The bundle has been successfully installed.  RESOLVED – All Java classes that the bundle needs are available. This state indicates that the bundle is either ready to be started or has stopped.  STARTING – The bundle is being started, the BundleActivator.start method will be called, and this method has not yet returned.  ACTIVE – The bundle has been successfully activated and is running; its Bundle Activator start method has been called and returned.  STOPPING – The bundle is being stopped. The BundleActivator.stop method has been called but the stop method has not yet returned.  UNINSTALLED – The bundle has been uninstalled. It cannot move into another state.
  • 37. Bundle Activator  Bundle is activated by calling its Bundle Activator object(if any).  BundleActivator interface defines methods that the framework invokes when it starts and stops the bundle.  Bundle developer should declare Bundle-Activator manifest header in the manifest file, in order to inform the framework.  The value of the header should be the fully qualified class name of the class which implements the BundleActivator interface Bundle-Activator: org.sample.Activator
  • 38. Public interface BundleActivator { /** * Invoked when this bundle is started */ public void start(BundleContext context) throws Exception; /** * Invoked when this bundle is stopped */ public void stop(BundleContext context) throws Excecption; }
  • 39. Bundle Context  Represents the execution context of a single bundle within the OSGi platform.  Act as a proxy between to the underlying framework.  BundleContext object is created by the framework when a bundle is started.  BundleContext object can be used to,  Install new bundles  Obtain registered services by other bundles,  Register services in the framework.  Subscribe or unsubscribe to events broadcast by the Framework
  • 40. Demo
  • 42. Specifies a mechanism for bundles to collaborate at runtime by sharing objects.
  • 43. OSGi provides a in-VM publish-find-bind model for plain old Java objects(POJO).
  • 44.  Introduces the OSGi service registry.  A service is Java object published in the framework service registry.  Bundles can register Java objects(services) with this service registry under one or more interfaces.  A Java interface as the type of the service is strongly recommended.  All these operations are dynamic. Service Layer
  • 45. • A bundle publishing a service in the framework registry supplies. 1. A string or string array, with fully qualified class name(s) that the service implements. 2. Actual Java object (i.e service) 3. A dictionary with additional service properties Registering a Service
  • 46. public class Activator implements BundleActivator { public void start(BundleContext bc) { Hashtable props = new Hashtable(); props.put("language", "en"); //Registering the HelloWorld service bc.registerService( HelloService.class.getName(), new HelloServiceImpl(), props); } public void stop(BundleContext bc) { } } Registering a Service
  • 47. Using a Service • Use framework to find a ServiceReference for the actual service. The ServiceReference,  avoid unnecessary dynamic service dependencies between bundles.  encapsulate the properties and other meta-date about the service object it represents.  Use ServiceReference to get the service object. 1)Cast the service object to appropriate Java type. 2)Use the service. • If you do not need the service anymore, use ServiceReference to unget the service object.
  • 48. public void start(BundleContext bc) { //Get the service reference for HelloService serviceRef = bc.getServiceReference(HelloService.class.getName() ); //service reference can be null, if the service is not registered. if (serviceRef != null) { helloService = (HelloService) bc.getService(serviceRef); } else { System.err.println("service reference not found."); } //service can be null.. if (helloService != null) { helloService.sayHello(); } else { System.err.println("No HelloService found!"); } Using a Service
  • 49. Once the bundle finished utilizing the service, It should release service using the following mechanism. public void stop(BundleContext bc) { if (helloService!=null) { bc.ungetService(serviceRef); helloService = null; serviceRef = null; } else { System.err.println("HelloService is null!"); } } Using a Service
  • 50. Demo
  • 51.  Framework fires ServiceEvents for following actions related to services.  Registering a service.  Unregistering a service.  Modifying service properties.  It is highly recommended for bundles which uses services, to listen to these events and carefully handle them.  Why? Events and Listeners
  • 54.  Stale reference is reference to a Java object that  belongs to the class loader of a bundle that is stopped  is associated with a service object that is unregistered.  Potential harmful because they may result in significantly increased memory usage.  Removing stale references is a responsibility of the bundle developer.  Bundles should listen to the service events of obtained services and act accordingly. Stale References
  • 55.  A service can come and go at any time.  A bundle developer must not assume the availability of the service at any moment.  Bundle can decide to withdraw its service from the registry while other bundles are still using this service.  A Service may not be registered at the other bundles trying to use it.  this depends on the start order of bundles.  it is highly recommended not do depend on the starting order of bundles.  Bundle developer should write code to handle this dynamic behavior of services. Services are Dynamic
  • 56.  Monitoring services or listening to service events is the only way to handle dynamic behavior of services.  Following mechanisms can be used for this purposes  Service Listeners  Service Trackers  Declarative Service  iPOJO  Blueprint services Monitoring Services
  • 57.  Introduced in R1 → from the beginning of OSGi  ServiceListener is a listener interface that may be implemented by a bundle developer. Public interface ServiceListener{ public void serviceChanged(ServiceEvent event); }  When a ServiceEvent is fired, it is synchronously delivered to a ServiceListener. Service Listener
  • 58. public class HelloServiceListener implements ServiceListener{ public void start(BundleContext context) throws Exception { context.addServiceListener(this); } public void stop(BundleContext context) throws Exception { context.removeServiceListener(this); } public void serviceChanged(ServiceEvent event) { switch (event.getType()) { case ServiceEvent.UNREGISTERING: break; case ServiceEvent.REGISTERED: break; case ServiceEvent.MODIFIED: break; } } } Service Listener
  • 59. Demo
  • 60. If the service is registered before adding the listener, listener will not get the REGISTERED event. Now what?
  • 61. public class HelloServiceListener implements ServiceListener{ public void start(BundleContext context) throws Exception { ref = context.getServiceReference(HelloService.class.getN ame()); if(ref != null){ helloService = (HelloService)context.getService(ref); } context.addServiceListener(this); } } • First try to get the service, then register the listener. • We still have a problem here.. • Race conditions. Service Listener
  • 62.  Service listeners  race conditions  listener leaks.  Service Trackers  must be closed otherwise listener leaks occur.  Writing a customizer to handle more than one service is complicated.  Working with the OSGi service model using the programmatic API can be complex and error prone.  Bundle developers tend to make optimistic assumptions regarding the availability of services in an attempt to simplify their code. Services are Dynamic
  • 64.  Introduced in R4.  Alternative approach for using OSGi services programming API.  Is a way for a bundle to declare, in an XML file, the services it registers and acquires.  Provides a simplified programming model for developers. They need to write less code.  Runtime portion of the declarative service is called Service Component Runtime(SCR).  Allows developers to keep OSGi code away from domain logic. Declarative Services
  • 65.  A service component contains a description that is interpreted at run time to create and dispose objects depending on the  availability of other services  need for such an object  available configuration data.  Can optionally provide as OSGi service.  DS specification uses the generic term component to refer to a service component  Component is a normal Java class(POJO) and it is declared in an XML document. Services Component
  • 66. Component Description – The declaration of a service component. It is contained within an XML document in a bundle. Component Properties – A set of properties which can be specified by the component description, Configuration Admin service and from the component factory. Component Configuration – A component configuration represents a component description parameterized by component properties. It is the entity that tracks the component dependencies and manages a component instance. An activated component configuration has a component context. Component Instance – An instance of the component implementation class. A component instance is created when a component configuration is activated and discarded when the component configuration is deactivated. A component instance is associated with exactly one component configuration. Concepts
  • 67. A component requires the following artifacts in the bundle: 1) An XML document that contains the component description. /OSGI-INF/example.xml 2) The Service-Component manifest header which names the XML documents that contain the component descriptions. Service-Component: OSGI-INF/example.xml 3) An implementation class that is specified in the component description. Declaring a Service
  • 68. Description of a component which reference a service. <?xml version="1.0" encoding="UTF-8"?> <component name="helloservice.listen"> <implementation class="org.sample.HelloComponent”/> <reference name="HS" interface="org.helloworld.HelloService" bind="setHelloService" unbind="unsetHelloService” /> </component> Example 1
  • 69. Component implementation class. public class HelloComponent { HelloService hs; protected void setHelloService(HelloService s) { hs = s; } protected void setHelloService(HelloService s) { hs = null; } protected void activate(ComponentContext ctxt) {...} protected void deactivate(ComponentContext ctxt) {...} } Example 1
  • 70. Description of a component which publish a service. <?xml version="1.0" encoding="UTF-8"?> <component name="example.handler"> <implementation class="org.helloworld.HelloServiceImpl"/> <service> <provide interface="org.helloworld.HelloService"/> </service> <component> Example 2
  • 71. Demo
  • 72.  The actor/implementation that manages the components and their life cycle.  Listens for bundles that become active(Active state) and detects Component Descriptions  The SCR is responsible for activating and deactivating Component Configurations SCR Service Component Runtime
  • 73. Component Life Cycle Enabled  Life cycle of a component contained within the life cycle of its bundle.  Initial enabled state of a component is specified in the component description, using the enabled attribute.  A component is enabled if the bundle is started and the enabled attribute is set to true. The default value is “true”.  A component should become enabled before it can be used.
  • 74. Component Life Cycle Satisfied  A component can become satisfied, if the following conditions are met  The component is enabled.  Using the component properties of the component configuration, all the component’s references are satisfied. A reference is satisfied when the reference specifies optional cardinality or there is at least one target service for the reference.
  • 75.  SCR must activate a component configuration when the component is enabled and the component configuration is satisfied and a component configuration is needed. During the life time of a component configuration, SCR can notify the component of changes in its bound references.  SCR will deactivate a previously activated component configuration when the component becomes disabled, the component configuration becomes unsatisfied, or the component configuration is no longer needed. Activation and Deactivation
  • 76.  Delayed Component  A component whose component configurations are activated when their service is requested.  Immediate Component  A component whose component configurations are activated immediately upon becoming satisfied.  Factory Component  A component whose component configurations are created and activated through the componentʼscomponent factory. Types of Components
  • 77.  A component is an immediate component if it is not a factory component and either does not specify a service or specifies a service and the immediate attribute of the component element set to true.  An immediate component is activated as soon as its dependencies are satisfied.  If an immediate component has no dependencies, it is activated immediately. Immediate Component
  • 78. Component description <?xml version="1.0" encoding="UTF-8"?> <component name="example.activator"> <implementation class="org.sample.HelloComponent"/> </component> Component implementation class public class HelloComponent { protected void activate(ComponentContext ctxt) {...} protected void deactivate(ComponentContext ctxt) {...} } Immediate Component
  • 79.  A delayed component  specifies a service  is not specified to be a factory component  does not have the immediate attribute of the component element set to true.  If a delayed component configuration is satisfied, SCR must register the component configuration as a service in the service registry but the activation of the component configuration is delayed until the registered service is requested.  This is achieved by using a ServiceFactory Delayed Component
  • 80. Component description <?xml version="1.0" encoding="UTF-8"?> <component name="example.handler"> <implementation class="org.helloworld.HelloServiceImpl"/> <service> <provide interface="org.helloworld.HelloService"/> </service> <component> Component implementation class public class HelloServiceImpl implements HelloService { public void sayHello() {...} } Delayed Component
  • 81. Component description. <?xml version="1.0" encoding="UTF-8"?> <component name="helloservice.listen"> <implementation class="org.sample.HelloComponent”/> <reference name="HS" interface="org.helloworld.HelloService" bind="setHelloService" unbind="unsetHelloService” /> </component> Component implementation class. public class HelloComponent { HelloService hs; protected void setHelloService(HelloService s) { hs = s; } protected void setHelloService(HelloService s) { hs = null; } protected void activate(ComponentContext ctxt) {...} protected void deactivate(ComponentContext ctxt) {...} } Accessing Services
  • 82.  cardinality for a referenced service  0..1 – optional and unary,  1..1 – mandatory and unary (Default) ,  0..n – optional and multiple,  1..n – mandatory and multiple.  Reference policy  static  dynamic  selecting target services  By specifying a filter in the target property, the set of services that should be part of the target services can be constrained References to Services
  • 83. <?xml version="1.0" encoding="UTF-8"?> <component name="helloservice.listen"> <implementation class="org.sample.HelloComponent"/> <reference name="HS" interface="org.sample.HelloService" cardinality="0..n" policy="dynamic" target="(language=en)" bind="setHelloService" unbind="setHelloService" /> </component> References to Services
  • 84. Demo
  • 85. OSGi Compendium Services OSGi Alliance defines standard API s for some of the heavily used services.  HTTPService  Logging Service  ComponentFactory Eg: There are several vendor implementations of HTTPService. Jetty servlet container Tomcat servlet container yet provide this capability
  • 86. P2 - Provisioning  P2 is the provisioning platform used by eclipse.  P2 is executed within a OSGi runtime, but not specific to eclipse/java or OSGi  Carbon uses P2 provisioning while building carbon products.  Carbon has a inbuilt P2 runtime. (feature manager)