Обновить комплекты пакетов
Я наткнулся на проблему, которая может быть кратко изложена следующим образом:
У меня есть приложение, которое встроено в OSGI. В этом контейнере OSGI я установил пакет A версии v1, который регистрирует этот сервисный объект. Этот сервисный объект используется хост-приложением. пока объект службы используется, я удалил пакет A и установил новую версию (v2) пакета A. Вот мои выводы.
- Старый сервисный объект работает нормально, даже если мы удалим пакет A(v1).
- Новый сервисный объект дает новую функциональность пакета A(v2).
Мой вопрос здесь, когда мы обновляем пакеты пакетов, используя
List<Bundle> refreshbundles = new ArrayList<Bundle>();
Bundle local; // points to the bundle
refreshbundles.add(local);
m_felix.adapt(FrameworkWiring.class).refreshBundles(refreshbundles)
и когда мы пытаемся зарегистрировать объект службы в новой версии пакета A, он возвращает ноль. Я попытался посмотреть на исходный код, но это не помогло. не могли бы вы помочь мне с этим?
РЕДАКТИРОВАТЬ:
HostApplication
public Felix m_felix = null;
m_felix = new Felix(config); //sending some config to felix.
m_felix.start();
//installing bundle
Bundle bundle = m_felix.getBundleContext().installBundle("file:/bundleA-1.0.jar")
bundle.start()
//getting the service object registered by bundle A.
ServiceReference sr = m_felix.getBundleContext()
.getServiceReference(SampleInterface.class.getName()))
(SampleInterface) m_felix.getBundleContext(sr).getService().sayHI();
//now uninstalling the bundle installing the new version of it say version 1.1
bundle.uninstall()
bundle = m_felix.getBundleContext().installBundle("file:/bundleA-1.1.jar")
bundle.start()
//getting the service object registered by bundleA1.1
ServiceReference sr = m_felix.getBundleContext()
.getServiceReference(SampleInterface.class.getName()))
(SampleInterface) m_felix.getBundleContext(sr).getService().sayHI();
//the above line is working fine but after refreshing the packages, Service object is returned as null
List<Bundle> refreshbundles = new ArrayList<Bundle>();
Bundle bundle; // points to the bundle
refreshbundles.add(bundle);
m_felix.adapt(FrameworkWiring.class).refreshBundles(refreshbundles)
//refresh done
ServiceReference sr = m_felix.getBundleContext()
.getServiceReference(SampleInterface.class.getName()))
(SampleInterface) m_felix.getBundleContext(sr).getService().sayHI();
//throwing null pointer exception because getService() is returning null.
что именно происходит, когда мы обновляем пакеты?
BundleA_Activator.java
public class BundleA_Activator extends BundleActivator{
public class BundleActivatorInterfaces implements BundleActivator{
ServiceRegistration SR;
@Override
public void start(BundleContext bundleContext) {
SR = bundleContext.registerService(SampleInterface.class.getName(), new ExposedClass(), null);
}
@Override
public void stop(BundleContext bundleContext) {
SR.unregister();
}
}