private void scheduleJob()

in src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java [566:617]


    private void scheduleJob(final Long bundleId, final Long serviceId, final Object job, final ScheduleOptions options)
    throws SchedulerException {
        this.checkJob(job);

        if ( !(options instanceof InternalScheduleOptions)) {
            throw new IllegalArgumentException("Options has not been created via schedule or is null.");
        }
        final InternalScheduleOptions opts = (InternalScheduleOptions)options;

        if ( opts.argumentException != null ) {
            throw opts.argumentException;
        }

        synchronized ( this.schedulers ) {
            // as this method might be called from unbind and during
            // unbind a deactivate could happen, we check the scheduler first
            final String poolName = getThreadPoolName(opts.threadPoolName);
            SchedulerProxy proxy = null;
            synchronized ( this.schedulers ) {
                if ( this.active ) {
                    proxy = this.schedulers.get(poolName);
                    if ( proxy == null ) {
                        proxy = new SchedulerProxy(this.threadPoolManager, poolName);
                        this.schedulers.put(poolName, proxy);
                    }
                }
            }
            if ( proxy == null ) {
                throw new IllegalStateException("Scheduler is not available anymore.");
            }


            final String name;
            if ( opts.name != null ) {
                // if there is already a job with the name, remove it first
                this.unschedule(bundleId, opts.name);
                name = opts.name;
            } else {
                name = job.getClass().getName() + ':' + UUID.randomUUID();
            }

            final Trigger trigger = opts.trigger.withIdentity(name).build();

            // create the data map
            final JobDataMap jobDataMap = this.initDataMap(bundleId, serviceId, name, job, opts);

            final JobDetail detail = this.createJobDetail(name, jobDataMap, opts.canRunConcurrently);

            this.logger.debug("Scheduling job {} with name {} and trigger {}", new Object[] {job, name, trigger});
            proxy.getScheduler().scheduleJob(detail, trigger);
        }
    }