org.apache.sling.event
Class EventUtil

java.lang.Object
  extended by org.apache.sling.event.EventUtil

public abstract class EventUtil
extends java.lang.Object

The EventUtil class is an utility class for clustered environments.


Nested Class Summary
static interface EventUtil.JobStatusNotifier
          This is a private interface which is only public for import reasons.
 
Field Summary
static java.lang.String PROPERTY_APPLICATION
          This event property specifies the application node.
static java.lang.String PROPERTY_DISTRIBUTE
          This event property indicates, if the event should be distributed in the cluster (default false).
static java.lang.String PROPERTY_JOB_ID
          The property for the unique event id.
static java.lang.String PROPERTY_JOB_PARALLEL
          The property to set if a job can be run parallel to any other job.
static java.lang.String PROPERTY_JOB_QUEUE_NAME
          The property to set to put the jobs into a separate job queue.
static java.lang.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 java.lang.String PROPERTY_JOB_RETRIES
          The property to for setting the maximum number of retries.
static java.lang.String PROPERTY_JOB_RETRY_COUNT
          The property to track the retry count for jobs.
static java.lang.String PROPERTY_JOB_RETRY_DELAY
          The property to set a retry delay.
static java.lang.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 java.lang.String PROPERTY_JOB_TOPIC
          The job topic property.
static java.lang.String PROPERTY_TIMED_EVENT_DATE
          The date for the timed event.
static java.lang.String PROPERTY_TIMED_EVENT_ID
          The property for the unique event id.
static java.lang.String PROPERTY_TIMED_EVENT_PERIOD
          The period for the timed event.
static java.lang.String PROPERTY_TIMED_EVENT_SCHEDULE
          The scheduler expression for the timed event.
static java.lang.String PROPERTY_TIMED_EVENT_TOPIC
          The real topic of the event.
static java.lang.String TOPIC_JOB
          The topic for jobs.
static java.lang.String TOPIC_TIMED_EVENT
          The topic for timed events.
 
Constructor Summary
EventUtil()
           
 
Method Summary
static void addProperties(javax.jcr.Node node, EventPropertiesMap properties, java.lang.String[] ignoreProps, java.lang.String binPropertyName)
          Add all java properties as properties to the node.
static void addProperties(javax.jcr.Node node, java.util.Map<java.lang.String,java.lang.Object> properties, java.lang.String[] ignoreProps, java.lang.String binPropertyName)
          Add all java properties as properties to the node.
static org.osgi.service.event.Event createDistributableEvent(java.lang.String topic, java.util.Dictionary<java.lang.String,java.lang.Object> properties)
          Create a distributable event.
static void finishedJob(org.osgi.service.event.Event job)
          Notify a finished job.
static java.lang.String getApplicationId(org.osgi.service.event.Event event)
          Return the application id the event was created at.
static java.lang.String getNodePropertyName(java.lang.String name)
          Return the converted repository property name
static javax.jcr.Value getNodePropertyValue(javax.jcr.ValueFactory valueFactory, java.lang.Object eventValue)
          Return the converted repository property value
static boolean isJobEvent(org.osgi.service.event.Event event)
          Is this a job event?
static boolean isLocal(org.osgi.service.event.Event event)
          Is this a local event?
static void processJob(org.osgi.service.event.Event job, JobProcessor processor)
          Process a job in the background and notify its success.
static EventPropertiesMap readProperties(javax.jcr.Node node, java.lang.String binPropertyName, java.lang.String[] ignorePrefixes)
          Read properties from a repository node and create a property map.
static boolean rescheduleJob(org.osgi.service.event.Event job)
          Notify a failed job.
static boolean shouldDistribute(org.osgi.service.event.Event event)
          Should this event be distributed in the cluster?
static java.lang.String toString(org.osgi.service.event.Event e)
          Improved toString method for an Event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_DISTRIBUTE

public static final java.lang.String PROPERTY_DISTRIBUTE
This event property indicates, if the event should be distributed in the cluster (default false).

See Also:
Constant Field Values

PROPERTY_APPLICATION

public static final java.lang.String PROPERTY_APPLICATION
This event property specifies the application node.

See Also:
Constant Field Values

PROPERTY_JOB_TOPIC

public static final java.lang.String PROPERTY_JOB_TOPIC
The job topic property.

See Also:
Constant Field Values

PROPERTY_JOB_ID

public static final java.lang.String PROPERTY_JOB_ID
The property for the unique event id. Value is of type String.

See Also:
Constant Field Values

PROPERTY_JOB_PARALLEL

public static final java.lang.String PROPERTY_JOB_PARALLEL
The property to set if a job can be run parallel to any other job.

See Also:
Constant Field Values

PROPERTY_JOB_RUN_LOCAL

public static final java.lang.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 java.lang.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 java.lang.String PROPERTY_JOB_RETRIES
The property to for setting the maximum number of retries. Value is of type Integer.

See Also:
Constant Field Values

PROPERTY_JOB_RETRY_DELAY

public static final java.lang.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 java.lang.String PROPERTY_JOB_QUEUE_NAME
The property to set to put the jobs into a separate job queue. This property spcifies the name of the job queue. If the job queue does not exists yet a new queue is created. If a job queue is used, the jobs are never executed in parallel from this queue!

See Also:
Constant Field Values

PROPERTY_JOB_QUEUE_ORDERED

public static final java.lang.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.

See Also:
Constant Field Values

TOPIC_JOB

public static final java.lang.String TOPIC_JOB
The topic for jobs.

See Also:
Constant Field Values

TOPIC_TIMED_EVENT

public static final java.lang.String TOPIC_TIMED_EVENT
The topic for timed events.

See Also:
Constant Field Values

PROPERTY_TIMED_EVENT_TOPIC

public static final java.lang.String PROPERTY_TIMED_EVENT_TOPIC
The real topic of the event.

See Also:
Constant Field Values

PROPERTY_TIMED_EVENT_ID

public static final java.lang.String PROPERTY_TIMED_EVENT_ID
The property for the unique event id.

See Also:
Constant Field Values

PROPERTY_TIMED_EVENT_SCHEDULE

public static final java.lang.String PROPERTY_TIMED_EVENT_SCHEDULE
The scheduler expression for the timed event.

See Also:
Constant Field Values

PROPERTY_TIMED_EVENT_PERIOD

public static final java.lang.String PROPERTY_TIMED_EVENT_PERIOD
The period for the timed event.

See Also:
Constant Field Values

PROPERTY_TIMED_EVENT_DATE

public static final java.lang.String PROPERTY_TIMED_EVENT_DATE
The date for the timed event.

See Also:
Constant Field Values
Constructor Detail

EventUtil

public EventUtil()
Method Detail

createDistributableEvent

public static org.osgi.service.event.Event createDistributableEvent(java.lang.String topic,
                                                                    java.util.Dictionary<java.lang.String,java.lang.Object> properties)
Create a distributable event. A distributable event is distributed across the cluster.

Parameters:
topic -
properties -
Returns:
An OSGi event.

shouldDistribute

public static boolean shouldDistribute(org.osgi.service.event.Event event)
Should this event be distributed in the cluster?

Parameters:
event -
Returns:
true if the event should be distributed.

isLocal

public static boolean isLocal(org.osgi.service.event.Event event)
Is this a local event?

Parameters:
event -
Returns:
true if this is a local event

getApplicationId

public static java.lang.String getApplicationId(org.osgi.service.event.Event event)
Return the application id the event was created at.

Parameters:
event -
Returns:
The application id or null if the event has been created locally.

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.

finishedJob

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

Throws:
java.lang.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:
java.lang.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.


addProperties

public static void addProperties(javax.jcr.Node node,
                                 java.util.Map<java.lang.String,java.lang.Object> properties,
                                 java.lang.String[] ignoreProps,
                                 java.lang.String binPropertyName)
                          throws javax.jcr.RepositoryException
Add all java properties as properties to the node. If the name and the value of a map entry can easily converted into a repository property, it is directly added. All other java properties are stored in one binary property.

Parameters:
node - The node where all properties are added to
properties - The map of properties.
ignoreProps - optional list of property which should be ignored
binPropertyName - The name of the binary property.
Throws:
javax.jcr.RepositoryException

addProperties

public static void addProperties(javax.jcr.Node node,
                                 EventPropertiesMap properties,
                                 java.lang.String[] ignoreProps,
                                 java.lang.String binPropertyName)
                          throws javax.jcr.RepositoryException
Add all java properties as properties to the node. If the name and the value of a map entry can easily converted into a repository property, it is directly added. All other java properties are stored in one binary property.

Parameters:
node - The node where all properties are added to
properties - The map of properties.
ignoreProps - optional list of property which should be ignored
binPropertyName - The name of the binary property.
Throws:
javax.jcr.RepositoryException

readProperties

public static EventPropertiesMap readProperties(javax.jcr.Node node,
                                                java.lang.String binPropertyName,
                                                java.lang.String[] ignorePrefixes)
                                         throws javax.jcr.RepositoryException,
                                                java.lang.ClassNotFoundException
Read properties from a repository node and create a property map.

Throws:
javax.jcr.RepositoryException
java.lang.ClassNotFoundException

getNodePropertyName

public static java.lang.String getNodePropertyName(java.lang.String name)
Return the converted repository property name

Parameters:
name - The java object property name
Returns:
The converted name or null if not possible.

getNodePropertyValue

public static javax.jcr.Value getNodePropertyValue(javax.jcr.ValueFactory valueFactory,
                                                   java.lang.Object eventValue)
Return the converted repository property value

Parameters:
valueFactory - The value factory
eventValue - The event value
Returns:
The converted value or null if not possible

toString

public static java.lang.String toString(org.osgi.service.event.Event e)
Improved toString method for an Event. This method prints out the event topic and all of the properties.



Copyright © 2007-2009. All Rights Reserved.