Package org.apache.sling.event.impl.jobs

Examples of org.apache.sling.event.impl.jobs.JobHandler


                    Thread.currentThread().interrupt();
                }
            }
            final Iterator<JobHandler> jobIter = restartJobs.iterator();
            while ( jobIter.hasNext() ) {
                final JobHandler handler = jobIter.next();
                boolean process = false;
                synchronized ( this.startedJobsLists ) {
                    process = this.startedJobsLists.remove(handler.getJob().getId()) != null;
                }
                if ( process ) {
                    if ( handler.reschedule() ) {
                        this.logger.info("No acknowledge received for job {} stored at {}. Requeueing job.", Utility.toString(handler.getJob()), handler.getJob().getId());
                        handler.getJob().retry();
                        this.requeue(handler);
                        this.notifyFinished(true);
                    }
                }
            }
View Full Code Here


    /**
     * Execute the queue
     */
    private void runJobQueue() {
        while ( this.running && !this.isOutdated()) {
            JobHandler info = null;
            if ( info == null ) {
                // so let's wait/get the next job from the queue
                info = this.take();
            }

View Full Code Here

        }

        if ( logger.isDebugEnabled() ) {
            logger.debug("Returning job for {} : {}", queueName, Utility.toString(result));
        }
        return (result != null ? new JobHandler( result, this.services.configuration) : null);
    }
View Full Code Here

        synchronized ( this.startedJobsLists ) {
            this.startedJobsLists.remove(jobId);
        }

        // get job handler
        final JobHandler handler;
        // let's remove the event from our processing list
        synchronized ( this.processingJobsLists ) {
            handler = this.processingJobsLists.remove(jobId);
        }

        if ( !this.running ) {
            this.logger.warn("Queue is not running anymore. Discarding finish for {}", jobId);
            return false;
        }

        if ( handler == null ) {
            if ( this.logger.isDebugEnabled() ) {
                this.logger.debug("This job has never been started by this queue: {}", jobId);
            }
            return false;
        }

        // handle the reschedule, a new job might be returned with updated reschedule info!
        final RescheduleInfo rescheduleInfo = this.handleReschedule(handler, resultState);
        if ( resultState == Job.JobState.QUEUED && !rescheduleInfo.reschedule ) {
            resultState = Job.JobState.GIVEN_UP;
        }

        if ( !rescheduleInfo.reschedule ) {
            // we keep cancelled jobs and succeeded jobs if the queue is configured like this.
            final boolean keepJobs = resultState != Job.JobState.SUCCEEDED || this.configuration.isKeepJobs();
            handler.finished(resultState, keepJobs, rescheduleInfo.processingTime);
        } else {
            this.reschedule(handler);
        }
        this.notifyFinished(rescheduleInfo.reschedule);
View Full Code Here

     * @see org.apache.sling.event.impl.jobs.deprecated.JobStatusNotifier#sendAcknowledge(org.osgi.service.event.Event)
     */
    @Override
    public boolean sendAcknowledge(final Event job) {
        final String jobId = (String)job.getProperty(ResourceHelper.PROPERTY_JOB_ID);
        final JobHandler ack;
        synchronized ( this.startedJobsLists ) {
            ack = this.startedJobsLists.remove(jobId);
        }
        // if the event is still in the started jobs list, we confirm the ack
        if ( ack != null ) {
            if ( logger.isDebugEnabled() ) {
                logger.debug("Received ack for job {}", Utility.toString(ack.getJob()));
            }
            final long queueTime = ack.started - ack.queued;
            NotificationUtility.sendNotification(this.services.eventAdmin, NotificationConstants.TOPIC_JOB_STARTED, ack.getJob(), queueTime);
            synchronized ( this.processingJobsLists ) {
                this.processingJobsLists.put(jobId, ack);
            }
        }
        return ack != null;
View Full Code Here

            this.logger.debug("Ignored exception " + e.getMessage(), e);
        }
    }

    public boolean stopJob(final JobImpl job) {
        final JobHandler handler;
        synchronized ( this.processingJobsLists ) {
            handler = this.processingJobsLists.get(job.getId());
        }
        if ( handler != null ) {
            handler.stop();
        }
        return handler != null;
    }
View Full Code Here

        // check if we're still active
        final JobManagerConfiguration config = this.configuration;
        if ( config != null ) {
            final List<Job> rescheduleList = this.configuration.clearJobRetryList();
            for(final Job j : rescheduleList) {
                final JobHandler jh = new JobHandler((JobImpl)j, this.configuration);
                jh.reschedule();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.event.impl.jobs.JobHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.