OSGI框架—HelloWorld小实例
背景
盟已经开发了例如像HTTP服务器、配置、日志、安全、用户管理、XML等很多公共功能标准组件接口。这些组件的兼容性插件实现可以从进行了不同优化和使用代价的不同计算机服务提供商得到。然而,服务接口能够基于专有权基础上开发。
安全协议
制。例如病毒中经常遇到的缓存溢出是不可能发生的。Java语言中的访问控制符限制了代码可见性。
框架结构
L0:运行环境
标准服务
现这个接口,并在注册服务层注册该服务。服务的客户端在注册库中找到它,或者当它出现或者消失时做出响应。这个同SOA架构使用Web服务进行发布的方式相似。
框架服务
选部分,指示框架的操作。框架服务如下:
系统服务
服务,用户管理服务,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: 2
Bundle-SymbolicName:org.serc.helloworld
Bundle-Version: 1.0
Bundle-Activator:org.serc.helloworld.activator.Activator
Import-Package:org.osgi.framework
Export-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: 2
Bundle-SymbolicName:org.serc.helloworld.client
Bundle-Version: 1.0
Bundle-Activator:org.serc.helloworld.client.HelloUser
Import-Package:org.serc.helloworld;version= "[1.0,2.0)" ,org.osgi.framework
|
相关书籍
编辑
1.《深入理解OSGi:Equinox原理、应用与最佳实践》 [4]
- 参考资料
-
- 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]
转载于:https://www.cnblogs.com/caogen1991/p/9258866.html
OSGI框架—HelloWorld小实例相关推荐
- ssh框架怎么写ajax,SSH框架+Ajax(运用dwr框架)综合小实例[精校版本]
<SSH框架+Ajax(运用dwr框架)综合小实例[精校版本]>由会员分享,可在线阅读,更多相关<SSH框架+Ajax(运用dwr框架)综合小实例[精校版本](36页珍藏版)> ...
- OSGI框架------HelloWorld程序
打开eclipse File->new->other->Plug-in Project 2.填写Project name,选择an OSGI framework 3.下一步选择红线选 ...
- OSGi框架学习------基本概念了解
1.OSGi优点 包的可见性:OSGi通过引入包的可见性机制,能够完全控制一个包中的代码对哪些模块可见,而不仅仅局限于无差别的可见性,从而完善了Java的代码访问控制机制. 包的版本: OSGi通过为 ...
- osgi框架基础原理与实例一
OSGI(Open Services Gateway Initiative),或者通俗点说JAVA动态模块系统,定义了一套模块应用开发的框架.OSGI容器实现方案如Knopflerfish, Equi ...
- 使用Bootstrap框架写的一个小实例
今天学习了一下Bootstrap框架,,写一个小实例练练手,感受一下bootstrap兼容三端的强大. <!doctype html> <html lang="zh-CN& ...
- OSGI框架:模块层、生命周期层、服务层
一.模块层 1. 什么是模块化: 模块层是OSGi框架中最基础的一部分,其中Java的模块化特性在这一层得到了很好的实现.但是这种实现与Java本身现有的一些模块化特性又有明显的不同. 模块化其实就是 ...
- osgi框架的应用_OSGi enRoute – OSGi应用程序的新框架
osgi框架的应用 当我们开始使用OSGi时,就有机会为小型网络网关开发世界一流的框架. 相比之下,今天的Raspberry Pi巨大. 16年后的今天,OSGi是市场上针对Java应用程序的主要模块 ...
- spring+mybatis之声明式事务管理初识(小实例)
前几篇的文章都只是初步学习spring和mybatis框架,所写的实例也都非常简单,所进行的数据访问控制也都很简单,没有加入事务管理.这篇文章将初步接触事务管理. 1.事务管理 理解事务管理之前,先通 ...
- “七层架构”-----实践篇-登录小实例
上一篇博客小编简单介绍了一下近期在软件开发过程中由三层架构演变而来的"七层架构"基本理论点.理论知识与产生结果之间还夹杂着一个重要的点---实践.用实践来检验理论知识,丰富知识内涵 ...
最新文章
- IDEA构建一个mybatis项目
- java里锛是什么意思,java实验总结
- 主宰这个世界的10大算法
- 3详细参数_【前沿】一加7Pro拍照详细参数曝光 3倍光变30W快充
- 3704对象关闭时_JVM 通过逃逸分析就能让对象在栈上分配?没那么简单!
- Pat乙级 1045 快速排序
- [翻译]IE8下VML的变化
- Java程序发送邮件
- Pro *C/C++学习笔记
- 在单个try-with-resources语句中仔细指定多个资源
- Mysql 零距离-入门(五)操作数据表
- 恭祝大家2019新年吉祥顺利!
- tecplot360的宏命令
- 【工具】VirtualBox装VBoxGuestAdditions增强工具失败解决方法和共享文件夹设置
- shell脚本小程序之特洛伊木马示例
- php 怎么使用sql server 2000,Linux下PHP支持MSSQL(SQL Server2000)
- 技术分享 | OceanBase 手滑误删了数据文件怎么办
- 远程连接阿里云服务器一直显示连接失败原因
- 目标检测的国内外研究现状
- 国产步进电机驱动芯片TMI8420,可pin to pin​替代DRV8825