OSGI CM之ManagedService的使用
2015-12-01 09:57
295 查看
OSGI里面用于操作配置文件(cfg)的接口有2个
org.osgi.service.cm.ManagedService 用于操作单个配置文件
org.osgi.service.cm.ManagedServiceFactory 用于操作一组相关的配置文件 用法见 OSGI CM之ManagedServiceFactory的使用
org.osgi.service.cm.ManagedService可以实现,文件改动就会收到通知的效果,下面是一个简单的例子
blueprint.xml
然后,打包成bundle,扔到karaf、servicemix的deploy目录中去
注意上面blueprint.xml 的conf.example
下一步,是在deploy或者etc目录下,新建一个conf.example.cfg文件,里面按照properties标准格式来写
以后,这要这个文件有改动,就会触发ConfigManagedExample的updated方法执行
org.osgi.service.cm.ManagedService 用于操作单个配置文件
org.osgi.service.cm.ManagedServiceFactory 用于操作一组相关的配置文件 用法见 OSGI CM之ManagedServiceFactory的使用
org.osgi.service.cm.ManagedService可以实现,文件改动就会收到通知的效果,下面是一个简单的例子
package com.pp; import java.util.Dictionary; import org.osgi.service.cm.ConfigurationException; import org.osgi.service.cm.ManagedService; public class ConfigManagedExample implements ManagedService { public void updated(Dictionary<String, ?> properties) throws ConfigurationException { System.out.println("--------文件被触发---------"); System.out.println(properties); } }
blueprint.xml
<?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <bean id="configManagedExample" class="com.pp.ConfigManagedExample" /> <service ref="configManagedExample" interface="org.osgi.service.cm.ManagedService"> <service-properties> <entry key="service.pid" value="conf.example" /> </service-properties> </service> </blueprint>
然后,打包成bundle,扔到karaf、servicemix的deploy目录中去
注意上面blueprint.xml 的conf.example
下一步,是在deploy或者etc目录下,新建一个conf.example.cfg文件,里面按照properties标准格式来写
以后,这要这个文件有改动,就会触发ConfigManagedExample的updated方法执行
相关文章推荐
- hdu计算机学院大学生程序设计竞赛(2015’11)1003 玩骰子
- 使用Git命令把本地项目上传到GitHub托管
- 使用 Intel HAXM 为 Android 模拟器加速,媲美真机(转)
- 集合恒等式定律及文氏图
- 如何删除表中的重复记录只保留其中一条?
- php web qq第三方登录
- java抽象类的特点
- LNMP系列(1)centos 6.0 nginx安装
- dpi 、 dip 、分辨率、屏幕尺寸、px、density 关系以及换算
- 配给应用程序的内存太小,将导致内存不足
- cocos2dx3.4开发环境搭建详解(2)
- JDK自带加密算法sha-1
- CSS中图片宽度适应手机屏幕
- iOS核心动画笔记2
- Spring MVC常用的注解
- 【Leetcode】之Longest Valid Parentheses
- IOS入门——使用UIView简单实现霓虹灯(两种方法)
- MySQL5.6 mysqldump 数据库备份的正确操作
- 資料處理 - 常見資料類型轉換類別
- SQL Server 2008 清空删除日志文件 130G日志 10秒内变10M