首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

服务追踪(ServiceTracker)

2012-11-07 
服务跟踪(ServiceTracker)public?class?Activator?implements?BundleActivator?{??????HelloServiceTracke

服务跟踪(ServiceTracker)

    public?class?Activator?implements?BundleActivator?{??????HelloServiceTracker?helloServiceTracker;??????ServiceRegistration?serviceRegistration;????????????public?void?start(BundleContext?context)?throws?Exception?{??????????System.out.println("start...");????????????????????//启动服务跟踪器??????????helloServiceTracker?=?new?HelloServiceTracker(context);??????????helloServiceTracker.open();????????????????????//注册服务??????????serviceRegistration?=?context.registerService(HelloService.class.getName(),?new?HelloServiceImpl(),?null);????????????????????//获取被跟踪的服务??????????HelloService?helloService?=??(HelloService)helloServiceTracker.getService();??????????if(helloService!=null){??????????????System.out.println(helloService.sayHello("cjm"));??????????}??????}????????public?void?stop(BundleContext?context)?throws?Exception?{??????????System.out.println("stop");????????????????????//关闭服务跟踪器??????????helloServiceTracker.close();??????????????serviceRegistration.unregister();??????}??}??

?

4、运行结果

osgi>
start...
adding service: p1
Hello cjm


osgi> stop 86
stop
removed service: p1

?

热点排行