Results 1 to 3 of 3

Thread: OSGI Service + init-method + exception

  1. #1
    Join Date
    May 2011
    Posts
    1

    Default OSGI Service + init-method + exception

    I have a question on better way to avoid a bundle to start when starting services throw an exception.

    I have a bean and a service declare as :
    Code:
    	<bean id="vaultService" class="com.sample.confiance.vault.impl.VaultServiceImpl">
    		<property name="halService" ref="halService"/>
    	</bean>
          
            <osgi:service id="VaultOsgiService" ref="vaultService"
                 interface="com.sample.confiance.vault.VaultService"
                 init-method="start"/>
    When in OSGI a BundleActivator.start() method throw an exception, the bundle refuse to start and come back to resolved state.
    If my vaultService.start method throw an exception, bundle start anyway, ans my service is in an inconsistant state. Is there a way, my bundle don't start if start method throw an exception ?

    Thanks for your reply

  2. #2
    Join Date
    Jul 2008
    Posts
    3

    Default

    Hi,

    the Spring DM/Blueprint extender cannot prevent a bundle from starting by throwing an exception in the BundleListener's bundleChanged method. That means, you might want to look for another way to guarantee a consistent state of your services whatsoever.

    Greetings,
    André

  3. #3
    Join Date
    Sep 2006
    Location
    Russia
    Posts
    28

    Default

    Yes, you could attach OsgiBundleApplicationContextListener in you bundle activator, which gets an event about your context state.

    Or you could implement BundleContextAware interface in your bean and when you got an exception, just stop your bundle.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •