Component Using OSGi DS not added to Sling Scheduler
I have 2 simple schedulers. They should both result in an message to the logs every 5min. However, The OSGi DS version does not get registered as a Scheduled Task. Is there something in addition to what is below that is needed to make this work?
Using Felix SCR
/**
* This service runs every 5 mins
*/
@Component(metatype = true, label = "A scheduled task",
description = "Simple demo for cron-job like task with properties")
@Service(value = Runnable.class)
@Properties({
@Property(name = "scheduler.expression", value = "0 0/5 * * * ?",
description = "Cron-job expression"),
})
public class SampleScheduler implements Runnable {
protected static final Logger log = LoggerFactory.getLogger(SampleScheduler.class);
public static final String CONFIG_PID = "org.aem.coe.coetraining.core.schedulers.SampleScheduler";
public static final String NAME = "Sample Scheduler";
@Override
public void run() {
log.info("-----------> Scheduler Running: {}", this.getClass());
}
}
Using OSGi DS
/**
* This service runs every 5 mins
*/
@Component(
immediate = true,
configurationPid = SampleScheduler.CONFIG_PID,
service = Runnable.class
)
@Designate(ocd = SampleScheduler.Configuration.class)
public class SampleScheduler implements Runnable {
protected static final Logger log = LoggerFactory.getLogger(SampleScheduler.class);
public static final String CONFIG_PID = "com.aemcoe.coe63.schedulers.SampleScheduler";
public static final String NAME = "Sample Scheduler";
@Override
public void run() {
log.info("-----------> Scheduler Running: {}", this.getClass());
}
@ObjectClassDefinition(name=SampleScheduler.NAME)
public @interface Configuration {
@AttributeDefinition(
name = "scheduler.expression",
description = "Provide the cron expression for the scheduler",
type = AttributeType.STRING
)
String scheduler_expression() default "0 0/5 * * * ?";
}
}
I have both installed but when I look at http://localhost:4502/system/console/status-slingscheduler I do not see the one with the OSGi DS Annotation. I do see the other:
Job : org.aem.coe.coetraining.core.schedulers.SampleScheduler.15615, class: org.aem.coe.coetraining.core.schedulers.SampleScheduler, concurrent: true, bundleId: 550, serviceId: 15615
Trigger : Trigger 'DEFAULT.org.aem.coe.coetraining.core.schedulers.SampleScheduler.15615': triggerClass: 'org.quartz.impl.triggers.CronTriggerImpl calendar: 'null' misfireInstruction: 0 nextFireTime: Mon Sep 10 16:25:00 CDT 2018
Additionally, I do see the OSGi DS Component get registered, but it doesn't get a Service PID or show the meta properties. 
Now, I know I could probably fix this by creating a configuration file or setting the configurations via the System Console... but is there not a way to just utilize the annotations and default values to add this to the scheduler?