incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r690164 - in /incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event: JobStatusProvider.java impl/JobEventHandler.java
Date Fri, 29 Aug 2008 09:46:57 GMT
Author: cziegeler
Date: Fri Aug 29 02:46:56 2008
New Revision: 690164

URL: http://svn.apache.org/viewvc?rev=690164&view=rev
Log:
Provide or search functionality; fix shutdown problem,  when service is shutdown before the
background thread started

Modified:
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java?rev=690164&r1=690163&r2=690164&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/JobStatusProvider.java
Fri Aug 29 02:46:56 2008
@@ -57,29 +57,35 @@
     /**
      * Return a list of currently schedulded jobs.
      * @param topic Topic can be used as a filter, if it is non-null, only jobs with this
topic will be returned.
-     * @param filterProps An optional map of filter props that act like a template.
+     * @param filterProps A list of filter property maps. Each map acts like a template.
The searched job
+     *                    must match the template (AND query). By providing several maps,
different filters
+     *                    are possible (OR query).
      * @return A non null collection.
      */
-    Collection<Event> getScheduledJobs(String topic, Map<String, Object> filterProps);
+    Collection<Event> getScheduledJobs(String topic, Map<String, Object>... filterProps);
 
     /**
      * Return the jobs which are currently in processing. If there are several application
nodes
      * in the cluster, there could be more than one job in processing
      * @param topic Topic can be used as a filter, if it is non-null, only jobs with this
topic will be returned.
-     * @param filterProps An optional map of filter props that act like a template.
+     * @param filterProps A list of filter property maps. Each map acts like a template.
The searched job
+     *                    must match the template (AND query). By providing several maps,
different filters
+     *                    are possible (OR query).
      * @return A non null collection.
      */
-    Collection<Event> getCurrentJobs(String topic, Map<String, Object> filterProps);
+    Collection<Event> getCurrentJobs(String topic, Map<String, Object>... filterProps);
 
     /**
      * Return all jobs either running or scheduled.
-     * This is actually a convenience method and collects the results from {@link #getScheduledJobs(String,
Map)}
-     * and {@link #getCurrentJobs(String, Map)}
+     * This is actually a convenience method and collects the results from {@link #getScheduledJobs(String,
Map...)}
+     * and {@link #getCurrentJobs(String, Map...)}
      * @param topic Topic can be used as a filter, if it is non-null, only jobs with this
topic will be returned.
-     * @param filterProps An optional map of filter props that act like a template.
+     * @param filterProps A list of filter property maps. Each map acts like a template.
The searched job
+     *                    must match the template (AND query). By providing several maps,
different filters
+     *                    are possible (OR query).
      * @return A non null collection.
      */
-    Collection<Event> getAllJobs(String topic, Map<String, Object> filterProps);
+    Collection<Event> getAllJobs(String topic, Map<String, Object>... filterProps);
 
     /**
      * Cancel this job.

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=690164&r1=690163&r2=690164&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
Fri Aug 29 02:46:56 2008
@@ -193,7 +193,7 @@
      * @see java.lang.Runnable#run()
      */
     public void run() {
-        if ( this.cleanupPeriod > 0 ) {
+        if ( this.cleanupPeriod > 0 && this.running ) {
             this.logger.debug("Cleaning up repository, removing all finished jobs older than
{} minutes.", this.cleanupPeriod);
 
             final String queryString = this.getCleanUpQueryString();
@@ -333,7 +333,9 @@
             this.ignoreException(e);
         }
         // load unprocessed jobs from repository
-        this.loadJobs();
+        if ( this.running ) {
+            this.loadJobs();
+        }
         while ( this.running ) {
             // so let's wait/get the next job from the queue
             EventInfo info = null;
@@ -1118,8 +1120,8 @@
      * @throws RepositoryException
      */
     private Collection<Event> queryJobs(final String topic,
-                                        final Map<String, Object> filterProps,
-                                        final Boolean locked)  {
+                                        final Boolean locked,
+                                        final Map<String, Object>... filterProps) 
{
         // we create a new session
         Session s = null;
         final List<Event> jobs = new ArrayList<Event>();
@@ -1144,24 +1146,41 @@
                     buffer.append(" and not(@jcr:lockOwner)");
                 }
             }
-            if ( filterProps != null ) {
-                final Iterator<Map.Entry<String, Object>> i = filterProps.entrySet().iterator();
-                while ( i.hasNext() ) {
-                    final Map.Entry<String, Object> current = i.next();
-                    // check prop name first
-                    final String propName = EventUtil.getNodePropertyName(current.getKey());
-                    if ( propName != null ) {
-                        // check value
-                        final Value value = EventUtil.getNodePropertyValue(s.getValueFactory(),
current.getValue());
-                        if ( value != null ) {
-                            buffer.append(" and @");
-                            buffer.append(propName);
-                            buffer.append(" = '");
-                            buffer.append(current.getValue());
-                            buffer.append("'");
+            if ( filterProps != null && filterProps.length > 0 ) {
+                buffer.append(" and (");
+                int index = 0;
+                for (Map<String,Object> template : filterProps) {
+                    if ( index > 0 ) {
+                        buffer.append(" or ");
+                    }
+                    buffer.append('(');
+                    final Iterator<Map.Entry<String, Object>> i = template.entrySet().iterator();
+                    boolean first = true;
+                    while ( i.hasNext() ) {
+                        final Map.Entry<String, Object> current = i.next();
+                        // check prop name first
+                        final String propName = EventUtil.getNodePropertyName(current.getKey());
+                        if ( propName != null ) {
+                            // check value
+                            final Value value = EventUtil.getNodePropertyValue(s.getValueFactory(),
current.getValue());
+                            if ( value != null ) {
+                                if ( first ) {
+                                    first = false;
+                                    buffer.append('@');
+                                } else {
+                                    buffer.append(" and @");
+                                }
+                                buffer.append(propName);
+                                buffer.append(" = '");
+                                buffer.append(current.getValue());
+                                buffer.append("'");
+                            }
                         }
                     }
+                    buffer.append(')');
+                    index++;
                 }
+                buffer.append(')');
             }
             buffer.append("]");
             final String queryString = buffer.toString();
@@ -1194,7 +1213,7 @@
      * @see org.apache.sling.event.JobStatusProvider#getCurrentJobs(java.lang.String)
      */
     public Collection<Event> getCurrentJobs(String topic) {
-        return this.getCurrentJobs(topic, null);
+        return this.getCurrentJobs(topic, (Map<String, Object>[])null);
     }
 
     /**
@@ -1208,29 +1227,29 @@
      * @see org.apache.sling.event.JobStatusProvider#getScheduledJobs(java.lang.String)
      */
     public Collection<Event> getScheduledJobs(String topic) {
-        return this.getScheduledJobs(topic, null);
+        return this.getScheduledJobs(topic, (Map<String, Object>[])null);
     }
 
     /**
-     * @see org.apache.sling.event.JobStatusProvider#getCurrentJobs(java.lang.String, java.util.Map)
+     * @see org.apache.sling.event.JobStatusProvider#getCurrentJobs(java.lang.String, java.util.Map...)
      */
-    public Collection<Event> getCurrentJobs(String topic, Map<String, Object>
filterProps) {
-        return this.queryJobs(topic, filterProps, true);
+    public Collection<Event> getCurrentJobs(String topic, Map<String, Object>...
filterProps) {
+        return this.queryJobs(topic, true, filterProps);
     }
 
     /**
-     * @see org.apache.sling.event.JobStatusProvider#getScheduledJobs(java.lang.String, java.util.Map)
+     * @see org.apache.sling.event.JobStatusProvider#getScheduledJobs(java.lang.String, java.util.Map...)
      */
-    public Collection<Event> getScheduledJobs(String topic, Map<String, Object>
filterProps) {
-        return this.queryJobs(topic, filterProps, false);
+    public Collection<Event> getScheduledJobs(String topic, Map<String, Object>...
filterProps) {
+        return this.queryJobs(topic, false, filterProps);
     }
 
 
     /**
-     * @see org.apache.sling.event.JobStatusProvider#getAllJobs(java.lang.String, java.util.Map)
+     * @see org.apache.sling.event.JobStatusProvider#getAllJobs(java.lang.String, java.util.Map...)
      */
-    public Collection<Event> getAllJobs(String topic, Map<String, Object> filterProps)
{
-        return this.queryJobs(topic, filterProps, null);
+    public Collection<Event> getAllJobs(String topic, Map<String, Object>...
filterProps) {
+        return this.queryJobs(topic, null, filterProps);
     }
 
 



Mime
View raw message