org.apache.sling.event.jobs
Class JobUtil

java.lang.Object
  extended by org.apache.sling.event.jobs.JobUtil

public abstract class JobUtil
extends Object

The Job class is an utility class for creating and processing jobs.

Since:
3.0

Nested Class Summary
static class JobUtil.JobPriority
          The priority for jobs.
 
Field Summary
static String JOB_ID
          This is a unique identifer which can be used to cancel the job.
static String PROPERTY_JOB_CREATED
          This property is set by the eventing and contains a calendar object specifying the date and time when this job has been created.
static String PROPERTY_JOB_NAME
          The property for the unique event name.
static String PROPERTY_JOB_PARALLEL
          The property to set if a job can be run parallel to any other job.
static String PROPERTY_JOB_PRIORITY
          This property allows to override the priority for the thread used to start this job.
static String PROPERTY_JOB_QUEUE_NAME
          The property to set to put the jobs into a separate job queue.
static String PROPERTY_JOB_QUEUE_ORDERED
          If this property is set with any value, the queue processes the jobs in the same order as they have arrived.
static String PROPERTY_JOB_RETRIES
          The property for setting the maximum number of retries.
static String PROPERTY_JOB_RETRY_COUNT
          The property to track the retry count for jobs.
static String PROPERTY_JOB_RETRY_DELAY
          The property to set a retry delay.
static String PROPERTY_JOB_RUN_LOCAL
          The property to set if a job should only be run on the same app it has been created.
static String PROPERTY_JOB_TOPIC
          The job topic property.
static String PROPERTY_NOTIFICATION_JOB
          Property containing the job event.
static String TOPIC_JOB
          The topic for jobs.
static String TOPIC_JOB_CANCELLED
          Asynchronous notification event when a job is cancelled.
static String TOPIC_JOB_FAILED
          Asynchronous notification event when a job failed.
static String TOPIC_JOB_FINISHED
          Asynchronous notification event when a job is finished.
static String TOPIC_JOB_STARTED
          Asynchronous notification event when a job is started.
 
Method Summary
static boolean acknowledgeJob(org.osgi.service.event.Event job)
          Send an acknowledge.
static void finishedJob(org.osgi.service.event.Event job)
          Notify a finished job.
static Calendar getJobCreated(org.osgi.service.event.Event job)
          Get the created calendar object.
static boolean isJobEvent(org.osgi.service.event.Event event)
          Is this a job event?
static void processJob(org.osgi.service.event.Event job, JobProcessor processor)
          Process a job in the background and notify its success.
static boolean rescheduleJob(org.osgi.service.event.Event job)
          Notify a failed job.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_JOB_TOPIC

public static final String PROPERTY_JOB_TOPIC
The job topic property.

See Also:
Constant Field Values

PROPERTY_JOB_NAME

public static final String PROPERTY_JOB_NAME
The property for the unique event name. Value is of type String (This is optional).

See Also:
Constant Field Values

PROPERTY_JOB_PARALLEL

public static final String PROPERTY_JOB_PARALLEL
The property to set if a job can be run parallel to any other job. The following values are supported: - boolean value true and false - string value true and false - integer value higher than 1 - if this is specified jobs are run in parallel but never more than the specified number. We might want to use different values in the future for enhanced parallel job handling. This value is only used, if PROPERTY_JOB_QUEUE_NAME is specified and the referenced queue is not started yet.

See Also:
Constant Field Values

PROPERTY_JOB_RUN_LOCAL

public static final String PROPERTY_JOB_RUN_LOCAL
The property to set if a job should only be run on the same app it has been created.

See Also:
Constant Field Values

PROPERTY_JOB_RETRY_COUNT

public static final String PROPERTY_JOB_RETRY_COUNT
The property to track the retry count for jobs. Value is of type Integer.

See Also:
Constant Field Values

PROPERTY_JOB_RETRIES

public static final String PROPERTY_JOB_RETRIES
The property for setting the maximum number of retries. Value is of type Integer.

See Also:
Constant Field Values

PROPERTY_JOB_RETRY_DELAY

public static final String PROPERTY_JOB_RETRY_DELAY
The property to set a retry delay. Value is of type Long and specifies milliseconds.

See Also:
Constant Field Values

PROPERTY_JOB_QUEUE_NAME

public static final String PROPERTY_JOB_QUEUE_NAME
The property to set to put the jobs into a separate job queue. This property specifies the name of the job queue. If the job queue does not exists yet a new queue is created. If a ordered job queue is used, the jobs are never executed in parallel from this queue! For non ordered queues the PROPERTY_JOB_PARALLEL with an integer value higher than 1 can be used to specify the maximum number of parallel jobs for this queue.

See Also:
Constant Field Values

PROPERTY_JOB_QUEUE_ORDERED

public static final String PROPERTY_JOB_QUEUE_ORDERED
If this property is set with any value, the queue processes the jobs in the same order as they have arrived. This property has only an effect if PROPERTY_JOB_QUEUE_NAME is specified and the job queue has not been started yet.

See Also:
Constant Field Values

PROPERTY_JOB_PRIORITY

public static final String PROPERTY_JOB_PRIORITY
This property allows to override the priority for the thread used to start this job. The property is evaluated by the processJob(Event, JobProcessor) method. If another way of executing the job is used, it is up to the client to ensure the job priority. For possible values see JobUtil.JobPriority.

See Also:
Constant Field Values

PROPERTY_JOB_CREATED

public static final String PROPERTY_JOB_CREATED
This property is set by the eventing and contains a calendar object specifying the date and time when this job has been created.

See Also:
Constant Field Values

TOPIC_JOB

public static final String TOPIC_JOB
The topic for jobs.

See Also:
Constant Field Values

JOB_ID

public static final String JOB_ID
This is a unique identifer which can be used to cancel the job.

See Also:
Constant Field Values

TOPIC_JOB_STARTED

public static final String TOPIC_JOB_STARTED
Asynchronous notification event when a job is started. The property PROPERTY_NOTIFICATION_JOB contains the job event and the property EventConstants.TIMESTAMP contains the timestamp of the event (as a Long).

See Also:
Constant Field Values

TOPIC_JOB_FINISHED

public static final String TOPIC_JOB_FINISHED
Asynchronous notification event when a job is finished. The property PROPERTY_NOTIFICATION_JOB contains the job event and the property EventConstants.TIMESTAMP contains the timestamp of the event (as a Long).

See Also:
Constant Field Values

TOPIC_JOB_FAILED

public static final String TOPIC_JOB_FAILED
Asynchronous notification event when a job failed. If a job execution fails, it is rescheduled for another try. The property PROPERTY_NOTIFICATION_JOB contains the job event and the property EventConstants.TIMESTAMP contains the timestamp of the event (as a Long).

See Also:
Constant Field Values

TOPIC_JOB_CANCELLED

public static final String TOPIC_JOB_CANCELLED
Asynchronous notification event when a job is cancelled. If a job execution is cancelled it is not rescheduled. The property PROPERTY_NOTIFICATION_JOB contains the job event and the property EventConstants.TIMESTAMP contains the timestamp of the event (as a Long).

See Also:
Constant Field Values

PROPERTY_NOTIFICATION_JOB

public static final String PROPERTY_NOTIFICATION_JOB
Property containing the job event. The value is of type org.osgi.service.event.Event.

See Also:
Constant Field Values
Method Detail

isJobEvent

public static boolean isJobEvent(org.osgi.service.event.Event event)
Is this a job event? This method checks if the event contains the PROPERTY_JOB_TOPIC property.

Parameters:
event - The event to check.
Returns:
true> if this is a job event.

acknowledgeJob

public static boolean acknowledgeJob(org.osgi.service.event.Event job)
Send an acknowledge. This signals the job handler that someone is starting to process the job. This method should be invoked as a first command during job processing. If this method returns false this means someone else is already processing this job, and the caller should not process the event anymore.

Returns:
Returns true if the acknowledge could be sent
Throws:
IllegalArgumentException - If the event is a job event but does not have a notifier context.

finishedJob

public static void finishedJob(org.osgi.service.event.Event job)
Notify a finished job.

Throws:
IllegalArgumentException - If the event is a job event but does not have a notifier context.

rescheduleJob

public static boolean rescheduleJob(org.osgi.service.event.Event job)
Notify a failed job.

Returns:
true if the job has been rescheduled, false otherwise.
Throws:
IllegalArgumentException - If the event is a job event but does not have a notifier context.

processJob

public static void processJob(org.osgi.service.event.Event job,
                              JobProcessor processor)
Process a job in the background and notify its success. This method also sends an acknowledge message to the job event handler.

Throws:
IllegalArgumentException - If the event is a job event but does not have a notifier context.

getJobCreated

public static Calendar getJobCreated(org.osgi.service.event.Event job)
Get the created calendar object.

Parameters:
job - The job event
Returns:
The created info or null if this is not a job event.


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