0

I have two bundles, one is DB related and another one simple. DB bundle will export osgi service reference. Another one will get the service reference. It is working fine when installing one by one. The service reference is null when starting the Jboss fuse karaf container.

Can i set bundle ordering ? or Can i set delay for completing DB bundle? I need to install bundle after completing DB bundle. Advance Thanks.

2ps
  • 15,099
  • 2
  • 27
  • 47
Sridhar
  • 89
  • 7

1 Answers1

0

The actual code you have to write depends on how your bundles start. Do you use a Java class as BundleActivator? Spring? Blueprint?

Generally speaking, each bundle must specify its dependencies. There are 2 kinds of dependencies:

  • dependeny on some classes in packages exported by other bundles
  • dependency on a service provided by some other bundle

Your bundle should declare packages and services (Java interfaces) it needs. This way you "force" JBoss/Karaf to start bundles in the correct order and avoid null service references.

Have a look at this guide:
https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html-single/Managing_OSGi_Dependencies/index.html

Alessandro Da Rugna
  • 4,571
  • 20
  • 40
  • 64
  • I'm using bundle Activator class and getting the service reference,,,Null pointer exception : Service Reference is null When i start my container. The bundles are not starting by order. How to start bundles by order? – Sridhar Jan 13 '17 at 10:23
  • I tried fabric method and features file install method, but not yet succeeded. – Sridhar Jan 13 '17 at 10:24
  • @Sridhar please read the guide, "Consumer Bundle" section. Basically your consumer bundle needs `Import-Service: org.your.service.Interface` in MANIFEST.MF and then get the service from `ServiceReference serviceReference = bundleContext.getServiceReference(serviceClass.getName());` You may want to use Blueprint or Spring to use XML config files to configure service dependencies – Alessandro Da Rugna Jan 13 '17 at 10:30
  • My MANIFEST.MF file dont have Import-Service tag. But ServiceReference serviceReference = bundleContext.getServiceReference(serviceClass.getName()); code working fine, if i install bundles one by one. – Sridhar Jan 13 '17 at 10:34
  • Add it. I strongly encourage you to try a component model like Blueprint which makes your development easier https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/Deploying_into_the_Container/files/DeploySimple-Blueprint-Importing.html – Alessandro Da Rugna Jan 13 '17 at 11:23