Presentation is loading. Please wait.

Presentation is loading. Please wait.

AQute R4 By Peter Kriens CEO aQute OSGi Technology Officer and OSGi Fellow.

Similar presentations


Presentation on theme: "AQute R4 By Peter Kriens CEO aQute OSGi Technology Officer and OSGi Fellow."— Presentation transcript:

1 aQute R4 By Peter Kriens CEO aQute OSGi Technology Officer and OSGi Fellow

2 ©1999-2004 aQute, All Rights Reserved slide #2 Preliminary a Contents

3 ©1999-2004 aQute, All Rights Reserved slide #3 Preliminary a Bundle Changes In R3 there is no distinction between the classloader and the JAR file. Impossible to get resources from a JAR without creating a class loader: expensive –Bundle.getEntryPaths(String prefix) –Bundle.getEntry(String path) Not possible to load a class explicitly from a bundle –Necessary for the Class.forName pattern –Bundle.loadClass(String class)

4 ©1999-2004 aQute, All Rights Reserved slide #4 Preliminary a Versions In R3 versions are treated as strings In R4, versions will have well defined semantics –... A version class holds those semantics Versions can now also be expressed as ranges: –version-range ::= ('' interval '') | atleast –interval ::= [ '[ | '( ] floor, ceiling [ '] | ') ] –atleast ::= floor | ('' floor '') –floor ::= version –ceiling ::= version

5 ©1999-2004 aQute, All Rights Reserved slide #5 Preliminary a Versions RangeInequality Test [floor,ceiling)floor x < ceiling [floor,ceiling]floor x ceiling (floor,ceiling)floor < x < ceiling (floor,ceiling]floor < x ceiling floorfloor x

6 ©1999-2004 aQute, All Rights Reserved slide #6 Preliminary a New Events Bundle RESOLVED/UNRESOLVED Event –Send out when the bundle is resolved/unresolved to BundleListeners Framework INFO and WARNING events –Send out when there are issues in the Framework that are not not errors but are interesting to know for the operator

7 ©1999-2004 aQute, All Rights Reserved slide #7 Preliminary a Manifest Localization The current bundle manifest contains information about the bundle. Some of this information is human readable. There is no means for this information to be localized when retrieved such as via Bundle.getHeaders() Translations will be supported by using a name starting with a % in the value part of the header This name is then searched in properties file in the bundle

8 ©1999-2004 aQute, All Rights Reserved slide #8 Preliminary a Manifest Localization META-INF/MANIFEST.MF –Bundle-Name: %acmebundle –Bundle-Vendor: %acmecorporation –Bundle-Description: %acmedescription –Bundle-Activator: com.acme.bundle.Activator –Bundle-Localization: localization/bundlemanifest –Acme-Defined-Header: %acme special header localization/bundle_en.properties –acmebundle=The ACME Bundle –acmecorporation=The ACME Corporation –acmedescription=The ACME Bundle provides all of the ACME services –acme special header=User Defined Acme Data

9 ©1999-2004 aQute, All Rights Reserved slide #9 Preliminary a Manifest Localization The Bundle interface defines the following methods to retrieve manifest header information: –getHeaders() - Returns a Dictionary object that contains the bundles manifest headers and values as key/value pairs. The values returned are localized according to the locale returned by java.util.Locale.getDefault. –getHeaders(String locale). - Returns a Dictionary object that contains the bundles manifest headers and values as key/value pairs. The values returned are localized using the specified locale. –getHeaders(null) - The locale returned by java.util.Locale.getDefault is used. –getHeaders() - Will return the raw (unlocalized) manifest headers including any leading %. The getHeaders() methods must continue to provide the manifest header information after the bundle enters the UNINSTALLED state. After the bundle has been uninstalled, this method will only return manifest headers localized for the default locale at the time the bundle was uninstalled. A framework implementation must use only the raw (unlocalized) manifest headers when processing manifest headers that have semantic meaning.

10 ©1999-2004 aQute, All Rights Reserved slide #10 Preliminary a Package Admin Providing Bundle –Information about the bundle that provides a package getProvidingBundles(String symbolicName) getBundles(String symbolicName, String versionRange) getFragments(Bundle host) getHosts(Bundle fragment) getBundleType(Bundle bundle) –BUNDLE_TYPE_FRAGMENT resolveBundles(Bundle[])

11 ©1999-2004 aQute, All Rights Reserved slide #11 Preliminary a Modularization The standard Java platform provides limited support for packaging, deploying, and validating Java-based applications and components. The.NET platform explicitly addresses these issues by introducing assemblies and the Global Assembly Cache (GAC). Assemblies define how applications and application components are packaged and deployed, while the GAC manages the dependencies among assemblies to ensure that they are validly resolved. In Java, the closest analogy to an assembly is a JAR file, but there is no analogy to the GAC. As a result of this, many Java-based projects, such as jBoss and NetBeans, have resorted to creating custom module- oriented layers with specialized class loaders for packaging, deploying, and validating applications and components.

12 ©1999-2004 aQute, All Rights Reserved slide #12 Preliminary a Modularization As an alternative, the OSGi R3 framework provides capabilities that are useful in a generic Java module framework. –A unit of modularization (i.e. a bundle), where the modules export and import packages among each other. –A simple module life cycle. –A framework to manage the module life cycle to ensure validity It is clear from these capabilities that the R3 framework provides a significant improvement over standard Java. However, the R3 framework does have some serious limitations as a generic module framework.

13 ©1999-2004 aQute, All Rights Reserved slide #13 Preliminary a Modularization Specifically, the R3 framework is limited to the following characteristics: –Only one version of a shared package can exist in the JVM among modules at any given time. While it is possible to load multiple versions of a specific package, this can only be accomplished by using private packages that are embedded in the module and which cannot be shared with other modules. –Importing modules do not have any influence over which provider is used to resolve their dependency, other than by specifying a version number. –The version compatibility policy when declaring an import is hard-coded to greater than or equal to a given version number, which is impractical for many real-world project situations. –Exporting modules have no way to indicate that they are providing a related set of packages that must be used in an all-or-nothing fashion. This may be necessary if there are implementation dependencies among packages. Consequently, an importer might get the packages from multiple providers, which would break the implementation dependencies.

14 ©1999-2004 aQute, All Rights Reserved slide #14 Preliminary a Modularization Many of these characteristics are not truly limitations of the OSGi framework –They result from the fact that the framework was not designed to be a generic module framework for Java. Understanding these limitations does, however, provide insight into the degrees of freedom necessary to create a generic module framework for Java

15 ©1999-2004 aQute, All Rights Reserved slide #15 Preliminary a Requirements Static Analysis –Tools Class Sharing –Importing –Exporting –Propagating Version Constraints Provider Selection Package Grouping Package Multiplicity –Singleton Importer Package Exporter A v1 Exporter C v2,x=3 Exporter B v2 Package Import specification Export specification

16 ©1999-2004 aQute, All Rights Reserved slide #16 Preliminary a Modularity headers Export-Package ::= package-description ( ',' package- description )* package-description ::= package-names ( ';' parameter )* package-names ::= package-name ( ; package-name )* package-name ::= parameter ::= attribute '=' value attribute ::= token value ::= token | quoted-string

17 ©1999-2004 aQute, All Rights Reserved slide #17 Preliminary a Modularity Attributes version – the version of the named packages grouping – a string value. Exports, and propagated imports, from a given module with the same value are grouped bundle-symbolic-name – The bundle exporting the package must have this name bundle-version – the bundle version associated with the export statement Arbitrary attributes …

18 ©1999-2004 aQute, All Rights Reserved slide #18 Preliminary a Modularity Import version - a version range to select the exporters implementation version. The default value is 0.0.0. propagate – Imported packages should be made visible so that they can be imported from the propagating module. grouping – Propagated imports, and exports are associated together into an export group resolution –static indicates that the import must be resolved when the importing module is resolved or otherwise fail –optional indicates that the import is optional and the importing module may be resolved without the import being resolved –dynamic indicates that the importing module may be resolved without the import being resolved. An attempt to resolve the import is made as necessary, e.g. during class loading.

19 ©1999-2004 aQute, All Rights Reserved slide #19 Preliminary a Declarative Service: Why? Currently programming for OSGi must take the dynamics of services that come and go into account. This is: –Error prone –Often very disruptive for the programmer –Albeit powerful ???

20 ©1999-2004 aQute, All Rights Reserved slide #20 Preliminary a Declarative Services: Why? Bundles can only be started when their package dependencies are resolved There exists an Import-Service and Export-Service header but this is ignored by the Framework This dependency must thus be handled by the programmer

21 ©1999-2004 aQute, All Rights Reserved slide #21 Preliminary a Declarative Services: Why? Startup time is a significant problem in frameworks like OSGi because of the number of components. It would be preferred to defer initialization until the component is actually needed This will allow the presence of a large number of components at little cost –Lazy Initialization –Creation of class loader must be done as late as possible Eclipses Extension Points taught us a lot! (And our services taught Eclipses team a lot!)

22 ©1999-2004 aQute, All Rights Reserved slide #22 Preliminary a Declarative Services Declarative services use a file in the bundle to specify a Service Component and its dependencies What are Service Components? –A piece of code that runs on an OSGi framework –Defined by a Java interface –May provide an OSGi service to the registry –May depend on a number of services –Will always be executed inside the context of a bundle. I.e. if the bundle is stopped, the component is no longer available –Inherits the bundle dependencies –Activation can be delayed until the component is used

23 ©1999-2004 aQute, All Rights Reserved slide #23 Preliminary a Example declaration { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/2/732811/slides/slide_23.jpg", "name": "©1999-2004 aQute, All Rights Reserved slide #23 Preliminary a Example declaration org.grasso.Quoter Depends on com.ibm.queue org.osgi.service.log IBMOracle com.", "description": "acme. Quoter.", "width": "800" }

24 ©1999-2004 aQute, All Rights Reserved slide #24 Preliminary a Declarative Services: References Each reference to another service has –A name (e.g. log). This name is used to bind the service to the component (push or pull) and/or to configure it –A cardinality (e.g. 1..n). This specifies how many matching services need to be available –A policy (e.g. static) which indicate if the references may be updated or are required to remain constant during the life of the component –A target (e.g. vendor~=IBM), which expresses a filter requirement on the referenced services

25 ©1999-2004 aQute, All Rights Reserved slide #25 Preliminary a Declarative services: Configuration References have a default target definition The default may be overridden with Configuration Admin Each component has a unique id This id is matched to a Configuration object If the Configuration object has a key that matches the references name, that value is used instead com. acme. Quoter Configuration Database com.ibm.queue org.osgi.service.log org.grasso.Quoter OracleIBM target=vendor~=IBM com.acme.quoter: log=vendor~=Oracle

26 ©1999-2004 aQute, All Rights Reserved slide #26 Preliminary a Component API A component becomes available when its dependencies can be fulfilled –An appropriate service is registered –No actual class loading takes place! When the service is used, the component is created by the declarative services runtime If the component implements an activate method, it is called to indicate initialization. The ComponentContext is given as a parameter If the component has implemented bindXXX methods (where XXX is the name of a reference) the runtime will call these methods according to the cardinality and policy The component is then returned as the service Service Factories will be supported as well where the component can be customized for a specific bundle Bind and initialization methods may be private, the runtime will use reflection to call them –This allows the component to be registered as service without exposing public functions that could be abused

27 ©1999-2004 aQute, All Rights Reserved slide #27 Preliminary a Lookup Instead of using a bind model (push) it is also possible to use a pull model The ComponentContext contains a locate() method that allows the component to locate the references. –The parameter of the locate method is the name of the reference –The indirection through configuration management is maintained

28 ©1999-2004 aQute, All Rights Reserved slide #28 Preliminary a Declarative Services: Example The MyValue Service Component is a business process It references two Service Components CustomerInfo –Given the customer identification it provides the symbol of the stock and number of shares. StockQuote –Returns the current value of the stock. The MyValue Service Component calls the CustomerInfo, and with the returned symbol it then calls StockQuote. After that it multiplies the number of shares returned from the CustomerInfo with the quote returned by the StockQuote MyValue service…StockQuote service…CustomerInfo squote cinfo process…MyValue Stock Quote Customer Info

29 ©1999-2004 aQute, All Rights Reserved slide #29 Preliminary a MyValue service…StockQuote service…CustomerInfo squote cinfo process…MyValue Stock Quote Customer Info Declarative Services package service.customerinfo; public interface CustomerInfo { public Customer getCustomerInfo(String customerID); } public class Customer { } package service.customerinfo.impl; import service.customerinfo.*; public class CustomerInfoImpl implements CustomerInfo { public Customer getCustomerInfo(String customerID) { Customer cust = new Customer(); cust.setCustNo(customerID); cust.setName("Victor Hugo"); cust.setSymbol("IBM"); cust.setNumShares(100); cust.setErrorMsg(""); return cust; }

30 ©1999-2004 aQute, All Rights Reserved slide #30 Preliminary a Declarative Services package service.stockquote; public interface StockQuote { public float getQuote(String symbol); } package service.stockquote.impl; import service.stockquote.*; public class StockQuoteImpl implements StockQuote { public float getQuote(String symbol) { // Interaction with business logic would go return 100.0f; } MyValue service…StockQuote service…CustomerInfo squote cinfo process…MyValue Stock Quote Customer Info

31 ©1999-2004 aQute, All Rights Reserved slide #31 Preliminary a Declarative Services: Pop Model package process.myvalue; public interface MyValue { public float myValue(String customerID) throws MyValueException; } package process.myvalue.impl; import process.myvalue.*; import org.osgi.service.component.ComponentContext; public class MyValueImpl implements MyValue { private ComponentContext context; void activate(ComponentContext context) { this.context = context;} public float myValue(String customerID) throws MyValueException { Customer customer = null; float quote = 0, value = 0; CustomerInfo cInfo = (CustomerInfo)context.locateService("customerInfo"); customer = cInfo.getCustomerInfo(customerID); if (customer.getErrorMsg().equals("")) { StockQuote sQuote = (StockQuote)context.locateService("stockQuote"); quote = sQuote.getQuote(customer.getSymbol()); value = quote * customer.getNumShares(); } else throw new MyValueException(customer.getErrorMsg()); return value; } private void deactivate(ComponentContext context) { this.context = null; }} MyValue service…StockQuote service…CustomerInfo squote cinfo process…MyValue Stock Quote Customer Info

32 ©1999-2004 aQute, All Rights Reserved slide #32 Preliminary a Declarative Services MyValue service…StockQuote service…CustomerInfo squote cinfo process…MyValue Stock Quote Customer Info

33 ©1999-2004 aQute, All Rights Reserved slide #33 Preliminary a Declarative Services: Push model package process.myvalue.impl; import process.myvalue.*; public class MyValueImpl implements MyValue { private ComponentContext context; private CustomerInfo cInfo; private StockQuote sQuote; private void bindCustomerInfo(CustomerInfo cInfo) { this.cInfo = cInfo; } private void unbindCustomerInfo(CustomerInfo cInfo) { this.cInfo = null; } private void bindStockQuote(StockQuote sQuote) { this. sQuote = sQuote; } private void unbindStockQuote(StockQuote sQuote) { this. sQuote = null; } public float myValue(String customerID) throws MyValueException { Customer customer = null; float quote = 0, value = 0; customer = cInfo.getCustomerInfo(customerID); if (customer.getErrorMsg().equals("")) { quote = sQuote.getQuote(customer.getSymbol()); value = quote * customer.getNumShares(); } else throw new MyValueException(customer.getErrorMsg()); return value; } MyValue service…StockQuote service…CustomerInfo squote cinfo process…MyValue Stock Quote Customer Info

34 ©1999-2004 aQute, All Rights Reserved slide #34 Preliminary a Relation MEG Application Model The MEG Application Model (which is in development) will likely use the same model as declarative services Current problem is that applications can be launched multiple times and declarative services are singletons

35 ©1999-2004 aQute, All Rights Reserved slide #35 Preliminary a Native Code Changes Native Code Matching Enhancements –Operating system name –Operating system version –Processor –Language Eclipse showed the need to extend the selection criteria –SWT depends not only on OS, but also on selected higher layers like Motif –Added an optional filter for additional selection criteria. Sometimes libraries are optional, this could not be expressed. A missing library meant the bundle could not resolve –* at end is used to indicate that the header can match without matching a particularly library

36 ©1999-2004 aQute, All Rights Reserved slide #36 Preliminary a Native Code Changes Bundle-NativeCode ::= nativecode-clause (, nativecode-clause )* (, optional-clause )? nativecode-clause ::= nativepath ( ; nativepath )* ( ; parameter )* nativepaths ::= jar-path | (jar-path) parameter ::= ( processordef | osnamedef | osversiondef | languagedef | filterdef ) processordef ::= processor = value osnamedef ::= osname = value osversiondef ::= osversion = version-range languagedef ::= language = value filterdef ::= selection-filter = quoted-string value ::= token | quoted-string optional-clause ::= *

37 ©1999-2004 aQute, All Rights Reserved slide #37 Preliminary a Permissions Bundles can be signed with public key encryption Permission Admin can associate a signer with a set of permissions Bundles that are downloaded can also contain a permission file that limits those permissions –Can not extend the signers scope This allows the signer to control the permissions used on the system It allows the operator to still control the maximum allowed permissions Developer Signer Operator Specifies Needed permission Verifies Permissions And fixes them Encloses Permissions OSGi Environment Download and Check permissions As defined by signer Not allowing more than signer

38 ©1999-2004 aQute, All Rights Reserved slide #38 Preliminary a AdminPermission OSGi R3 has an AdminPermission that is very coarse –No parameters, i.e. a blank permission –Implicit assumption that there is only a single management agent The enterprise model (where the Enterprise can manage part of the device) collides with this assumption R4 will therefore have an AdminPermission that will take parameters –The target of the permission is the bundle –The bundle can be identified by the signer or the id The action represents all places where AdminPermission is currently used Admin Permission Admin Permission Admin Permission Admin Permission Admin Permission Admin Permission

39 ©1999-2004 aQute, All Rights Reserved slide #39 Preliminary a aQute www.aQute.biz +46 300 39800, Peter.Kriens@aQute.biz


Download ppt "AQute R4 By Peter Kriens CEO aQute OSGi Technology Officer and OSGi Fellow."

Similar presentations


Ads by Google