I guess to have access to any extra configuration during job execution i
have to schedule the job manually and not via the "whiteboard pattern", so
similar to:
@Reference
QuartzScheduler scheduler;
@Context
private BundleContext context;
public void doSchedule()
{
final Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);
Date tomorrow = cal.getTime();
ScheduleOptions scheduleOptions = this.scheduler.AT(tomorrow, 5,
10);
Map<String, Serializable> extraConfig = new HashMap<>();
extraConfig.put("scheduledBy", context.getBundle().getBundleId());
scheduleOptions.config(extraConfig);
try {
this.scheduler.schedule(new SampleJob(), scheduleOptions);
} catch (SchedulerError schedulerError) {
schedulerError.printStackTrace();
}
}
then during job execution i can access this "scheduledBy" property via the
config.
Is this the case?
Thank you,
Vassil
На вт, 13.04.2021 г. в 20:45 ч. Васил Зорев <[email protected]>
написа:
> Hello,
>
> Following the karaf-scheduler-example for a Runnable service (
> https://github.com/apache/karaf/tree/main/examples/karaf-scheduler-example/karaf-scheduler-example-runnable)
> i implemented a similar Job-based service. Please see attached the Job
> itself and its pom.xml. I placed it in a module within the existing
> examples project only for local testing purpose, so please don't mind the
> official groupId/package..
>
> Then the job was executed 5 times as expected, but each time if i tried to
> read from the JobContext the configuration attribute, it is always null
> (org.apache.karaf.scheduler.JobContext#getConfiguration). I tried to figure
> out by looking at the scheduler sources
> (org.apache.karaf.scheduler.core.QuartzScheduler) how the job is scheduled,
> but couldn't find that there is any configuration set there in any case.
> Please tell me if i missed something, if such configuration would be
> available to the job implementor at all in any case, and what to expect
> there ?
>
>
>
> Hope you got my question..
>
> Thank you,
>
> Regards,
>
> Vassil Zorev
>