本文整理汇总了Java中org.osgi.framework.SynchronousBundleListener类的典型用法代码示例。如果您正苦于以下问题:Java SynchronousBundleListener类的具体用法?Java SynchronousBundleListener怎么用?Java SynchronousBundleListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SynchronousBundleListener类属于org.osgi.framework包,在下文中一共展示了SynchronousBundleListener类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
@Override
public void start(BundleContext bundleContext) throws Exception {
final String configAdminInit = bundleContext.getBundle().getHeaders().get("X-Aries-Blueprint-ConfigAdmin-Init");
if (configAdminInit != null) {
final BundleContext sysContext = bundleContext.getBundle(0).getBundleContext();
// we are started before blueprint.core and felix.configadmin
// we are sure that felix.configadmin is started before blueprint.core
sysContext.addBundleListener(new SynchronousBundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
if (event.getType() == BundleEvent.STARTED
&& "org.apache.felix.configadmin".equals(event.getBundle().getSymbolicName())) {
// configadmin should have already been started
ServiceReference<?> sr = sysContext.getServiceReference("org.osgi.service.cm.ConfigurationAdmin");
if (sr != null && sysContext.getService(sr) != null) {
initializeConfigAdmin(sysContext, configAdminInit);
}
}
}
});
}
}
示例2: start
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
@Override
public void start(BundleContext bundleContext) throws Exception {
final String configAdminInit = bundleContext.getBundle().getHeaders().get("X-Camel-Blueprint-ConfigAdmin-Init");
if (configAdminInit != null) {
final BundleContext sysContext = bundleContext.getBundle(0).getBundleContext();
// we are started before blueprint.core and felix.configadmin
// we are sure that felix.configadmin is started before blueprint.core
sysContext.addBundleListener(new SynchronousBundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
if (event.getType() == BundleEvent.STARTED
&& "org.apache.felix.configadmin".equals(event.getBundle().getSymbolicName())) {
// configadmin should have already been started
ServiceReference<?> sr = sysContext.getServiceReference("org.osgi.service.cm.ConfigurationAdmin");
if (sr != null && sysContext.getService(sr) != null) {
initializeConfigAdmin(sysContext, configAdminInit);
}
}
}
});
}
}
示例3: init
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
@Override
public void init(ConfigurationProvider configurationProvider) {
LOG.debug("Initializing observer configuration");
tracker = new ServiceTracker<SessionFactoryObserver, SessionFactoryObserver>(bundleContext, SessionFactoryObserver.class,
null);
tracker.open();
bundleContext.addBundleListener(new SynchronousBundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
if (event.getBundle().equals(bundleContext.getBundle()) && event.getType() == BundleEvent.STOPPING) {
tracker.close();
tracker = null;
}
}
});
configurationProvider.getConfiguration().setSessionFactoryObserver(this);
configurationProvider.invalidate();
}
示例4: ListenerBundleEvent
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
/**
* 监听插件安装事件,当有新插件安装或卸载时成功也更新一下
*/
public void ListenerBundleEvent(){
BundleContextFactory.getInstance().getBundleContext()
.addBundleListener(
new SynchronousBundleListener(){
public void bundleChanged(BundleEvent event) {
//把插件列表清空
bundles.clear();
BundleContext context =BundleContextFactory.getInstance().getBundleContext();
for(int i=0;i<context.getBundles().length;i++)
{
bundles.add(context.getBundles()[i]);
}
adapter.notifyDataSetChanged();
}
});
}
示例5: testCallGetResourceOnADifferentBundleRetrievedThroughBundleEvent
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
public void testCallGetResourceOnADifferentBundleRetrievedThroughBundleEvent() throws Exception {
String EXTRA_BUNDLE = "org.apache.servicemix.bundles.spring-core";
Bundle[] bundles = bundleContext.getBundles();
Bundle bundle = null;
for (int i = 1; bundle == null && i < bundles.length; i++) {
String location = bundles[i].getLocation();
if (location != null && location.contains(EXTRA_BUNDLE))
bundle = bundles[i];
}
assertNotNull("no bundle found", bundle);
final Bundle sampleBundle = bundle;
final boolean[] listenerCalled = new boolean[] { false };
// register listener
bundleContext.addBundleListener(new SynchronousBundleListener() {
public void bundleChanged(BundleEvent event) {
// call getResource
event.getBundle().getResource(LOCATION);
// call getResources
try {
event.getBundle().getResources(LOCATION);
} catch (IOException e) {
throw new RuntimeException(e);
}
listenerCalled[0] = true;
}
});
// update
sampleBundle.stop();
assertTrue("bundle listener hasn't been called", listenerCalled[0]);
}
示例6: UIServiceTrackers
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
/**
* Constructs the registry and registers a bundle listener that will remove trackers for bundles that are stopping.
* @param bundleContext the bundle context used to register the bundle listener
*/
public UIServiceTrackers(BundleContext bundleContext) {
bundleContext.addBundleListener(new SynchronousBundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
if (event.getType() == BundleEvent.STOPPING) {
removeTrackerFor(event.getBundle());
}
}
});
}
示例7: HttpServiceTrackers
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
/**
* Creates this http tracker registry and registers a bundle listener,
* that will close the trackers for a bundle once it is stopped.
*
* @param bundleContext the context used for registering the bundle listener
*/
public HttpServiceTrackers(BundleContext bundleContext) {
bundleContext.addBundleListener(new SynchronousBundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
if (event.getType() == BundleEvent.STOPPING) {
removeTrackerFor(event.getBundle());
}
}
});
}
示例8: addBundleListener
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
public void addBundleListener(BundleListener bundleListener) {
checkValid();
List list = bundleListener instanceof SynchronousBundleListener ? Framework.syncBundleListeners : Framework.bundleListeners;
if (this.bundle.registeredBundleListeners == null) {
this.bundle.registeredBundleListeners = new ArrayList();
}
if (!this.bundle.registeredBundleListeners.contains(bundleListener)) {
list.add(bundleListener);
this.bundle.registeredBundleListeners.add(bundleListener);
}
}
示例9: removeBundleListener
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
public void removeBundleListener(BundleListener bundleListener) {
checkValid();
(bundleListener instanceof SynchronousBundleListener ? Framework.syncBundleListeners : Framework.bundleListeners).remove(bundleListener);
this.bundle.registeredBundleListeners.remove(bundleListener);
if (this.bundle.registeredBundleListeners.isEmpty()) {
this.bundle.registeredBundleListeners = null;
}
}
示例10: init
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
@Override
public void init(final ConfigurationProvider configurationProvider) {
LOG.debug("Initializing filter configuration");
tracker = new ServiceTracker<FilterProvider, FilterProvider>(bundleContext, FilterProvider.class, null) {
@Override
public FilterProvider addingService(ServiceReference<FilterProvider> reference) {
LOG.debug("Filter provider added as a service");
FilterProvider provider = super.addingService(reference);
addFilterDefinitions(provider, configurationProvider);
return provider;
}
@Override
public void removedService(ServiceReference<FilterProvider> reference, FilterProvider service) {
LOG.debug("Filter provider removed");
removeFilterDefinitions(service, configurationProvider);
super.removedService(reference, service);
}
};
tracker.open();
bundleContext.addBundleListener(new SynchronousBundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
if (event.getBundle().equals(bundleContext.getBundle()) && event.getType() == BundleEvent.STOPPING) {
tracker.close();
tracker = null;
}
}
});
}
示例11: testCallGetResourceOnADifferentBundleRetrievedThroughBundleEvent
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
public void testCallGetResourceOnADifferentBundleRetrievedThroughBundleEvent() throws Exception {
String EXTRA_BUNDLE = "org.springframework.core";
Bundle[] bundles = bundleContext.getBundles();
Bundle bundle = null;
// find cglib library as we don't use it
for (int i = 1; bundle == null && i < bundles.length; i++) {
String location = bundles[i].getLocation();
if (location != null && location.indexOf(EXTRA_BUNDLE) > -1)
bundle = bundles[i];
}
assertNotNull("no bundle found", bundle);
final Bundle sampleBundle = bundle;
final boolean[] listenerCalled = new boolean[] { false };
// register listener
bundleContext.addBundleListener(new SynchronousBundleListener() {
public void bundleChanged(BundleEvent event) {
// call getResource
event.getBundle().getResource(LOCATION);
// call getResources
try {
event.getBundle().getResources(LOCATION);
}
catch (IOException e) {
throw new RuntimeException(e);
}
listenerCalled[0] = true;
}
});
// update
sampleBundle.stop();
assertTrue("bundle listener hasn't been called", listenerCalled[0]);
}
示例12: adaptBundleListener
import org.osgi.framework.SynchronousBundleListener; //导入依赖的package包/类
private ModuleListener adaptBundleListener(BundleListener listener) {
if (listener instanceof SynchronousBundleListener) {
return new SynchronousBundleListenerAdaptor(listener);
} else {
return new BundleListenerAdaptor(listener);
}
}