private Job addJobInternal()

in src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java [577:617]


    private Job addJobInternal(final String jobTopic,
            final Map<String, Object> jobProperties,
            final List<String> errors) {
        final QueueInfo info = this.configuration.getQueueConfigurationManager().getQueueInfo(jobTopic);

        final TopologyCapabilities caps = this.configuration.getTopologyCapabilities();
        info.targetId = (caps == null ? null : caps.detectTarget(jobTopic, jobProperties, info));

        if (info.targetId == null && logger.isInfoEnabled()) {
            logger.info("Persisting job {} into queue {} with no assigned target",
                    Utility.toString(jobTopic, jobProperties), info.queueName);
        } else if (info.targetId != null && logger.isDebugEnabled()) {
            logger.debug("Persisting job {} into queue {}, target={}",
                    Utility.toString(jobTopic, jobProperties), info.queueName, info.targetId);
        }
        final ResourceResolver resolver = this.configuration.createResourceResolver();
        try {
            final JobImpl job = this.writeJob(resolver,
                    jobTopic,
                    jobProperties,
                    info);
            if ( info.targetId != null ) {
                this.configuration.getAuditLogger().debug("ASSIGN OK {} : {}",
                        info.targetId, job.getId());
            } else {
                this.configuration.getAuditLogger().debug("UNASSIGN OK : {}",
                        job.getId());
            }
            return job;
        } catch (final PersistenceException re ) {
            // something went wrong, so let's log it
            this.logger.error("Exception during persisting new job '" + Utility.toString(jobTopic, jobProperties) + "'", re);
        } finally {
            resolver.close();
        }
        if ( errors != null ) {
            errors.add("Unable to persist new job.");
        }

        return null;
    }