2

I have implemented 2 services A,B in my bundle. I would like to change the code of service A by building a new jar file and do update command but keep the service B running without start it again.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
DM CHAU
  • 67
  • 6

1 Answers1

4

Sounds like you have 2 services in 1 bundle. The unit of deployment is a bundle, so my recommendation is to split the two services into two bundles. Otherwise, undeploying your existing bundle will naturally also tear down Service B.

Alternatively, in case the API/interface resides in a separate bundle, you could deploy a new service-implementation for A in a separate bundle, with a higher priority, and rewire all uses of the service. Which typically is rather confusing, so it's a distant second place recommendation.

Edit: You comment that you are combining services in a bundle to minimize the number of jars, but you want to update the services independently. Specifically for minimizing the number of jars: Are you trying to solve a problem that you indeed had? I'm mainly working with Liferay, which is fully OSGi, and a plain vanilla installation comes with more than 1000 bundles - the runtime handles it just fine. Make sure you're not preemptively optimizing something that doesn't need optimization.

If your components have different maintenance intervals, then deploy them in different bundles. Period. No use working against the system, which has no problem with the number of bundles at all.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • My main idea is deploying multiple processes/jobs in 1 file jar (bundle) because there are too much processes in my systems. For example, if my system has 70-100 processes/jobs, I will need to deploy 70-100 jars (bundles) and I think this approach is quite difficult to implement and monitor. Therefore, I would like to divide these processes into some "combine" bundles (15 processes in bundle A, 15 processes in bundle B and so on. – DM CHAU Apr 15 '20 at 01:39
  • However, the processes in same bundle could be updated independently. After researching, I decide to use OSGI services as my processes, means that I use OSGI services to start and stop my process and it seems working well. – DM CHAU Apr 15 '20 at 01:40
  • Do you have any idea (OSGI approaches) for my idea? I have created some questions but no one could help. Please follow below links or just directly reply me in this topic – DM CHAU Apr 15 '20 at 01:43
  • https://stackoverflow.com/questions/60724443/how-to-deploy-multiple-processesbundles-in-1-jar-onto-osgi-felix – DM CHAU Apr 15 '20 at 01:43
  • https://stackoverflow.com/questions/60808451/deploy-multiple-instance-in-1-bundle-osgi – DM CHAU Apr 15 '20 at 01:44
  • so you mean that there are no way to update service OSGI independently using Apache Felix? – DM CHAU Apr 20 '20 at 02:35
  • No, quite the opposite: There is a way: Just package everything you want to deploy independently in independent bundles. Don't worry about the number of bundles. – Olaf Kock Apr 20 '20 at 06:33
  • Could you please share with me some examples (maybe the source code in github)?. I also heard about Composite Bundle but I cant find some code in details. – DM CHAU Apr 20 '20 at 07:17
  • You already say _"I have implemented 2 services A,B in my bundle"_: Just implement service A in A.jar, and service B in B.jar - you know how to implement services, all I'm telling you is to package them so that you can redeploy the bundle if you want to redeploy the service. Just accept that bundles are the unit of deployment (with the least resistance) – Olaf Kock Apr 20 '20 at 07:25
  • Are there anyway to building multiple bundles from 1 eclipse project? because each project has only 1 pom.xml which defines only 1 . Or I must create project A to build jar A and project B to build jar B? – DM CHAU Apr 20 '20 at 09:39
  • 1
    That last comment actually is a new question rather than a clarification IMHO. What problem would "multiple bundles from one project" solve anyway? Sounds very much like a [x-y-problem](https://meta.stackexchange.com/a/66378/364505). There's no limit in projects that eclipse can handle, and no limit in the number of bundles that the OSGi runtime can handle. Decide if you want your project independent of each other or bundled together into a single unit, then go with your decision. But decide for one, don't try to fight the system because your initial idea was different. – Olaf Kock Apr 20 '20 at 10:02