Refresh Package Bundles












2














I've stumbled upon a problem, that can be summarized as follows:



I have an application which is embedded with OSGI. In this OSGI container, I have installed a bundle A of version v1 which registers that service object. This service object is used by the host application. while the service object is in use, I uninstalled the bundle A and installed a new version(v2) of the bundle A. Here are my findings.




  • Old service object works fine even if we uninstall the bundle A(v1).

  • The new service object gives the new functionality of bundle A(v2).


My question here is when we refresh the bundle packages by using



List<Bundle> refreshbundles = new ArrayList<Bundle>();
Bundle local; // points to the bundle
refreshbundles.add(local);
m_felix.adapt(FrameworkWiring.class).refreshBundles(refreshbundles)


and when we try to get the service object registered by the new version of the bundle A, it is returning null. I tried looking at the source code but it didn't help. can you please help me with this?



EDIT:



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.


what exactly is happening when we refresh the bundles?



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();
}
}









share|improve this question
























  • Which bundle exports the service interface? Is it the same bundle registers the service? From which bundle are you looking for the service? Which bundle did you refresh in the code above? How are you looking for the service (code please)?
    – Neil Bartlett
    Nov 23 at 14:55










  • As it is embedded OSGI I'm looking for service from host application in which OSGI is started. I hope the above code will answer the others questions. thank you. If you have any other questions please comment.
    – Anilkumar Vemula
    Nov 25 at 6:18










  • Is the package containing SampleInterface exported by the system bundle and imported by bundleA? Also, what is the state of bundleA after you call refresh?
    – Neil Bartlett
    Nov 26 at 9:40










  • Thank you neil. SampleInterface is added as SYSTEM_PACKAGE in Host Application and it is imported by Bundle A. State of bundle A is Active. So, I started the bundle again which solved my issue. Refreshing bundles is changing the state of the bundle from Active to Resolve by calling bundle.stop().
    – Anilkumar Vemula
    Nov 27 at 6:29






  • 1




    Aha, so the bundle was not publishing the service because it was not ACTIVE. Good job finding the issue. However there are some problems with the code you posted. One is that you call getService several times but never call ungetService, so the service cannot be released by OSGi.
    – Neil Bartlett
    Nov 27 at 10:03
















2














I've stumbled upon a problem, that can be summarized as follows:



I have an application which is embedded with OSGI. In this OSGI container, I have installed a bundle A of version v1 which registers that service object. This service object is used by the host application. while the service object is in use, I uninstalled the bundle A and installed a new version(v2) of the bundle A. Here are my findings.




  • Old service object works fine even if we uninstall the bundle A(v1).

  • The new service object gives the new functionality of bundle A(v2).


My question here is when we refresh the bundle packages by using



List<Bundle> refreshbundles = new ArrayList<Bundle>();
Bundle local; // points to the bundle
refreshbundles.add(local);
m_felix.adapt(FrameworkWiring.class).refreshBundles(refreshbundles)


and when we try to get the service object registered by the new version of the bundle A, it is returning null. I tried looking at the source code but it didn't help. can you please help me with this?



EDIT:



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.


what exactly is happening when we refresh the bundles?



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();
}
}









share|improve this question
























  • Which bundle exports the service interface? Is it the same bundle registers the service? From which bundle are you looking for the service? Which bundle did you refresh in the code above? How are you looking for the service (code please)?
    – Neil Bartlett
    Nov 23 at 14:55










  • As it is embedded OSGI I'm looking for service from host application in which OSGI is started. I hope the above code will answer the others questions. thank you. If you have any other questions please comment.
    – Anilkumar Vemula
    Nov 25 at 6:18










  • Is the package containing SampleInterface exported by the system bundle and imported by bundleA? Also, what is the state of bundleA after you call refresh?
    – Neil Bartlett
    Nov 26 at 9:40










  • Thank you neil. SampleInterface is added as SYSTEM_PACKAGE in Host Application and it is imported by Bundle A. State of bundle A is Active. So, I started the bundle again which solved my issue. Refreshing bundles is changing the state of the bundle from Active to Resolve by calling bundle.stop().
    – Anilkumar Vemula
    Nov 27 at 6:29






  • 1




    Aha, so the bundle was not publishing the service because it was not ACTIVE. Good job finding the issue. However there are some problems with the code you posted. One is that you call getService several times but never call ungetService, so the service cannot be released by OSGi.
    – Neil Bartlett
    Nov 27 at 10:03














2












2








2


0





I've stumbled upon a problem, that can be summarized as follows:



I have an application which is embedded with OSGI. In this OSGI container, I have installed a bundle A of version v1 which registers that service object. This service object is used by the host application. while the service object is in use, I uninstalled the bundle A and installed a new version(v2) of the bundle A. Here are my findings.




  • Old service object works fine even if we uninstall the bundle A(v1).

  • The new service object gives the new functionality of bundle A(v2).


My question here is when we refresh the bundle packages by using



List<Bundle> refreshbundles = new ArrayList<Bundle>();
Bundle local; // points to the bundle
refreshbundles.add(local);
m_felix.adapt(FrameworkWiring.class).refreshBundles(refreshbundles)


and when we try to get the service object registered by the new version of the bundle A, it is returning null. I tried looking at the source code but it didn't help. can you please help me with this?



EDIT:



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.


what exactly is happening when we refresh the bundles?



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();
}
}









share|improve this question















I've stumbled upon a problem, that can be summarized as follows:



I have an application which is embedded with OSGI. In this OSGI container, I have installed a bundle A of version v1 which registers that service object. This service object is used by the host application. while the service object is in use, I uninstalled the bundle A and installed a new version(v2) of the bundle A. Here are my findings.




  • Old service object works fine even if we uninstall the bundle A(v1).

  • The new service object gives the new functionality of bundle A(v2).


My question here is when we refresh the bundle packages by using



List<Bundle> refreshbundles = new ArrayList<Bundle>();
Bundle local; // points to the bundle
refreshbundles.add(local);
m_felix.adapt(FrameworkWiring.class).refreshBundles(refreshbundles)


and when we try to get the service object registered by the new version of the bundle A, it is returning null. I tried looking at the source code but it didn't help. can you please help me with this?



EDIT:



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.


what exactly is happening when we refresh the bundles?



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();
}
}






osgi apache-felix embedded-osgi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 at 6:14

























asked Nov 22 at 18:44









Anilkumar Vemula

112




112












  • Which bundle exports the service interface? Is it the same bundle registers the service? From which bundle are you looking for the service? Which bundle did you refresh in the code above? How are you looking for the service (code please)?
    – Neil Bartlett
    Nov 23 at 14:55










  • As it is embedded OSGI I'm looking for service from host application in which OSGI is started. I hope the above code will answer the others questions. thank you. If you have any other questions please comment.
    – Anilkumar Vemula
    Nov 25 at 6:18










  • Is the package containing SampleInterface exported by the system bundle and imported by bundleA? Also, what is the state of bundleA after you call refresh?
    – Neil Bartlett
    Nov 26 at 9:40










  • Thank you neil. SampleInterface is added as SYSTEM_PACKAGE in Host Application and it is imported by Bundle A. State of bundle A is Active. So, I started the bundle again which solved my issue. Refreshing bundles is changing the state of the bundle from Active to Resolve by calling bundle.stop().
    – Anilkumar Vemula
    Nov 27 at 6:29






  • 1




    Aha, so the bundle was not publishing the service because it was not ACTIVE. Good job finding the issue. However there are some problems with the code you posted. One is that you call getService several times but never call ungetService, so the service cannot be released by OSGi.
    – Neil Bartlett
    Nov 27 at 10:03


















  • Which bundle exports the service interface? Is it the same bundle registers the service? From which bundle are you looking for the service? Which bundle did you refresh in the code above? How are you looking for the service (code please)?
    – Neil Bartlett
    Nov 23 at 14:55










  • As it is embedded OSGI I'm looking for service from host application in which OSGI is started. I hope the above code will answer the others questions. thank you. If you have any other questions please comment.
    – Anilkumar Vemula
    Nov 25 at 6:18










  • Is the package containing SampleInterface exported by the system bundle and imported by bundleA? Also, what is the state of bundleA after you call refresh?
    – Neil Bartlett
    Nov 26 at 9:40










  • Thank you neil. SampleInterface is added as SYSTEM_PACKAGE in Host Application and it is imported by Bundle A. State of bundle A is Active. So, I started the bundle again which solved my issue. Refreshing bundles is changing the state of the bundle from Active to Resolve by calling bundle.stop().
    – Anilkumar Vemula
    Nov 27 at 6:29






  • 1




    Aha, so the bundle was not publishing the service because it was not ACTIVE. Good job finding the issue. However there are some problems with the code you posted. One is that you call getService several times but never call ungetService, so the service cannot be released by OSGi.
    – Neil Bartlett
    Nov 27 at 10:03
















Which bundle exports the service interface? Is it the same bundle registers the service? From which bundle are you looking for the service? Which bundle did you refresh in the code above? How are you looking for the service (code please)?
– Neil Bartlett
Nov 23 at 14:55




Which bundle exports the service interface? Is it the same bundle registers the service? From which bundle are you looking for the service? Which bundle did you refresh in the code above? How are you looking for the service (code please)?
– Neil Bartlett
Nov 23 at 14:55












As it is embedded OSGI I'm looking for service from host application in which OSGI is started. I hope the above code will answer the others questions. thank you. If you have any other questions please comment.
– Anilkumar Vemula
Nov 25 at 6:18




As it is embedded OSGI I'm looking for service from host application in which OSGI is started. I hope the above code will answer the others questions. thank you. If you have any other questions please comment.
– Anilkumar Vemula
Nov 25 at 6:18












Is the package containing SampleInterface exported by the system bundle and imported by bundleA? Also, what is the state of bundleA after you call refresh?
– Neil Bartlett
Nov 26 at 9:40




Is the package containing SampleInterface exported by the system bundle and imported by bundleA? Also, what is the state of bundleA after you call refresh?
– Neil Bartlett
Nov 26 at 9:40












Thank you neil. SampleInterface is added as SYSTEM_PACKAGE in Host Application and it is imported by Bundle A. State of bundle A is Active. So, I started the bundle again which solved my issue. Refreshing bundles is changing the state of the bundle from Active to Resolve by calling bundle.stop().
– Anilkumar Vemula
Nov 27 at 6:29




Thank you neil. SampleInterface is added as SYSTEM_PACKAGE in Host Application and it is imported by Bundle A. State of bundle A is Active. So, I started the bundle again which solved my issue. Refreshing bundles is changing the state of the bundle from Active to Resolve by calling bundle.stop().
– Anilkumar Vemula
Nov 27 at 6:29




1




1




Aha, so the bundle was not publishing the service because it was not ACTIVE. Good job finding the issue. However there are some problems with the code you posted. One is that you call getService several times but never call ungetService, so the service cannot be released by OSGi.
– Neil Bartlett
Nov 27 at 10:03




Aha, so the bundle was not publishing the service because it was not ACTIVE. Good job finding the issue. However there are some problems with the code you posted. One is that you call getService several times but never call ungetService, so the service cannot be released by OSGi.
– Neil Bartlett
Nov 27 at 10:03

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436650%2frefresh-package-bundles%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436650%2frefresh-package-bundles%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Trompette piccolo

How do I get these specific pathlines to nodes?

What visual should I use to simply compare current year value vs last year in Power BI desktop