BlueprintListener的使用

来源:互联网 发布:world of tanks mac 编辑:程序博客网 时间:2024/05/10 15:30

OSGI里面有很多种Listener,添加一个Listener一般是调用BundleContext里面的addListener,比如

BundleContext.addBundleListener();BundleContext.addFrameworkListener();BundleContext.addServiceListener();

但是,BlueprintListener有点不一样

下面有个简单的用法

package com.pp;import org.osgi.framework.BundleActivator;import org.osgi.framework.BundleContext;import org.osgi.framework.ServiceRegistration;import org.osgi.service.blueprint.container.BlueprintListener;public class BlueprintListenerExample implements BundleActivator{private ServiceRegistration<BlueprintListener> registration = null;public void start(BundleContext context) throws Exception{BlueprintListener blueprintListener = (event) -> {System.out.println("BlueprintListener " + event.getBundle().getSymbolicName() + ", type=" + event.getType());};registration = context.registerService(BlueprintListener.class, blueprintListener, null); }public void stop(BundleContext context) throws Exception{registration.unregister();}}


然后,在MANIFEST.MF文件里面增加Bundle-Activator:com.pp.BlueprintListenerExample
这样,就添加了一个BlueprintListener
10 0
原创粉丝点击