org.apache.sling.event.impl.jobs.queues
Class AbstractJobQueue

java.lang.Object
  extended by org.apache.sling.event.impl.jobs.stats.StatisticsImpl
      extended by org.apache.sling.event.impl.jobs.queues.AbstractJobQueue
All Implemented Interfaces:
JobStatusNotifier, Queue, Statistics
Direct Known Subclasses:
AbstractParallelJobQueue, OrderedJobQueue

public abstract class AbstractJobQueue
extends StatisticsImpl
implements JobStatusNotifier, Queue

The job blocking queue extends the blocking queue by some functionality for the job event handling.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.sling.event.impl.jobs.deprecated.JobStatusNotifier
JobStatusNotifier.NotifierContext
 
Field Summary
protected  InternalQueueConfiguration configuration
          Configuration.
protected  boolean isWaiting
          Is the queue currently waiting(sleeping)
protected  boolean isWaitingForNext
          Marker flag if the queue is waiting for another element (= empty)
protected  org.slf4j.Logger logger
          The logger.
protected  String queueName
          The queue name.
protected  boolean running
          Are we still running?
 
Fields inherited from interface org.apache.sling.event.impl.jobs.deprecated.JobStatusNotifier
CONTEXT_PROPERTY_NAME
 
Constructor Summary
AbstractJobQueue(String name, InternalQueueConfiguration config, JobConsumerManager jobConsumerManager, org.osgi.service.event.EventAdmin eventAdmin)
          Start this queue
 
Method Summary
protected  boolean canBeClosed()
          Check whether this queue can be closed
 void checkForUnprocessedJobs()
          Periodically check for started jobs without an acknowledge.
 void clear()
          Remove all outstanding jobs from the queue.
 void close()
          Close this queue.
protected  boolean executeJob(JobHandler handler)
          Execute a job
 boolean finishedJob(org.osgi.service.event.Event job, boolean shouldReschedule)
          Notify that the job is finished.
 InternalQueueConfiguration getConfiguration()
          Return the queue configuration
 String getName()
          Get the name of the job queue.
 Object getState(String key)
          For monitoring purposes and possible extensions from the different queue types.
 String getStateInfo()
          Return some information about the current state of the queue.
 Statistics getStatistics()
          Return statistics information about this queue.
protected  void ignoreException(Exception e)
          Helper method which just logs the exception in debug mode.
protected abstract  boolean isEmpty()
          Is the queue empty?
protected  boolean isOutdated()
          Is the queue outdated?
 boolean isSuspended()
          Is the queue currently suspended?
protected abstract  void notifyFinished(JobHandler rescheduleInfo)
           
 void outdate()
          Outdate this queue.
 void process(JobHandler handler)
          Add a new job to the queue.
protected abstract  void put(JobHandler event)
          Put another job into the queue.
 void removeAll()
          Remove all outstanding jobs and delete them.
protected abstract  Collection<JobHandler> removeAllJobs()
          Remove all events from the queue and return them.
protected abstract  JobHandler reschedule(JobHandler info)
          Reschedule a job.
 void resume()
          Resume a suspended queue.
 boolean sendAcknowledge(org.osgi.service.event.Event job)
          Send an acknowledge message that someone is processing the job.
 void start()
          Start the job queue.
protected abstract  JobHandler start(JobHandler event)
           
 void suspend()
          Suspend the queue - when a queue is suspended it stops processing jobs - however already started jobs are finished (but not rescheduled).
protected abstract  JobHandler take()
          Get another job from the queue.
 boolean tryToClose()
          Check if the queue can be closed
 
Methods inherited from class org.apache.sling.event.impl.jobs.stats.StatisticsImpl
add, addActive, cancelledJob, clearQueued, copyFrom, decQueued, failedJob, finishedJob, getAverageProcessingTime, getAverageWaitingTime, getLastActivatedJobTime, getLastFinishedJobTime, getNumberOfActiveJobs, getNumberOfCancelledJobs, getNumberOfFailedJobs, getNumberOfFinishedJobs, getNumberOfJobs, getNumberOfProcessedJobs, getNumberOfQueuedJobs, getStartTime, incQueued, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.slf4j.Logger logger
The logger.


configuration

protected final InternalQueueConfiguration configuration
Configuration.


queueName

protected volatile String queueName
The queue name.


running

protected volatile boolean running
Are we still running?


isWaiting

protected volatile boolean isWaiting
Is the queue currently waiting(sleeping)


isWaitingForNext

protected boolean isWaitingForNext
Marker flag if the queue is waiting for another element (= empty)

Constructor Detail

AbstractJobQueue

public AbstractJobQueue(String name,
                        InternalQueueConfiguration config,
                        JobConsumerManager jobConsumerManager,
                        org.osgi.service.event.EventAdmin eventAdmin)
Start this queue

Parameters:
name - The queue name
config - The queue configuration
environment - The environment component
Method Detail

getStateInfo

public String getStateInfo()
Description copied from interface: Queue
Return some information about the current state of the queue. This method is meant to see the internal state of the queue for debugging or monitoring purposes.

Specified by:
getStateInfo in interface Queue
See Also:
Queue.getStateInfo()

start

public void start()
Start the job queue.


getConfiguration

public InternalQueueConfiguration getConfiguration()
Return the queue configuration

Specified by:
getConfiguration in interface Queue

close

public void close()
Close this queue.


tryToClose

public boolean tryToClose()
Check if the queue can be closed


canBeClosed

protected boolean canBeClosed()
Check whether this queue can be closed


checkForUnprocessedJobs

public void checkForUnprocessedJobs()
Periodically check for started jobs without an acknowledge.


sendAcknowledge

public boolean sendAcknowledge(org.osgi.service.event.Event job)
Description copied from interface: JobStatusNotifier
Send an acknowledge message that someone is processing the job.

Specified by:
sendAcknowledge in interface JobStatusNotifier
Parameters:
job - The job.
Returns:
true if the ack is ok, false otherwise (e.g. if someone else already send an ack for this job.
See Also:
JobStatusNotifier.sendAcknowledge(org.osgi.service.event.Event)

finishedJob

public boolean finishedJob(org.osgi.service.event.Event job,
                           boolean shouldReschedule)
Description copied from interface: JobStatusNotifier
Notify that the job is finished. If the job is not rescheduled, a return value of false indicates an error during the processing. If the job should be rescheduled, true indicates that the job could be rescheduled. If an error occurs or the number of retries is exceeded, false will be returned.

Specified by:
finishedJob in interface JobStatusNotifier
Parameters:
job - The job.
shouldReschedule - Should the event be rescheduled?
Returns:
true if everything went fine, false otherwise.
See Also:
JobStatusNotifier.finishedJob(org.osgi.service.event.Event, boolean)

getName

public String getName()
Get the name of the job queue.

Specified by:
getName in interface Queue

process

public void process(JobHandler handler)
Add a new job to the queue.


executeJob

protected boolean executeJob(JobHandler handler)
Execute a job


ignoreException

protected void ignoreException(Exception e)
Helper method which just logs the exception in debug mode.

Parameters:
e -

isOutdated

protected boolean isOutdated()
Is the queue outdated?


outdate

public void outdate()
Outdate this queue.


getStatistics

public Statistics getStatistics()
Description copied from interface: Queue
Return statistics information about this queue.

Specified by:
getStatistics in interface Queue
See Also:
Queue.getStatistics()

resume

public void resume()
Description copied from interface: Queue
Resume a suspended queue. Queue.suspend(). If the queue is not suspended, calling this method has no effect. Depending on the queue implementation, if a job failed a job queue might sleep for a configured time, before a new job is processed. By calling this method, the job queue can be woken up and force an immediate reprocessing. This feature is only supported by ordered queues at the moment. If a queue does not support this feature, calling this method has only an effect if the queue is really suspended.

Specified by:
resume in interface Queue
See Also:
Queue.resume()

suspend

public void suspend()
Description copied from interface: Queue
Suspend the queue - when a queue is suspended it stops processing jobs - however already started jobs are finished (but not rescheduled). Depending on the queue implementation, the queue is only suspended for a specific time. A queue can be resumed with Queue.resume().

Specified by:
suspend in interface Queue
See Also:
Queue.suspend()

isSuspended

public boolean isSuspended()
Description copied from interface: Queue
Is the queue currently suspended?

Specified by:
isSuspended in interface Queue
See Also:
Queue.isSuspended()

removeAll

public void removeAll()
Description copied from interface: Queue
Remove all outstanding jobs and delete them. This actually cancels all outstanding jobs (but no notifications are send).

Specified by:
removeAll in interface Queue
See Also:
Queue.removeAll()

clear

public void clear()
Description copied from interface: Queue
Remove all outstanding jobs from the queue. This does not delete the jobs. The jobs are either processed by a different cluster node or on restart.

Specified by:
clear in interface Queue
See Also:
Queue.clear()

getState

public Object getState(String key)
Description copied from interface: Queue
For monitoring purposes and possible extensions from the different queue types. This method allows to query state information.

Specified by:
getState in interface Queue
See Also:
Queue.getState(java.lang.String)

reschedule

protected abstract JobHandler reschedule(JobHandler info)
Reschedule a job.


put

protected abstract void put(JobHandler event)
Put another job into the queue.


take

protected abstract JobHandler take()
Get another job from the queue.


isEmpty

protected abstract boolean isEmpty()
Is the queue empty?


removeAllJobs

protected abstract Collection<JobHandler> removeAllJobs()
Remove all events from the queue and return them.


start

protected abstract JobHandler start(JobHandler event)

notifyFinished

protected abstract void notifyFinished(JobHandler rescheduleInfo)


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.