OSGI dynamic scheduler + configurationFactory
Hi Experts,
I am running into the issue where I am trying to add dynamic jobs to the scheduler.
Here is my setting/scenario:
1. FactoryConfigService.java -
@Component(configurationFactory = true, policy = ConfigurationPolicy.REQUIRE, immediate = true, label = "Factory Config Service", description = "Factory configuration Service", metatype = true)@Properties({
@Property(name = Constants.SERVICE_DESCRIPTION, value = "Factory Configuration Service"),
@Property(name = Constants.SERVICE_VENDOR, value = "FactoryConfig") })
@Service(value = FactoryConfigService.class)
- It contains a property
@Property(label = "cronJob", value = "cronJob", description = "cronJob")
public static final String SITE_NAME = "cronJob";
- I created 3 instances of "Factory Config Service" from OSGI console and set cronJob to be 0 0 1 * * ?, 0 0 2 * * ? and 0 0 3 * * ?
2. Scheduler.java
@Component(immediate = true, metatype = true, label = Scheduler")
@Properties({
@Property(name = Constants.SERVICE_DESCRIPTION, value = "Scheduler"),
@Property(name = Constants.SERVICE_VENDOR, value = "Universal") })
@Service(value = Scheduler.class)
@Reference(policy = ReferencePolicy.STATIC)
private FactoryConfigService configService; // Reference to the Factory config
@Reference(policy = ReferencePolicy.STATIC)
private ConfigurationAdmin configAdmin;
protected void activate(ComponentContext componentContext) throws Exception {
LOGGER.info("Scheduler in activation: " + this.scheduler);
//pseudocode
// Add jobs
}
GOAL: I would like to execute activate method of Scheduler every time I add new instance config or modify existing instance.
PROBLEM: activate method gets invoked when bundle is restarted, refreshed and deployed, BUT does not get called again when I add new instance or modify new instance ( change cronJob schedule)
Any pointers or sample framework code would be greatly appreciated.
