OSGI框架—HelloWorld小实例
背景
OSGI 盟已经开发了例如像HTTP服务器、配置、日志、安全、用户管理、XML等很多公共功能标准组件接口。这些组件的兼容性插件实现可以从进行了不同优化和使用代价的不同计算机服务提供商得到。然而,服务接口能够基于专有权基础上开发。
安全协议
框架结构
OSGI L0:运行环境

标准服务
OSGI 现这个接口,并在注册服务层注册该服务。服务的客户端在注册库中找到它,或者当它出现或者消失时做出响应。这个同SOA架构使用Web服务进行发布的方式相似。
框架服务
OSGI 选部分,指示框架的操作。框架服务如下:
系统服务
OSGI 服务,用户管理服务,IO连接器服务和参数服务都是系统服务的一个方面。
HelloWorld


|
install [URL]
|
将URL表示的bundle安装到框架中
|
|
uninstall [bundleID]
|
将id=bundleID的bundle卸载
|
|
start [bundleID]
|
启动一个bundle
|
|
stop [bundleID]
|
停止一个bundle
|
|
refresh [bundleID]
|
刷新bundle
|
|
update [bundleID]
|
更新bundle 的内容
|
|
ss
|
简单显示所有bundle的状态
|
|
status
|
展示安装的bundle和注册的服务
|
|
headers [bundleID]
|
展示bundle 的manifest中的元数据
|









|
1
2
3
4
|
package org.serc.helloworld;public interface Hello { void sayHello();} |
|
1
2
3
4
5
6
7
8
9
10
|
package org.serc.helloworld.impl;public class HelloImpl implements Hello{ final String helloString; public HelloImpl(String helloString){ this.helloString= helloString; } public void sayHello(){ System.out.println(this.helloString); }} |
|
1
|
Export-Package: org.serc.helloworld;version="1.0" |
|
1
2
3
4
5
6
7
8
9
10
11
12
|
package org.serc.helloworld.activator;public class Activator implements BundleActivator { private List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>(); public void start(BundleContext ctx) { registrations.add(ctx.registerService(Hello.class.getName(),new HelloImpl("Hello, OSGi"), null)); } public void stop(BundleContext ctx) { for(ServiceRegistration registration : registrations) { System.out.println("unregistering:"+ registration); registration.unregister(); }} |
|
1
|
Bundle-Activator:org.serc.helloworld.activator.Activator |
|
1
2
3
4
5
6
|
Bundle-ManifestVersion:2Bundle-SymbolicName:org.serc.helloworldBundle-Version:1.0Bundle-Activator:org.serc.helloworld.activator.ActivatorImport-Package:org.osgi.frameworkExport-Package: org.serc.helloworld;version="1.0" |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package org.serc.helloworld.client;public class HelloUser implements BundleActivator { public void start(BundleContext ctx) { ServiceReference ref = ctx.getServiceReference(Hello.class.getName()); if(ref != null) { Hello hello = null; try{ hello= (Hello) ctx.getService(ref); if(hello != null) hello.sayHello(); else System.out.println("Service:Hello---objectnull"); }catch (RuntimeException e) { e.printStackTrace(); }finally { ctx.ungetService(ref); hello= null; } }else { System.out.println("Service:Hello---notexists"); } } public void stop(BundleContext ctx) throws Exception { }} |
|
1
2
3
4
5
|
Bundle-ManifestVersion:2Bundle-SymbolicName:org.serc.helloworld.clientBundle-Version:1.0Bundle-Activator:org.serc.helloworld.client.HelloUserImport-Package:org.serc.helloworld;version="[1.0,2.0)",org.osgi.framework |




相关书籍
深入理解OSGi
1.《深入理解OSGi:Equinox原理、应用与最佳实践》
[4]
R5.0中的核心规范进行了全面的解读,首先讲解了OSGi模块的建立、描述、依赖关系的处理,然后讲解了Bundle的启动原理和调度管理,最后讲解了与本地及远程服务相关的内容。第三部分:OSGi服务与Equinox应用实践(第5~11章),不仅详细讲解了OSGi服务纲要规范和企业级规范中最常用的几个子规范和服务的技术细节,还通过一个基于Equinox的BBS案例演示了Equinox的使用方法,最重要的是还通过源码分析了Equinox关键功能的实现机制和原理。第四部分:最佳实践(第12~14章),总结了大量关于OSGi的最佳实践,包括从Bundle如何命名、模块划分、依赖关系处理到保持OSGi动态性、管理程序启动顺序、使用API基线管理模块版本等各方面的实践技巧,此外还介绍了Spring
DM的原理以及如何在OSGi环节中进行程序测试。
[5]
Eclipse RCP与Spring OSGi
RCP相关的一系列核心概念、Eclipse
RCP开发环境的搭建,以及SWT、JFace、Forms、Nebula和WindowBuilder等Eclipse
RCP开发所常用的界面编程技术;高级篇(第6~12章)系统讲解了Eclipse RCP应用开发的基础知识、Eclipse
RCP软件产品各个组成部分的构建方法,以及Eclipse
RCP扩展的使用和扩展点的开发,掌握这些技术知识的读者将能构建一个结构完整的Eclipse
RCP软件,并解决软件开发过程中遇到的故障;实战篇(第13~15章)详细讲解了Eclipse RCP与Spring
OSGi框架、Hibernate ORM框架、JPA规范、Maven工具的整合,以及它与Java的模块化设计。
[6]
- 参考资料
-
- 1.
OSGi入门教程
.天码营[引用日期2015-12-28] - 2.
动态模型系统 OSGi
.开源社区网[引用日期2012-08-18] - 3.
OSGi开发环境建立和Hello World
.osgi中文社区[引用日期2013-05-28] - 4.
周志明,谢小明.《深入理解OSGi:Equinox原理、应用与最佳实践》.北京:机械工业出版社,2013:I-II
- 5.
陆阳.《Eclipse RCP与Spring OSGi:技术详解与最佳实践》.北京:机械工业出版社,2013:I-II
- 6.
软件工程国家工程研究中心
.北大未名站[引用日期2013-05-28]
- 1.
OSGI框架—HelloWorld小实例的更多相关文章
- ssh框架的小实例(用户登录)
刚学SSH框架写一个小实例,以便以后查看: 本案例简单的实现一个用户登录: 数据库方面就不写了,自己领悟吧!哈哈(根据user.hbm.xml文件就知道了) 我们一般可以创建下面几个包,什么意思呢,自 ...
- Spring3.0 与 MyBatis框架 整合小实例
本文将在Eclipse开发环境下,采用Spring MVC + Spring + MyBatis + Maven + Log4J 框架搭建一个Java web 项目. 1. 环境准备: 1.1 创建数 ...
- [置顶] Cocos2d-x 实例源码分析之二 小实例的主框架
这篇文章是分析第一个小实例ActionTest的源码.其实所有实例程序的结构都是一样的,只有特定方法里的代码不同,大的框架都是一样的.也就是说看完这篇文章你就可以自己开始分析其他源码了. 废话不多说, ...
- 从一个简单的小实例分析JSP+Servelt与JSP+Struts2框架的区别
最近在学struts2,struts2相比以前的JSP+Servlet,在处理流程上的更简单,我们就一个小实例来具体分析一下. 实例内容如下: 实现一个简单的注册页面包括:用户名.密码.重复密码.年龄 ...
- MVC框架模式技术实例(用到隐藏帧、json、仿Ajax、Dom4j、jstl、el等)
前言: 刚刚学完了MVC,根据自己的感悟和理解写了一个小项目. 完全按照MVC模式,后面有一个MVC的理解示意图. 用MVC模式重新完成了联系人的管理系统: 用户需求: 多用户系统,提供用户注册.登录 ...
- Spring初识(通过小实例清晰认识Spring)
1.spring架构: spring是J2EE应用程序框架,是轻量级的IoC和AOP的容器框架,主要是针对javaBean的生命周期进行管理的轻量级容器,可以单独使用,也可以和Struts框架,iba ...
- spring+mybatis之声明式事务管理初识(小实例)
前几篇的文章都只是初步学习spring和mybatis框架,所写的实例也都非常简单,所进行的数据访问控制也都很简单,没有加入事务管理.这篇文章将初步接触事务管理. 1.事务管理 理解事务管理之前,先通 ...
- Springboot Application 集成 OSGI 框架开发
内容来源:https://www.ibm.com/developerworks/cn/java/j-springboot-application-integrated-osgi-framework-d ...
- Eclipse IDE下的Spring框架使用简单实例
Eclipse IDE下的Spring框架使用简单实例 1 准备Java jdk安装. Eclipse软件安装.根据系统安装32/64版本,选择Eclipse IDE for Java Develop ...
随机推荐
- jquery 获取绑定事件
在1.8.0版本之前,我们要想获取某个DOM绑定的事件处理程序可以这样: 1 $.data(domObj,'events');//或者$('selector').data('events') 而从1. ...
- FreeRTOS 任务计数信号量,任务二值信号量,任务事件标志组,任务消息邮箱
以下基础内容转载自安富莱电子: http://forum.armfly.com/forum.php 本章节为大家讲解 FreeRTOS 计数信号量的另一种实现方式----基于任务通知(Task Not ...
- Mysql定时备份数据脚本
项目集群搭建完成,数据库虽有做主从同步,但考虑到数据安全性,为了满足这个需求那么要每天对数据备份处理, 但每天手动进行备份处理太过于被动,而且白天用户访问,会有数据变化以及在备份时会影响服务器正常运行 ...
- python学习笔记(9)--Python UnicodeEncodeError: 'gbk' codec can't encode character 解决方法
Python UnicodeEncodeError: 'gbk' codec can't encode character 解决方法 这篇文章主要介绍了Python UnicodeEncodeErro ...
- 代码审计之Finecms任意文件下载漏洞
PS:该漏洞已被公布,只是学习.故自己跟着大佬的步伐审计. 文件地址:\controllers\ApiController.php Line 57 public function downAction ...
- Qt中将QString转换为char *或者相反
1.将QString转换为std::string,可以通过QString的成员函数toStdString() QString Qstr="123";std::string str= ...
- exit会结束一个进程
#include <stdio.h> #include <unistd.h> #include <sys/types.h> #include<stdlib.h ...
- at91 uart driver for vxworks
/* at91UART.c - AT91RM9200 serial driver */ /* Copyright 2003-2004 Coordinate Co., Ltd. */ /* Copyri ...
- 在CentOS中编译FFmpeg for Android静态库(含fdk aac,x264)
本文可以编译出集成了x264和fdk_aac的库,而且支持neon 下载源码: https://github.com/mstorsjo/fdk-aac http://sourceforge.net/p ...
- springMVC介绍
http://www.iteye.com/blogs/subjects/springMVC —————————————————————————————————————————————————————— ...

