marcel offermans - connecting repositories · luminis osgi history • started as an embedded...
TRANSCRIPT
luminis
Introduction to OSGiMarcel Offermans
luminis
Introduction
• Marcel Offermans
• Luminis
• IT solutions from idea toimplementation
• with and for customers:consultancy and projects
• experts in Java, OSGi, .NET,Agile/Scrum
• Apache Felix and Ace PMC
Enschede
image © 2008 Google Earth
ApeldoornArnhem
luminis
Agenda
• History of OSGi
• The Framework
• The Compendium
• Patterns, Models & Embedding
• Open Source Frameworks
luminis
OSGi history
• Started as an embedded platform for the “home gateway”
• Originally under the JCP as JSR-8 (1999)
• OSGi alliance, consists of a large number of big companies, with the following mission:
• Maintaining and publicizing the OSGi specification.
• Certifying implementations.
• Organising events.
• Current version: OSGi Release 4.1 (JSR-291)
luminis
OSGi releases
• R1: may 2000
• R2: october 2001
• Java Embedded Server (Sun), Oscar (SourceForge)
• R3: march 2003
• Knopflerfish
• R4: august 2005
• IBM joined and influenced this release, Equinox (Eclipse Foundation)
• R4.1: april 2007
luminis
OSGi today
OSGi technology is the dynamic module system for Java™
OSGi technology is Universal Middleware.
OSGi technology provides a service-oriented, component-based environment for developers and offers standardized ways to manage the software lifecycle. These capabilities greatly increase the value of a wide range of computers and devices that use the Java™ platform.
luminis
OSGi Alliance
• Expert Groups:
• core platform (CPEG)
• mobile (MEG)
• vehicle (VEG)
• enterprise (EEG)
• residential (REG)
• Working Groups:
• marketing
• requirements
luminis
OSGi specification
!"#$%"&'($)&%*+,-./'0"&'($)&%1/02&34$5067&%!"#$%8++$,3)&
9&+&,:&%;<%=&':$/3%;>?82'$+%@AAB
OSGi Alliance
Digitally signed by OSGi Alliance DN: cn=OSGi Alliance, c=US Date: 2007.02.22 14:44:10 + 01'00'
Signatu re Not Verified
!"#$%"&'($)&%*+,-./'01/'&%"2&)$.$),-$/345&%!"#$%6++$,3)&
7&+&,8&%9:%;&'8$/3%9<=62'$+%>??@
OSGi Alliance
Digitally signed by OSGi Alliance DN: cn=OSGi Alliance, c=US Date: 2007.02.22 14:45:47 + 01'00'
Signatur e Not Verified
luminis
OSGi Framework Layering
L3 - Provides a publish/find/bind service model to decouple bundles
L2 - Manages the life cycle of a bundle in a framework without requiring the vm to be restarted
L1 - Creates the concept of a module (aka. bundles) that use classes from each other in a controlled way according to system and bundle constraints
L0 - well defined profiles that define the environment in which bundles can work, ie:* CDC/Foundation* JavaSE-6
SERVICE MODEL
MODULE
LIFE-CYCLE
ExecutionEnvironment
luminis
Module Layer (1/3)
• Unit of deploymentis the bundle i.e., a JAR
• Separate class loaderper bundle
• Class loader graph
• Independent namespaces
• Class sharing at the Java package level
Module
ModuleBundle Bundle Bundle
org.apache.utils 1.0
org.apache.utils 1.1org.apache.log 2.3
org.apache.db 1.4
Bundle
exports
imports
exports
imports
exports
exports
luminis
Module Layer (2/3)
• Multi-version support
• i.e., side-by-side versions
• Explicit code boundaries and dependencies
• i.e., package imports and exports
• Support for various sharing policies
• i.e., arbitrary version range support
• Arbitrary export/import attributes
• Influence package selection Module
luminis
Module Layer (3/3)
• Sophisticated class space consistency model
• Ensures code constraints are not violated
• Package filtering for fine-grained class visibility
• Exporters may include/exclude specific classes from exported package
• Bundle fragments
• A single logical module in multiple physical bundles
• Bundle dependencies
• Allows for tight coupling when required Module
luminis
Manifest
Bundle-Name: Example BundleBundle-SymbolicName: net.luminis.example.bundleBundle-Version: 1.0.0DynamicImport-Package: net.luminis.jdbc.*Import-Package: org.osgi.framework;version=“1.3“, org.osgi.service.event;version=“[1.1,2.0)“, net.luminis.foo;resolution:=“optional“Export-Package: org.osgi.service.event;uses:=org.osgi.framework;version=“1.1“Bundle-ManifestVersion: 2
luminis
Life-cycle Layer
• Managed life cycle
• States for each bundle;
• Allows updates of existing bundles
• Dynamically install, start, update, and uninstall
Life-cycle
Life-cycle
start
end
installedinstall
startingstart
stopping stop
activeresolved
uninstalled
uninstall
Module
luminis
Life-cycle Example
Bundle
OSGi Framework
luminis
Life-cycle Example
Bundle
OSGi Framework
Provided Package
luminis
Life-cycle Example
Bundle
OSGi Framework
Bundle
Install
Bundle
luminis
Life-cycle Example
Bundle
OSGi Framework
Bundle
Resolve
Bundle
luminis
Service Layer
• OSGi framework promotes service oriented interaction pattern among bundles
Service
Service
Log Database
Bundle Bundle Bundle
publish useuse
publish
Bundle
Prefs
publish
use
Service Provider
Service Requester
Service Registry
interact
publish find
Life-cycle
Module
luminis
Service Example
Bundle
OSGi Framework
luminis
Service Example
Bundle
OSGi Framework
Provided Package
Provided Service
luminis
Service Example
Bundle
OSGi Framework
Bundle
Install
Bundle
luminis
Service Example
Bundle
OSGi Framework
Bundle
Resolve
Bundle
luminis
Service Example
� � � � �
� � � � � � � � � � � � �
� � � � �
� � � � � � � �� � � � � �
luminis
Security Concepts Overview
• Codebased security of the Java Security Model
• Makes use of Protection Domain
• The stack walk based Permission Check
• Signed bundles
• User based security is supported by the UserAdmin service but not integrated in the standard permission check as with JAAS
• PermissionAdmin and ConditionalPermissionAdmin servicesprovide management infrastructure
Security
Module
Life-cycle
Service
luminis
Conditional Permission Admin
• New (4.0) way of doing permission management
• use this exclusively for new implementations
• interoperability when both PA and CPA are present
• IF all conditions of a set of conditions match THEN apply the supplied permissions
• More flexible, extensible model
• Conditions evaluation is highly optimized
luminis
Example
ConditionalPermissionAdmin condPermAdmin = getConditionalPermissionAdmin();
condPermAdmin.addConditionalPermissionInfo( new ConditionInfo[] { new ConditionInfo( BundleLocationCondition.class.getName(), new String[] {"*://www.luminis.nl/*"}) }, new PermissionInfo[] { new PermissionInfo(AdminPermission.class.getName(), "*", "*"), new PermissionInfo(ServicePermission.class.getName(), "*", ServicePermission.GET), new PermissionInfo(ServicePermission.class.getName(), "net.luminis.service.*", ServicePermission.REGISTER), new PermissionInfo(PackagePermission.class.getName(), "net.luminis.service.*", PackagePermission.EXPORT), new PermissionInfo(PropertyPermission.class.getName(), "*", "read") });
luminis
Signing bundles in Eclipse
luminis
BundleSignerCondition
• Condition to test if the signer of a bundle matches a pattern
• Uses the wildcard matching
condPermAdmin.addConditionalPermissionInfo(new ConditionInfo[]{ new ConditionInfo(BundleSignerCondition.class.getName(),
new String[]{"*,o=luminis"}) }, ALLPERMISSION_INFO);
luminis
Local Permissions
• Defined in a resource inside the bundle
• Defines a set of permissions that are enforced by the framework
• A bundle can get less than these permissions, but never more
• Defaults to All Permissions
• Good way for operators to “audit” the permissions of a bundle
luminis
Local Permissions Example
• OSGI-INF/permissions.perm
( ..ServicePermission "..log.LogService" "GET" ) ( ..PackagePermission "..log" "IMPORT" ) ( ..ServicePermission "..cm.ManagedService" "REGISTER" )( ..PackagePermission "..cm" "IMPORT" ) ( ..ServicePermission "..useradmin.UserAdmin" "GET" ) ( ..PackagePermission "..cm" "SET" ) ( ..PackagePermission "com.acme.chess" "IMPORT,EXPORT" ) ( ..PackagePermission "com.acme.score" "IMPORT" )
luminis
Agenda
• History of OSGi
• The Framework
• The Compendium
• Patterns, Models & Embedding
• Open Source Frameworks
luminis
OSGi compendium
Log
HTTP
Device Access
Configuration AdminPreferences
Metatype
Wire AdminUser Admin
IO Connector
Initial Provisioning
UPnP™ Device
Declarative Services
Event Admin Service Tracker
XML Parser
Position
Measurement and State
Execution Environment Spec
!"#$%"&'($)&%*+,-./'0"&'($)&%1/02&34$5067&%!"#$%8++$,3)&
9&+&,:&%;<%=&':$/3%;>?82'$+%@AAB
OSGi Alliance
Digitally signed by OSGi Alliance DN: cn=OSGi Alliance, c=US Date: 2007.02.22 14:44:10 + 01'00'
Signatu re Not Verified
luminis
User Admin
• Used in any application that needs role based access control
• Provides: users, roles and groups
• Can authenticate users
• Can determine autorization for authenticated users
• Fairly easy to plug-in to HTTP, SOAP, RMI, JMX or anything else
luminis
Config Admin
• Configuration Admin:
• contains externally configurable settings for a service;
• allows manage-ment systems to configure all settings;
• settings can becreated even before theactual bundle is installed.
!"#$%"&'($)&%*+,-./'0%1&+&,2&%3 456357
8/9.$:;',-$/9%<=0$9%"&'($)&%">&)$.$),-$/9%%?&'2$/9%@A7 B9-'/=;)-$/9
!"# $%&'()*+,-(%&./01(&.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&$."-.$-$
?+'06#$4-'$4,#-.#$."#$-55,&5,)-.#$'+1?#,$&($2#,3)4#2$+'0#,$."#$4&'.,&6$
&($."#$%&'()*+,-.)&'$/01)'$2#,3)4#<
!"#$%&'()*#(%&
!"#$%+,-'()*#(%+$#*(
C;9=+&=&(&+/>&'
D'$-&2,%C;9=+&
C;9=+&%$2=&>+/E&=
)/9.$:;',-$/9
8/9.$:;',-$/9<=0$9
=,-,
luminis
Event Admin
• Publish subscribe
• Asynchronous and synchronous
• Hierarchical topics
• Used within OSGi too
!"#$%"&'($)&%*+,-./'0%1&+&,2&%3 4567348
9(&:-%;<0$:%"&'($)&%"=&)$.$),-$/:%%>&'2$/:%5?@ 9(&:-%;<0$:%;')A$-&)-B'&
! !"#$%&'()*+,-#.,"#"$%&"!"#$%&'()*+,-#."'(")*+& ,-.")/'012&3"*("1(4/'5
26741'("'8"%'9"4'"9/14&"*(":0&(4";6<=13%&/>"$%&"!"#$%&/01+$&/.2-+%#2%(.#"
'(")*+& ,-?")/'012&3"*"+''2"'0&/01&9"'8"4%&"2&31+(>
! !"#$%&3(),2.+)#.,456$0*#.,"#"$%&"!"#$%&56$0*#."'(")*+& ,-@")/'012&3"4%&"
/6=&3"'("%'9"4'"36<37/1<&"*(2"%*(2=&"&0&(43>
!!"#$ %&'()*+,-.(*+/01.)'0)2/'
$%&":0&(4"A2B1("13"<*3&2"'("4%&"'()*+,-73(),2.+)#")*44&/(>"$%13")*44&/("
2&7'6)=&3"3'6/7&3"8/'B"4%&1/"%*(2=&/3"<C"1(4&/)'31(+"*("#"#$%&2-6$$#*"
<&49&&("4%&B>"$%&")6<=13%&/")'343"&0&(43"4'"4%&"7%*((&=D"9%17%"12&(4181&3"
9%17%"%*(2=&/3"(&&2"4'"<&"('4181&2"*(2"4%&("4*E&3"7*/&"'8"4%&"('41817*41'("
)/'7&33>"$%13"B'2&="13"2&)174&2"1("F1+6/&"?G>
8+9(.#&:; <-6$$#*&'6%%#.$
H("4%13"B'2&=D"4%&"&0&(4"3'6/7&"*(2"&0&(4"%*(2=&/"*/&"7'B)=&4&=C"2&7'6)=&2"
<&7*63&"(&14%&/"%*3"*(C"21/&74"E('9=&2+&"'8"4%&"'4%&/>"$%&"7'B)=17*4&2"
='+17"'8"B'(14'/1(+"7%*(+&3"1("4%&"&0&(4")6<=13%&/3"*(2"&0&(4"%*(2=&/3"13"
7'B)=&4&=C"7'(4*1(&2"914%1("4%&"&0&(4"7%*((&=>"$%13"13"%1+%=C"*20*(4*5
+&'63"1("*("IJK1"&(01/'(B&(4"<&7*63&"14"31B)=181&3"4%&")/'7&33"'8"<'4%"
3&(21(+"*(2"/&7&101(+"&0&(43>
!!"#" 31'*%&'()
:0&(43"%*0&"4%&"8'=='91(+"*44/1<64&3L
! =>?+2"#"A"4')17"4%*4"2&81(&3"9%*4"%*))&(&2>"F'/"&M*B)=&D"9%&("*"<6(2=&"
13"34*/4&2"*("&0&(4"13")6<=13%&2"4%*4"%*3"*"4')17"'8"!"#$!%#&$ ' "()*+!",$
-./01*23*/4$5678629 >
! '.>?#.%+#,"#"N&/'"'/"B'/&")/')&/41&3"4%*4"7'(4*1("*22141'(*="1(8'/B*41'("
*<'64"4%&"&0&(4>"F'/"&M*B)=&D"4%&")/&01'63"&M*B)=&"&0&(4"%*3"*")/')&/4C"
'8":./01*; &0 "9%17%"13"3&4"4'"*"<!/# "'<O&74D"*B'(+"'4%&/")/')&/41&3>
!!"#"#! 345.06
$%&"4')17"'8"*("&0&(4"2&81(&3"4%&"%@?#"'8"4%&"&0&(4>"H4"13"8*1/=C"+/*(6=*/"1("
'/2&/"4'"+10&"%*(2=&/3"4%&"'))'/46(14C"4'"/&+134&/"8'/"O634"4%&"&0&(43"4%&C"*/&"
1(4&/&34&2"1(>"P%&("*"4')17"13"2&31+(&2D"143"(*B&"3%'6=2"('4"1(7=62&"*(C"
'4%&/"1(8'/B*41'(D"367%"*3"4%&")6<=13%&/"'8"4%&"&0&(4"'/"4%&"2*4*"*33'71*4&2"
914%"4%&"&0&(4D"4%'3&")*/43"*/&"1(4&(2&2"4'"<&"34'/&2"1("4%&"&0&(4")/')&/41&3>
$%&"4')17"13"1(4&(2&2"4'"3&/0&"*3"*"81/345=&0&="81=4&/"8'/"2&4&/B1(1(+"9%17%"
%*(2=&/3"3%'6=2"/&7&10&"4%&"&0&(4>":0&(4"A2B1("3&/017&"1B)=&B&(4*41'(3"
63&"4%&"34/6746/&"'8"4%&"4')17"4'"')41B1Q&"4%&"213)*47%1(+"'8"4%&"&0&(43"4'"4%&"
%*(2=&/3>
=.:1&%>*" ??%*"3&@*AA23*/4B(/01*"
5@??:
??%*"3&@*AA%&'()*+,-.(
5@??:
2&:<9(&:- A,:<+&9(&:-
=/2-9(&:-
luminis
Event AdminExample
class Subscriber implements BundleActivator, EventHandler { final static String[] topics = new String[] { "org/osgi/service/log/LogEntry/LOG_WARNING", "org/osgi/service/log/LogEntry/LOG_ERROR" };
public void start(BundleContext context) { Dictionary d = new Hashtable(); d.put(EventConstants.EVENT_TOPIC, topics); d.put(EventConstants.EVENT_FILTER, "(bundle.symbolicName=com.acme.*)"); context.registerService(EventHandler.class.getName(), this, d); } public void stop(BundleContext context) { }
public void handleEvent(Event event) { //... }}
class Publisher { EventAdmin m_eventAdmin;
public void send() { if (m_eventAdmin != null) { Dictionary properties = new Hashtable(); properties.put("timestamp", new Date()); m_eventAdmin.sendEvent(new Event("com/acme/timer", properties)); } }}
luminis38
Preferences
• Preferences:
• contains bundle privatesettings;
• is coupled to the bundlelife-cycle;
• like the standard Java APIthere is a notion of systemand user preferences perbundle.
luminis
Agenda
• History of OSGi
• The Framework
• The Compendium
• Patterns, Models & Embedding
• Open Source Frameworks
luminis
Service Whiteboard Pattern
• Instead of having clients look up and use a service interface, have clients register a service interface to express their interest
• The service tracks the registered client interfaces and calls them when appropriate
• This is called the Whiteboard pattern
• It can be considered an Inversion of Control pattern
luminis
Service vs. Extender Models
• Two different approaches for adding extensibility to an OSGi-based application
• The service-based approach uses the OSGi service concept and the service registry as the extensibility mechanism
• The extender-based approach uses the OSGi installed bundle set as the extensibility mechanism
• Advantages and disadvantages for each
• Can be used independently or together
luminis
Example code
http://felix.apache.org/site/apache-felix-application-demonstration.html
luminis
Bundled vs. Hosted
• Applications can leverage OSGi functionality in two ways
• Bundled application
• Build entire application as a set of bundles that will run on top of a framework instance
• Hosted framework
• Host a framework instance inside the application and externally interact with bundles/services
luminis
Hosted Framework
• More complicated due to external/internal gap between application and framework
• e.g., unlike bundles the host application does not have a bundle context by which it can access framework services
• Requires host/framework interactions
• Accessing framework
• Providing services to bundles
• Using services from bundles
• Standardized API is in progress for R4.2
luminis
Hosted Framework
• Felix tries to simplify hosted framework scenarios
• Configuration data is passed into framework constructor
• Felix framework is the System Bundle
• Gives the host application an intuitive way to access framework functionality
• Felix constructor also accepts „constructor activators“ to extend system bundle
• Felix tries to multiplex singleton resources to allow for multiple framework instances
luminis
Hosted Framework
public class Main { private static Felix m_felix = null; public static void main(String[] args) throws Exception { Map configMap = new HashMap(); configMap.put(AutoActivator.AUTO_START_PROP + ".1", "file:bundle/org.apache.felix.shell-1.0.2.jar " + "file:bundle/org.apache.felix.shell.tui-1.0.2.jar"); List list = new ArrayList(); list.add(new AutoActivator(configMap)); configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list); try { m_felix = new Felix(configMap); m_felix.start(); m_felix.waitForStop(); System.exit(0); } catch (Exception ex) { System.err.println("Could not create framework: " + ex); ex.printStackTrace(); System.exit(-1); } }}
luminis
Hosted Framework
• Providing a host application service:
• Accessing internal bundle services:
BundleContext bc = felix.getBundleContext();bc.registerService(Service.class, svcObj, null);
BundleContext bc = felix.getBundleContext();ServiceReference ref = bc.getServiceReference(Service.class);Service svcObj = (Service) bc.getService(ref);
luminis
Hosted Framework
• Classes shared among host application and bundles must be on the application class path
• Disadvantage of hosted framework approach, which limits dynamics
• Use of reflection by host to access bundle services can eliminate this issue, but it is still not an optimal solution
• In summary, better to completely bundle your application if possible
luminis
Open Source Implementations
• Apache Felix: http://felix.apache.org/
• R4, originally called Oscar
• Knopflerfish 2: http://www.knopflerfish.org/
• R4, open source version of UbiServ by Makewave
• Equinox: http://www.eclipse.org/equinox/
• R4, initially developed for Eclipse and the RCP
• Concierge: http://concierge.sourceforge.net/
• R3, optimized for resource constrained environments
luminis
Agenda
• History of OSGi
• The Framework
• The Compendium
• Patterns, Models & Embedding
• Open Source Frameworks
luminis
Coming soon:
• software distribution
• configuration management
• just started in the Apache Incubator
luminis
Any questions?
? & !