The next release of the OSGi specifications are planned for publication at EclipseCon 2011. So what is new? This presentation will provide an overview of the new features in the spec including Java 5 generics for the Framework and ServiceTracker, modern replacement for PackageAdmin and StartLevel, generic capabilities and requirements, resolver hooks, bytecode weaving and many more improvements and new features. The presentation assumes the audience has a basic understanding of OSGi and will focus on the changes in 4.3.
2. Generics
• Framework API feels “old-
fashioned”
• Lack of generics
• Uses of arrays and null
return
• Generics have been held back
because the embedded world
is still still based upon Java 1.4
4. -target jsr14
• Developed to compile Java 5 code for 1.4 JREs
• All compilers recognize the
• -source 1.5 -target jsr14 switches
5. -target jsr14
• Developed to compile Java 5 code for 1.4 JREs
• All compilers recognize the
• -source 1.5 -target jsr14 switches
• Output class format 48 (1.4)
• Stores generics in skippable attributes
• Avoids Java 5 introduced types/members
6. -target jsr14
• Developed to compile Java 5 code for 1.4 JREs
• All compilers recognize the
• -source 1.5 -target jsr14 switches
• Output class format 48 (1.4)
• Stores generics in skippable attributes
• Avoids Java 5 introduced types/members
• Works like a charm, but …
• No annotations
• No enums
8. Type Safe use of Services
ServiceReference lr =
context.getServiceReference(LogService.class.getName());
LogService log = (LogService)context.getService(lr);
becomes
ServiceReference<LogService> lr =
context.getServiceReference(LogService.class);
LogService log = context.getService(lr);
9. Type Safe use of Services
ServiceReference[] rs =
context.getServiceReferences(EventAdmin.class.getName(),
…);
becomes
Collection<ServiceReference<EventAdmin>> rs =
context.getServiceReferences(EventAdmin.class, …);
There can be some source incompatibilities since using null for the service
type argument is now ambiguous.
10. Type Safe use of Services
ServiceRegistration sr =
context.registerService(
ConfigurationListener.class.getName(), …)
becomes
ServiceRegistration<ConfigurationListener> sr =
context.registerService(ConfigurationListener.class, …)
11. Type Safe use of Services
ServiceTracker st = new ServiceTracker(
context, EventListener.class, null);
st.open();
EventListener el = (EventListener)st.getService();
becomes
ServiceTracker<EventListener,EventListener> st =
new ServiceTracker<EventListener,EventListener>(
context, EventListener.class, null);
st.open();
EventListener el = st.getService();
13. Capabilities
• A capability is a set of attributes in a namespace
• Built-in capabilities
• osgi.wiring.package: Export-Package
• osgi.wiring.bundle: Bundle-SymbolicName
• osgi.wiring.host: Bundle-SymbolicName
14. Capabilities
• A capability is a set of attributes in a namespace
• Built-in capabilities
• osgi.wiring.package: Export-Package
• osgi.wiring.bundle: Bundle-SymbolicName
• osgi.wiring.host: Bundle-SymbolicName
• Generic capabilities: Provide-Capability manifest header
16. Requirements
• A requirement is a filter expression over the attribute set of a capability
• Built-in requirements
• osgi.wiring.package: Import-Package
• osgi.wiring.bundle: Require-Bundle
• osgi.wiring.host: Fragment-Host
17. Requirements
• A requirement is a filter expression over the attribute set of a capability
• Built-in requirements
• osgi.wiring.package: Import-Package
• osgi.wiring.bundle: Require-Bundle
• osgi.wiring.host: Fragment-Host
• Generic requirements: Require-Capability manifest header
18. 7,*&4%.F','#"?;%#"7".*'*)','&,(,:%3%*15'D;./3"+'&,.').31'(#)$%/"'*4"%#'&,(,:%3%*%"+'94".'*4"%#'
#"?;%#"7".*+',#"'+,*%+-%"/2'*4,*'%+2'#"?;%#"7".*+',#"'*#,.+%*%$"5'
G4"'H"?;%#"@E,(,:%3%*1',./'I#)$%/"@E,(,:%3%*1'4",/"#+',#"'7,.%-"+*'4",/"#+'*4,*''&-0"(&'F"."#%&'
#"?;%#"7".*+',./'&,(,:%3%*%"+'%.',.1'.,7"'+(,&"5'J)9"$"#2','.;7:"#')-'7,.%-"+*'4",/"#+'%.'*4"'
C!K%'+("&%-%&,*%).+',#"',&*;,331'#"?;%#"7".*+').'&,(,:%3%*%"+'+("&%-%"/':1')*4"#'C!K%'7,.%-"+*'4",/@
Capabilities and Requirements
"#+5'=)#'"<,7(3"2',.'67()#*@I,&0,F"'&3,;+"'%+','#"?;%#"7".*').'*4"'&,(,:%3%*1'+("&%-%"/':1'*4"'L<()#*@
I,&0,F"'&3,;+"5'G4%+'+("&%-%&,*%).'*4"#"-)#"'&).*,%.+','.;7:"#')-'.,7"'+(,&"+'-)#'*4"+"'C!K%'7,.%@
-"+*'4",/"#+M'+1&$23$#$%&245%6,-2'+1&$23$#$%&278.98&-2',./'+1&$23$#$%&2:+1"5'G4"+"'.,7"'+(,&"+'
%.-3;".&"'*4"'#"+)3$"#',./'/"-%."'*4"'&3,++'3),/%.F'(#)&"++5'=)#'"<,7(3"2','H"?;%#"@D;./3"'&3,;+"'%+','
• Additional resolver constraint
#"?;%#"7".*'*4,*'".+;#"+'*4,*'*4"'"<()#*"/'(,&0,F"+')-'*4"'#"?;%#"/':;./3"',#"',$,%3,:3"'*)'*4"'
#"?;%#"#N+'&3,++'3),/"#5
H"?;%#"7".*+',./'E,(,:%3%*%"+',#"''&-0"(&''%.',':;./3"5'G4"'C!K%'-#,7"9)#0'&,.'*4".'7,*&4'*4"'
#"?;%#"7".*+'*)'&,(,:%3%*%"+')-')*4"#':;./3"+'%.'*4"'(&!304$,5'(4,+"5'>':;./3"'&,.').31'#;.'94".'%*'%+'
• Each non-optional requirement must be satisfied by a capability
#"+)3$"/',./'*4"#"-)#"'%*+'/"("./".&%"+',#"'+,*%+-%"/5'G4"'#"+)3$"#'&#",*"+'6$(&!':"*9"".'*4"'#"?;%#"@
7".*+',./'&,(,:%3%*%"+O'*4"'/"&3,#%.F':;./3"'%+'.)*',39,1+'*4"'+,7"',+'*4"'4)+*%.F':;./3"5'G4"'#"+)3$@
%.F'(#)&"++'%+'/"+&#%:"/'%.'7&!304$,518(3-&!!').'(,F" PQ5'G4"'/%,F#,77%.F'*"&4.%?;"')-'*4"'
• Visible in the wiring of the bundles
H"?;%#"7".*RE,(,:%3%*1'7)/"3'%+'/"(%&*"/'%.'=%F;#"'S5T2'*4"'/"*,%3+')-'*4"'9%#%.F',#"'-;#*4"#'
"<(3,%."/'%.'9*,'0&1:$($,51;8<1=.&-$%$-"#$3,').'(,F" QSU5
>$5*(&1?@A 7&)*$(&+&,#!1",'1B"."/$0$#$&!1",'1#C&$(1:$($,5
<-=5$#->-%"
*8784$,$";
A5%6,-
<-=5$#->-%"?*8784$,$";
:+1" @#8&>-%" <5%"$>-
!"!"+ ,-./%0$12*$13.*$
19. osgi.ee Capabilities and Requirements
• Replacement for org.osgi.framework.executionenvironment and
Bundle-RequiredExecutionEnvironment
20. osgi.ee Capabilities and Requirements
• Replacement for org.osgi.framework.executionenvironment and
Bundle-RequiredExecutionEnvironment
• Provide-Capability: osgi.ee; osgi.ee="OSGi/Minimum";
version:List<Version>="1.0,1.1,1.2",
osgi.ee; osgi.ee="JavaSE";
version:List<Version>="1.2,1.3,1.4,1.5,1.6"
21. osgi.ee Capabilities and Requirements
• Replacement for org.osgi.framework.executionenvironment and
Bundle-RequiredExecutionEnvironment
• Provide-Capability: osgi.ee; osgi.ee="OSGi/Minimum";
version:List<Version>="1.0,1.1,1.2",
osgi.ee; osgi.ee="JavaSE";
version:List<Version>="1.2,1.3,1.4,1.5,1.6"
• Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)
(version>=1.6))"
23. adapt
• Replacing Framework services
• Bundle was almost always parameter, not very
OO
• The Bundle.adapt method adapts a Bundle object
to another type (if supported)
• <A> A adapt( Class<A> type )
<A>
24. adapt
• Replacing Framework services
• Bundle was almost always parameter, not very
OO
• The Bundle.adapt method adapts a Bundle object
to another type (if supported)
• <A> A adapt( Class<A> type )
<A>
• Returned objects match the life cycle of the
adapted bundle.
26. Replacements
• PackageAdmin service Bundle Wiring API
• BundleWiring wiring =
bundle.adapt(BundleWiring.class)
• StartLevel service Start Level API
• BundleStartLevel bsl =
<A>
bundle.adapt(BundleStartLevel.class)
27. Replacements
• PackageAdmin service Bundle Wiring API
• BundleWiring wiring =
bundle.adapt(BundleWiring.class)
• StartLevel service Start Level API
• BundleStartLevel bsl =
<A>
bundle.adapt(BundleStartLevel.class)
• PackageAdmin and StartLevel are not in Core 4.3
spec but frameworks will still implement them
38. Updating a Bundle
In
Use
Bundle Bundle
Revision Wiring
Bundle
Wire
Current
Bundle Bundle Bundle Bundle Bundle
Revision Wiring Wire Wiring Revision
Bundle Bundle Bundle
Revisions (host) (fragment)
39. Framework Wiring
• System Bundle can be
adapted to control framework
wide actions
Framework
• refresh Wiring
• resolve adapt
System
• dependency closure Bundle
40. StartLevel API
• Bundle Start Level controls
start level information for an
individual bundle Bundle
Start Level
• get/set bundle start level
adapt
Bundle
41. StartLevel API
• Bundle Start Level controls
start level information for an
individual bundle Bundle Framework
Start Level Start Level
• get/set bundle start level
adapt adapt
• Framework Start Level System
controls framework wide start Bundle
Bundle
level information
• get/set framework start
level
• get/set initial bundle start
42. Bytecode Weaving
• Very popular in enterprise
applications
• Need an OSGi standard way to
allow weaving classes when
loading
• Introducing the WeavingHook
service
43. Weaving Hook
• WeavingHook is passed a
WovenClass object
Weaver
• WovenClass allows weaver to
• Mutate class file bytes Weaving Hooks
Woven
Class
• Add dynamic package
import
Framework
• Weaving Hooks called in
ranking order
46. Composite Bundles
• Remember the session on
Composite Bundles from last
year?
• Or the year before?
• Well, if you did attend those
sessions, you can forget what
you heard
47. Composite Bundles
• Remember the session on
Composite Bundles from last
year?
• Or the year before?
• Well, if you did attend those
sessions, you can forget what
you heard
• Replaced by Resolver Hooks
48. Resolver Hook
• Replaces nested frameworks and composite bundles proposals
• Allows influence over resolver’s decisions
• Hook can prevent a requirement from matching a capability
• Primary use case is scoping groups of bundles
• But can be used for other purposes
• Provide primitives to build different scoping models
49. Resolver Hook
• Visitor pattern
• Resolver Hook Factory called
to make a Resolver Hook Resolver
Hook Impl
• Resolver Hook used for one
resolve operation Resolver
Resolver Hook Factory
Hook
• Resolver Hook removes
candidates to constrain the
resolve solution Framework
• Resolver Hooks called in
ranking order
50. Bundle Hooks
• Resolver Hooks alone are not
enough to implement a bundle
scoping solution
• Also need to be able to “hide”
bundles outside a group from
bundles “inside” a group
• Like Service Hooks for
services, Bundle Hooks allow
this for bundles
51. Find Hook and Event
Hook
• Find Hook can hide bundles
from BundleContext
getBundle(long) and
getBundles() methods Bundle Hook
Impl
• Event Hook can hide bundle
events from registered
Find Hook Event Hook
BundleListener and
SynchronousBundleListener
objects
Framework
52. BSN/Version Pair
• In 4.2, there could only be one
bundle installed with a given
Bundle-SymbolicName and
Bundle-Version pair
• Implicit singleton
• With scoping via Resolver
Hooks and Bundle Hooks
• We can allow this invariant
to be broken
53. Launching Property
• Launching framework with the
org.osgi.framework.bsnversion
property set to multiple
• Will allow the invariant to be
broken
• Scoping systems will need to
properly handle
• By default, or with the property set
to single, the invariant is held
54. Service EventListener Hook
• Replaces the Service Event Hook
• Allows finer control over event delivery
• Hook now has access to ListenerInfo for each listener which can receive
the service event
55. A designer knows he has
achieved perfection not
when there is nothing left to
add, but when there is
nothing left to take away.
- Antoine de Saint-Exupéry
56. Next Releases
• Residential 4.3 - Summer 2011
• TR069 support via DMTAdmin enhancements
• Residential DM Tree
• Compendium 4.3 - Fall 2011
• Updates to some Compendium services
• Some new Compendium Services
• Enterprise 4.3 - 2012
• Subsystems
• OBR