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

java.lang.Object
  extended by org.apache.sling.event.impl.jobs.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.JobStatusNotifier
JobStatusNotifier.NotifierContext
 
Field Summary
protected  InternalQueueConfiguration configuration
          Configuration.
protected  boolean isWaiting
          Is the queue currently waiting(sleeping)
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.JobStatusNotifier
CONTEXT_PROPERTY_NAME
 
Constructor Summary
AbstractJobQueue(String name, InternalQueueConfiguration config, EnvironmentComponent environment)
          Start this queue
 
Method Summary
protected  boolean canBeMarkedForRemoval()
           
 void checkForUnprocessedJobs()
          Periodically check for started jobs without an ack.
 void clear()
          Remove all outstanding jobs from the queue.
 void close()
          Close this queue.
protected  boolean executeJob(JobEvent info)
          Process 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?
 boolean isMarkedForRemoval()
          Check if this queue is marked for removal
 boolean isSuspended()
          Is the queue currently suspended?
 void markForRemoval()
          Mark this queue for removal.
protected abstract  void notifyFinished(JobEvent rescheduleInfo)
           
 void process(JobEvent event)
          Add a new job to the queue.
protected abstract  void put(JobEvent event)
          Put another job into the queue.
 void removeAll()
          Remove all outstanding jobs and delete them.
protected abstract  Collection<JobEvent> removeAllJobs()
          Remove all events from the queue and return them.
 void rename(String name)
          Rename this queue.
protected abstract  JobEvent reschedule(JobEvent 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  JobEvent start(JobEvent 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  JobEvent take()
          Get another job from the queue.
 
Methods inherited from class org.apache.sling.event.impl.jobs.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)

Constructor Detail

AbstractJobQueue

public AbstractJobQueue(String name,
                        InternalQueueConfiguration config,
                        EnvironmentComponent environment)
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.


checkForUnprocessedJobs

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


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)

canBeMarkedForRemoval

protected boolean canBeMarkedForRemoval()

markForRemoval

public void markForRemoval()
Mark this queue for removal.


isMarkedForRemoval

public boolean isMarkedForRemoval()
Check if this queue is marked for removal


getName

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

Specified by:
getName in interface Queue

process

public void process(JobEvent event)
Add a new job to the queue.


executeJob

protected boolean executeJob(JobEvent info)
Process a job


ignoreException

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

Parameters:
e -

rename

public void rename(String name)
Rename this queue.


reschedule

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


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 supsended.

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)

put

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


take

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


isEmpty

protected abstract boolean isEmpty()
Is the queue empty?


removeAllJobs

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


start

protected abstract JobEvent start(JobEvent event)

notifyFinished

protected abstract void notifyFinished(JobEvent rescheduleInfo)


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