OSGi开发之OSGi概念.ppt_第1页
OSGi开发之OSGi概念.ppt_第2页
OSGi开发之OSGi概念.ppt_第3页
OSGi开发之OSGi概念.ppt_第4页
OSGi开发之OSGi概念.ppt_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、OSGi Development,2011-12,目录,OSGi概念 The History of OSGi Program design key point Modularity Cohesion Coupling Encapsulation Granularity Service OSGi features OSGi Layer OSGi Basic Concept Modularity Dynamic Extension OSGi implementaion OSGi开发,OSGi的发展轨迹,UPnP Initial Provisioning Name Space Jini Start

2、Level IO Connector Wire Admin XML Parser Measurement As the OSGi R4 RI; /equinox. Used by Eclipse RCP .,Equinox,Java limited,Java class version Class loader base on classpath to load java class, cant use different version. Authority control by package level

3、 When the class declare as public, all clients can access Manage Dependencies,Yes, there is still a software crisis! Many applications are fragile monoliths with poorly defined dependencies, collaboration points and behavioral responsibilities. Modularity is remarkably hard without OSGi. OSGi enforc

4、es good software modularity. Modularity, it turns out, is the lubricant of collaboration.,The Software Crisis,分工(Division of Labour) 抽象化(Abstraction) 重复使用(Reuse) 容易维护(Ease of Maintenance and Repair),模块化MODULARITY,Self-Contained 完整的逻辑单元 Highly Cohesive 功能紧密 Loosely Coupled 松耦合,MODULE,Wrong!,Right!,Mo

5、dular,模块化的优势,Cohesion?,Cohesion is an inward view of the relevance of the elements of a bundle to one other. In a highly cohesive bundle all parts are directly related to, and focused on, addressing a defined, narrowly focused topic. Sadly, low cohesive bundles are rife. Highly cohesive bundles requ

6、ire careful design to keep them small.,High cohesion,Low cohesion,Coupling?,Coupling is an outward view of the number of relationships between a bundle and other bundles in the system. Bundles should be loosely coupled. A loosely coupled bundle is more likely to be used, reused and tested. “Dont mak

7、e me inflate an entire universe!” Loosely coupled bundles are simpler to understand, test, debug change, etc.,Loose Coupling is Good,Encapsulation,Bundles should be encapsulated from each other. Encapsulation enables loose coupling. Encapsulation enables the hiding of implementation details. A bundl

8、es API should be split into internal and external. Encapsulation at the module level is challenging in Java due to weak visibility rules.,Good Fences Make Good Neighbors,Granularity,Bundle size matters. The size of a bundle affects its coupling and cohesion. Big bundles often have low cohesion and h

9、igh coupling. Big bundles are harder to: Use reuse Test Debug,Size Does Matter,OSGi Services,Bundles can collaborate via the OSGi service registry. A service is just an instance of a POJO class. Services are often stateless. Services must be thread-safe. Multiple implementations and instances of a s

10、ervice are common. Services are dynamically bound and unbound at runtime by either OSGi-specific wiring code, or the Declarative Services runtime.,Not Everything Should be a Service,OSGi Features,Modularity with rule; Dynamic configuration, ”Plug and Play” Extension Best practice guide and support f

11、or building modularity/dynamic/extension system Modularity with rule; Dynamic support for module,OSGi service, Extension support with OSGi service. These features are supported by OSGi, this meaning is that you dont need realize those features by yourself. What you need do is just use it,Universal M

12、iddleware - 是OSGi近年来新取的名词,目标是让OSGi脱离语言限制,成为所有语言的统一模型。,OSGI LAYER,OSGi Layer,Bundles Logical modules that make up an application Service layer Provides communication among modules and their contained components. This layer is tightly integrated with the lifecycle layer. Lifecycle layer Provides acces

13、s to the underlying OSGi framework. This layer handles the lifecycle of individual bundles so you can manage your application dynamically, including starting and stopping bundles. Module layer Provides an API to manage bundle packaging, dependency resolution, and class loading. Execution environment

14、 A configuration of a JVM. This environment uses profiles that define the environment in which bundles can work. Security layer Optional layer based on Java 2 security, with additional constraints and enhancements.,OSGI核心组件,Framework Bundle Service,Bundle,Bundle Container,BundleContext,OSGi Bundles,

15、OSGi中,我们将应用程序模块化成bundle,每个bundle是由一些紧耦合的,动态加载的,类的集合以及明确声明依赖关系的配置文件组成的jar。 Bundle可以在OSGi容器中installed, started, stopped, updated, and removed。 Bundle允许模块之间共享类,这是一种静态重用的形式。当bundle在容器中启动后,它share出来的类即可被其他类引用。 Bundle是jar文件,他的清单文件显式地声明了jar中哪些包对外是可见的(exported packages) ,哪些外部包是本包需要的(imported packages).,简述 OS

16、Gi Service 是一个java class或者服务接口的实例,它具有名值对 OSGi Service通过接口来定义语义,通过一个java对象实现接口。 OSGi服务注册 服务提供者注册服务到服务注册库中,让别的bundle来使用 服务消费者查找服务并与服务提供者绑定,OSGi Service,OSGi Basic Concepts - Modularity,Modularity Define module in OSGi; Publish functions for other modules; Use functions provided by other modules.,Bundl

17、e,Bundle,JAVA,Operating System,Hardware,OSGi Framework,OSGi Basic Concepts - Modularity,Define module in OSGi In OSGi module compose of one or more bundles; Bundle is a normal jar file, the difference is its Manifest.mf file, OSGi add some specical header info property to declarative bundle, such as

18、: bundle-version export-package import-package Publish functions for other bundles add export-package header info to provide package for other bundles to use such as .osgi.ppt.service; add Fragment-Host header info to provide all resources for host bundle to use; publish OSGi service for other

19、 bundles; Use BundleContext.registerService to register normal java interface as OSGi service; Write xml with rule to declarative normal java class as OSGi component, and provide service interface for other bundles, such as:,Use functions provided by other modules add import-package header info to i

20、mport packages provided by other bundles, then you can use the java class in those packages; add require-bundle header info to use all export packages and resources provider by bundle; use OSGi service provided by other bundles; Use BundleContext.getService to get OSGi service provided by other bund

21、les; Write xml with rule to declarative normal java class as OSGi component,and inject OSGi service provided by other bundles, such as:,OSGi Basic Concepts - Modularity,2020/8/12,OSGi Basic Concepts - Dynamic,Dynamic Bundle lifecycle OSGi component lifecycle Handle the dynamic when bundle lifecycle

22、changed; when OSGi component lifecycle changed; when configuration changed; when framework changed; when custom event published;,OSGi provide an API for manageing bundles lifecycle (Install/Resolve/Start/Stop/Refresh/Update/Uninstall),so OSGi framework RI will control bundle lifecycle self;,Componen

23、t that provide no service; when all need OSGi services(exclued optional service) are usable,the component will be actived; Component that provide services; when all need OSGi services(exclued optional service) are usable; other component call this OSGi service implemention.,OSGi Basic Concepts - Dynamic,2020/8/12,22,Handle the dynamic,when bundle lifecycle changed; OSGi component lifecycle will change automatically; OSGi will handle bundle lifecycle dynamic self; when OSGi component lifecycle changed; OSGi service tracker can be used to monitor OSGi service; Declarative Servi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论