Use Spring-DM Extender

916 views Asked by At

I need to wait some time before shut down my OSGI context.( Give some time to finish the tasks that are currently running). I came across with shutdown.wait.time property in the extenderProperties bean.

Can anyone please let me know how can I use this OSGi fragments to achieve my goal? I think I can attach a fragment bundle to my existing OSGI bundle.

Thanks in advance. appreciate your help.

1

There are 1 answers

0
Jason Day On BEST ANSWER

You'll need to create a bundle with two files in it: META-INF/MANIFEST.MF and META-INF/spring/extender/extender.xml (the xml file could be named anything with an xml extension, but must be in the META-INF/spring/extender folder). Your MANIFEST.MF file will need to contain the OSGi manifest header Fragment-Host of org.springframework.osgi.extender. If you're using the maven-bundle-plugin, your plugin configuration would look something like this:

...
<plugin>
  <groupId>org.apache.felix</groupId>
  <artifactId>maven-bundle-plugin</artifactId>
  <version>2.3.5</version>
  <extensions>true</extensions>
  <configuration>
    <instructions>
      <Fragment-Host>org.springframework.osgi.extender</Fragment-Host>
    </instructions>
  </configuration>
</plugin>
...

Your extender.xml file will need to define a java.util.Properties bean with a name of extenderProperties. It should contain a property named shutdown.wait.time with a value in milliseconds (eg. 30000 for 30 seconds). The file may look like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:util="http://www.springframework.org/schema/util"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util     http://www.springframework.org/schema/util/spring-util-3.0.xsd">
  <util:properties id="extenderProperties">
    <prop key="shutdown.wait.time">30000</prop>
  </util:properties>
</beans>

Then deploy the bundle into your environment. You may need to restart the Spring OSGi bundles (or your server) depending on the order this fragment bundle is installed in relation to the Spring DM bundles.