On Wed, Jan 18, 2012 at 4:10 PM, Alessandro Adamou <[email protected]> wrote: > Hi, > > I have an OSGi bundle with a service Component, and in the @Activate method > of that component I am getting some files using the DataFileProvider. > > Problem is, one file is a resource of the same bundle, which has its > Data-Files instruction. Quite often, when the component activates upon > install, the resource is not found yet and activation fails. It works after > stopping and restarting the component. > > I guess it's because the provider for that bundle has not been created yet > when @Activate is called on the component. >
I think this might be correct. The DataBundleInstaller creates the BundleDataFileProvider on the BundleEvent.STARTED event. Based on the documentation this is called after the activate method of the Bundle completes. Assuming that the components are started within the activate method there is a good change that they are activated before the BundleDataFileProvider of the Bundle is registered with the MainDataFileProvider. > Is there a solution to this? I want to use the DataFileProvider for all > files, as I cannot always assume to know if a certain file is provided by my > bundle (suppose there is one with the same name and a higher priority > elsewhere). > Do you need to read that file in the activate method? Maybe you can do the initialization on the first call to your method. You could also check if changing the Event the DataBundleInstaller uses to BundleEvent.STARTING. However the Javadoc says that such event are only delivered to SynchronousBundleListeners so this might require more changes. best Rupert -- | Rupert Westenthaler [email protected] | Bodenlehenstraße 11 ++43-699-11108907 | A-5500 Bischofshofen
