org.apache.sling.event.impl
Class TimedJobHandler

java.lang.Object
  extended by org.apache.sling.event.impl.AbstractRepositoryEventHandler
      extended by org.apache.sling.event.impl.TimedJobHandler
All Implemented Interfaces:
javax.jcr.observation.EventListener, Job, TimedEventStatusProvider, org.osgi.service.event.EventHandler

@Service(value=TimedEventStatusProvider.class)
@Properties(value={@Property(name="event.topics",propertyPrivate=true,value={"org/osgi/framework/BundleEvent/UPDATED","org/osgi/framework/BundleEvent/STARTED","org/apache/sling/event/timed"}),@Property(name="repository.path",value="/var/eventing/timed-jobs",propertyPrivate=true)})
public class TimedJobHandler
extends AbstractRepositoryEventHandler
implements Job, TimedEventStatusProvider

An event handler for timed events.


Nested Class Summary
protected static class TimedJobHandler.ScheduleInfo
           
 
Nested classes/interfaces inherited from class org.apache.sling.event.impl.AbstractRepositoryEventHandler
AbstractRepositoryEventHandler.EventInfo
 
Field Summary
 
Fields inherited from class org.apache.sling.event.impl.AbstractRepositoryEventHandler
CONFIG_PROPERTY_REPO_PATH, environment, logger, queue, repositoryPath, running, writeLock, writeQueue, writerSession
 
Fields inherited from interface org.apache.sling.event.TimedEventStatusProvider
PROPERTY_EVENT_ID
 
Constructor Summary
TimedJobHandler()
           
 
Method Summary
protected  void addNodeProperties(javax.jcr.Node eventNode, org.osgi.service.event.Event event)
          Add properties when storing event in repository.
 void cancelTimedEvent(String jobId)
          Cancel this timed event.
 void execute(JobContext context)
          Execute this job.
protected  String getEventNodeType()
          Return the node type for the event.
 org.osgi.service.event.Event getScheduledEvent(String topic, String eventId, String jobId)
          Return the scheduled event with the given id.
 Collection<org.osgi.service.event.Event> getScheduledEvents(String topic, Map<String,Object>... filterProps)
          Return a list of currently schedulded events.
 void handleEvent(org.osgi.service.event.Event event)
           
protected  void loadEvents()
          Load all active timed events from the repository.
 void onEvent(javax.jcr.observation.EventIterator iter)
           
protected  String persistEvent(org.osgi.service.event.Event event, TimedJobHandler.ScheduleInfo scheduleInfo)
           
protected  boolean processEvent(org.osgi.service.event.Event event, TimedJobHandler.ScheduleInfo scheduleInfo)
          Process the event.
protected  void processWriteQueue()
           
protected  void runInBackground()
           
protected  void startWriterSession()
          Start the repository session and add this handler as an observer for new events created on other nodes.
 
Methods inherited from class org.apache.sling.event.impl.AbstractRepositoryEventHandler
activate, addEventProperties, deactivate, getWriterRootNode, ignoreException, readEvent, stopWriterSession, writeEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimedJobHandler

public TimedJobHandler()
Method Detail

startWriterSession

protected void startWriterSession()
                           throws javax.jcr.RepositoryException
Description copied from class: AbstractRepositoryEventHandler
Start the repository session and add this handler as an observer for new events created on other nodes.

Overrides:
startWriterSession in class AbstractRepositoryEventHandler
Throws:
javax.jcr.RepositoryException
See Also:
AbstractRepositoryEventHandler.startWriterSession()

processWriteQueue

protected void processWriteQueue()
Specified by:
processWriteQueue in class AbstractRepositoryEventHandler
See Also:
AbstractRepositoryEventHandler.processWriteQueue()

runInBackground

protected void runInBackground()
Specified by:
runInBackground in class AbstractRepositoryEventHandler
See Also:
AbstractRepositoryEventHandler.runInBackground()

persistEvent

protected String persistEvent(org.osgi.service.event.Event event,
                              TimedJobHandler.ScheduleInfo scheduleInfo)

processEvent

protected boolean processEvent(org.osgi.service.event.Event event,
                               TimedJobHandler.ScheduleInfo scheduleInfo)
Process the event. If a scheduler is available, a job is scheduled or stopped.

Parameters:
event - The incomming event.
Returns:

onEvent

public void onEvent(javax.jcr.observation.EventIterator iter)
Specified by:
onEvent in interface javax.jcr.observation.EventListener
See Also:
EventListener.onEvent(javax.jcr.observation.EventIterator)

handleEvent

public void handleEvent(org.osgi.service.event.Event event)
Specified by:
handleEvent in interface org.osgi.service.event.EventHandler
See Also:
EventHandler.handleEvent(org.osgi.service.event.Event)

execute

public void execute(JobContext context)
Description copied from interface: Job
Execute this job.

Specified by:
execute in interface Job
Parameters:
context - The context of the job.
See Also:
Job.execute(org.apache.sling.commons.scheduler.JobContext)

loadEvents

protected void loadEvents()
Load all active timed events from the repository.

Throws:
javax.jcr.RepositoryException

addNodeProperties

protected void addNodeProperties(javax.jcr.Node eventNode,
                                 org.osgi.service.event.Event event)
                          throws javax.jcr.RepositoryException
Description copied from class: AbstractRepositoryEventHandler
Add properties when storing event in repository. This method can be enhanced by sub classes.

Overrides:
addNodeProperties in class AbstractRepositoryEventHandler
Throws:
javax.jcr.RepositoryException
See Also:
org.apache.sling.engine.event.impl.JobPersistenceHandler#addNodeProperties(javax.jcr.Node, org.osgi.service.event.Event)

getEventNodeType

protected String getEventNodeType()
Description copied from class: AbstractRepositoryEventHandler
Return the node type for the event.

Overrides:
getEventNodeType in class AbstractRepositoryEventHandler
See Also:
AbstractRepositoryEventHandler.getEventNodeType()

getScheduledEvent

public org.osgi.service.event.Event getScheduledEvent(String topic,
                                                      String eventId,
                                                      String jobId)
Description copied from interface: TimedEventStatusProvider
Return the scheduled event with the given id.

Specified by:
getScheduledEvent in interface TimedEventStatusProvider
Returns:
The scheduled event or null.
See Also:
TimedEventStatusProvider.getScheduledEvent(java.lang.String, java.lang.String, java.lang.String)

getScheduledEvents

public Collection<org.osgi.service.event.Event> getScheduledEvents(String topic,
                                                                   Map<String,Object>... filterProps)
Description copied from interface: TimedEventStatusProvider
Return a list of currently schedulded events.

Specified by:
getScheduledEvents in interface TimedEventStatusProvider
Parameters:
topic - Topic can be used as a filter, if it is non-null, only jobs with this topic will be returned.
filterProps - A list of filter property maps. Each map acts like a template. The searched event must match the template (AND query). By providing several maps, different filters are possible (OR query).
Returns:
A non null collection.
See Also:
TimedEventStatusProvider.getScheduledEvents(java.lang.String, java.util.Map...)

cancelTimedEvent

public void cancelTimedEvent(String jobId)
Description copied from interface: TimedEventStatusProvider
Cancel this timed event.

Specified by:
cancelTimedEvent in interface TimedEventStatusProvider
Parameters:
jobId - The unique identifer as found in the property TimedEventStatusProvider.PROPERTY_EVENT_ID.
See Also:
TimedEventStatusProvider.cancelTimedEvent(java.lang.String)


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