0% found this document useful (0 votes)
74 views14 pages

OSGi Service Discovery

OSGi provides a service registry that allows bundles to publish and discover services. Bundles can register services they provide and lookup services by interface or properties. The OSGi life cycle manages the loading, starting, stopping and updating of bundles. Service patterns like the service listener and service tracker patterns provide callbacks when services are added or removed to help clients dynamically adapt to changing services.

Uploaded by

Da Neben
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views14 pages

OSGi Service Discovery

OSGi provides a service registry that allows bundles to publish and discover services. Bundles can register services they provide and lookup services by interface or properties. The OSGi life cycle manages the loading, starting, stopping and updating of bundles. Service patterns like the service listener and service tracker patterns provide callbacks when services are added or removed to help clients dynamically adapt to changing services.

Uploaded by

Da Neben
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

OSGi Service Discovery

OSGi
• Introducing the OSGi Framework
– OSGi Alliance
– Components/Bundles
– Module and Life Cycle layer
• Services in OSGi
– Service Registry
– Service Patterns
– Remote Services

2
OSGi Alliance
• Open Services Gateway initiative
• OSGi Alliance is a non-profit consortium
– founded in march 1999
– specifies/maintains the OSGi standard
• specifying detailed API
• providing reference implementation / test cases
– Members: IBM, Nokia, Motorola, BMW,….

• Some open source implementations:


– Equinox OSGi, Knoplerfish OSGi, Apache Felix
3
OSGi Framework

Services

Security
Bundles Life Cycle

Modules

Execution Environment

Java Virtual Machine

Operating System

Hardware
4
OSGi Bundle
Bundle Manifest
• Packages

JAR FILE
import org.abc…
• Own classes, interfaces
• Other resources
export org.xy….
Services
Manifest file

Bundle version Life Cycle


Bundle symbolic name
Bundle classpath
BundleActivator
Modules
import packages

export packages Execution Environment

Java Virtual Machine 5


deliver
install OSGi Life Cycle
automatic
Installed
Started
manual (other
bundles, user,…)
re

rt
s ol

ta
ve

s
d

Resolved Active Services


uninstall

Life Cycle
ll
sta
in
un

Stopped Modules
Uninstalled

Execution Environment

Java Virtual Machine 6


OSGi Class Loading

Bundle Bundle

Manifest Services
import … Manifest
export … import …
export … Life Cycle
Class Loader provides
Modules
Class Loader

Execution Environment

Java Virtual Machine 7


Services
• Component-oriented
– Components can be delivered and installed
dynamically, but cannot interact dynamically
• Service-oriented
– Bundles can provide interfaces as services
– Other bundles can find/bind/use/release them

8
OSGi Service Registry
Service Registry
• register services by providing class or
interface name and optional properties
• Find by interface/class name
z

• Bind by getting an object reference


xy
er

• Service provider can have one object for


ist

Service
g

all clients or for each client an object


re

(stateful)
• Registry is returning only compatible
versions of an object Life Cycle

Bundle yz
/ b ind x
fin d Modules
xyz.class

Bundle Execution Environment

abc.class
Java Virtual Machine 9
Service Registry
• Problem
– Services can be provided and removed at any time
Client has to poll regularly to find an appropriate service
Client can get NullPointerException if service is removed

• Solutions provided by service discovery patterns


– Service Listener Pattern
– Service Tracker
– Whiteboard Pattern
– Declarative Services
10
Service Listener Pattern
Service Registry
•f ServiceListener

registe
callba

r
r xyz

listene
ck
e
regist

r
Requester
1. Implements ServiceListener interface with
Provider serviceChanged method
2. Register ServiceListener at Registry with
requested interface names/properties
3. Whenever an appropriate service is
xyz.class
registered the callback method
serviceChanged is invoked with an
ServiceEvent object as parameter
11
Service Tracker
• Problem
– ServiceListener is too complicate to implement, not
flexible enough and error prone

• Improvement is achieved by ServiceTracker


– User defined callback methods for adding,
removing, changing services
– Can block until an appropriate service is available
– If a used service was removed, it automatically
provides a new service if found
12
Events
• Use case
– Whenever an event occurs, multiple
requester/subscribers want to be informed

• Therefore the Event-Listener-Pattern and


Whiteboard Pattern are provided
– Whiteboard Patern is an big amendment of the
Event-Listener-Pattern, so we omit the Event-
Listener-Pattern

13
Whiteboard Pattern
Service Registry
•f ServiceListener

registe
callba

r
r xyz

listene
ck
e
regist

r
Subscriber
1. Implements ServiceListener interface with
Provider serviceChanged method
2. Register ServiceListener at Registry with
requested interface names/properties
3. Whenever an appropriate service is
xyz.class
registered the callback method
serviceChanged is invoked with an
ServiceEvent object as parameter
14

You might also like