org.apache.sling.event.impl
Class AbstractRepositoryEventHandler

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

@Service(value=org.osgi.service.event.EventHandler.class)
public abstract class AbstractRepositoryEventHandler
extends Object
implements org.osgi.service.event.EventHandler, javax.jcr.observation.EventListener

Abstract base class for all event handlers in this package.


Nested Class Summary
static class AbstractRepositoryEventHandler.EventInfo
           
 
Field Summary
protected static String CONFIG_PROPERTY_REPO_PATH
           
protected  EnvironmentComponent environment
          Environment component.
protected  org.slf4j.Logger logger
          Default log.
protected  java.util.concurrent.BlockingQueue<AbstractRepositoryEventHandler.EventInfo> queue
          A local queue for serialising the event processing.
protected  String repositoryPath
          The path in the repository.
protected  boolean running
          Is the background task still running?
protected  Object writeLock
          Sync lock
protected  java.util.concurrent.BlockingQueue<org.osgi.service.event.Event> writeQueue
          A local queue for writing received events into the repository.
protected  javax.jcr.Session writerSession
          The repository session to write into the repository.
 
Constructor Summary
AbstractRepositoryEventHandler()
           
 
Method Summary
protected  void activate(org.osgi.service.component.ComponentContext context)
          Activate this component.
protected  void addEventProperties(javax.jcr.Node eventNode, Dictionary<String,Object> properties)
          Add properties from the node to the event properties.
protected  void addNodeProperties(javax.jcr.Node eventNode, org.osgi.service.event.Event event)
          Add properties when storing event in repository.
protected  void deactivate(org.osgi.service.component.ComponentContext context)
          Deactivate this component.
protected  String getEventNodeType()
          Return the node type for the event.
protected  javax.jcr.Node getWriterRootNode()
          Get the root node from the writer session.
protected  void ignoreException(Exception e)
          Helper method which just logs the exception in debug mode.
protected abstract  void processWriteQueue()
           
protected  org.osgi.service.event.Event readEvent(javax.jcr.Node eventNode)
          Read an event from the repository.
protected abstract  void runInBackground()
           
protected  void startWriterSession()
          Start the repository session and add this handler as an observer for new events created on other nodes.
protected  void stopWriterSession()
          Stop the session.
protected  javax.jcr.Node writeEvent(org.osgi.service.event.Event e, String suggestedName)
          Write an event to the repository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.osgi.service.event.EventHandler
handleEvent
 
Methods inherited from interface javax.jcr.observation.EventListener
onEvent
 

Field Detail

logger

protected final org.slf4j.Logger logger
Default log.


CONFIG_PROPERTY_REPO_PATH

@Property(value="/sling/events")
protected static final String CONFIG_PROPERTY_REPO_PATH
See Also:
Constant Field Values

writerSession

protected javax.jcr.Session writerSession
The repository session to write into the repository.


writeLock

protected final Object writeLock
Sync lock


repositoryPath

protected String repositoryPath
The path in the repository.


running

protected volatile boolean running
Is the background task still running?


queue

protected final java.util.concurrent.BlockingQueue<AbstractRepositoryEventHandler.EventInfo> queue
A local queue for serialising the event processing.


writeQueue

protected final java.util.concurrent.BlockingQueue<org.osgi.service.event.Event> writeQueue
A local queue for writing received events into the repository.


environment

@Reference
protected EnvironmentComponent environment
Environment component.

Constructor Detail

AbstractRepositoryEventHandler

public AbstractRepositoryEventHandler()
Method Detail

activate

protected void activate(org.osgi.service.component.ComponentContext context)
Activate this component.

Parameters:
context -

runInBackground

protected abstract void runInBackground()
                                 throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

processWriteQueue

protected abstract void processWriteQueue()

deactivate

protected void deactivate(org.osgi.service.component.ComponentContext context)
Deactivate this component.

Parameters:
context -

startWriterSession

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

Throws:
javax.jcr.RepositoryException

stopWriterSession

protected void stopWriterSession()
Stop the session.


getEventNodeType

protected String getEventNodeType()
Return the node type for the event.


getWriterRootNode

protected javax.jcr.Node getWriterRootNode()
Get the root node from the writer session.


writeEvent

protected javax.jcr.Node writeEvent(org.osgi.service.event.Event e,
                                    String suggestedName)
                             throws javax.jcr.RepositoryException
Write an event to the repository.

Parameters:
e - The event
suggestName - A suggest name/path for the node.
Throws:
javax.jcr.RepositoryException

readEvent

protected org.osgi.service.event.Event readEvent(javax.jcr.Node eventNode)
                                          throws javax.jcr.RepositoryException,
                                                 ClassNotFoundException
Read an event from the repository.

Returns:
Throws:
javax.jcr.RepositoryException
ClassNotFoundException

addEventProperties

protected void addEventProperties(javax.jcr.Node eventNode,
                                  Dictionary<String,Object> properties)
                           throws javax.jcr.RepositoryException
Add properties from the node to the event properties.

Parameters:
eventNode - The repository node.
properties - The event properties.
Throws:
javax.jcr.RepositoryException

addNodeProperties

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

Parameters:
eventNode -
event -
Throws:
javax.jcr.RepositoryException

ignoreException

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

Parameters:
e -


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