incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1086626 - in /sling/trunk/bundles/extensions/event: pom.xml src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java src/main/java/org/apache/sling/event/jobs/JobManager.java
Date Tue, 29 Mar 2011 15:28:12 GMT
Author: cziegeler
Date: Tue Mar 29 15:28:12 2011
New Revision: 1086626

URL: http://svn.apache.org/viewvc?rev=1086626&view=rev
Log:
SLING-2037 : Add limit to job query

Modified:
    sling/trunk/bundles/extensions/event/pom.xml
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobManager.java

Modified: sling/trunk/bundles/extensions/event/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/pom.xml?rev=1086626&r1=1086625&r2=1086626&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/pom.xml (original)
+++ sling/trunk/bundles/extensions/event/pom.xml Tue Mar 29 15:28:12 2011
@@ -67,7 +67,7 @@
                         </Import-Package>
                         <Export-Package>
                             org.apache.sling.event;version=2.4.0,
-                            org.apache.sling.event.jobs;version=1.0.0
+                            org.apache.sling.event.jobs;version=1.1.0
                         </Export-Package>
                         <Private-Package>
                             org.apache.sling.event.impl.*

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java?rev=1086626&r1=1086625&r2=1086626&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java
Tue Mar 29 15:28:12 2011
@@ -217,7 +217,7 @@ public class DefaultJobManager
         for(final AbstractJobQueue jbq : this.queues.values() ) {
             jbq.checkForUnprocessedJobs();
         }
-        
+
         // we only do a full clean up on every fifth run
         this.schedulerRuns++;
         final boolean doFullCleanUp = (schedulerRuns % 5 == 0);
@@ -545,10 +545,11 @@ public class DefaultJobManager
         return true;
     }
 
-    private void queryCollection(
+    private boolean queryCollection(
             final List<Event> result,
             final QueryType type,
             final Collection<JobEvent> collection,
+            final long limit,
             final Map<String, Object>... filterProps) {
         synchronized ( collection ) {
             final Iterator<JobEvent> iter = collection.iterator();
@@ -566,16 +567,31 @@ public class DefaultJobManager
                 }
                 if ( add ) {
                     result.add(job.event);
+                    if ( limit > 0 && result.size() == limit ) {
+                        return true;
+                    }
                 }
             }
         }
+        return false;
     }
+
     /**
      * @see org.apache.sling.event.jobs.JobManager#queryJobs(QueryType, java.lang.String,
java.util.Map...)
      */
     public JobsIterator queryJobs(final QueryType type,
             final String topic,
             final Map<String, Object>... filterProps) {
+        return this.queryJobs(type, topic, -1, filterProps);
+    }
+
+    /**
+     * @see org.apache.sling.event.jobs.JobManager#queryJobs(QueryType, java.lang.String,
long, java.util.Map...)
+     */
+    public JobsIterator queryJobs(final QueryType type,
+            final String topic,
+            final long limit,
+            final Map<String, Object>... filterProps) {
         final List<Event> result = new ArrayList<Event>();
         if ( topic != null ) {
             final List<JobEvent> l;
@@ -583,15 +599,18 @@ public class DefaultJobManager
                 l = this.allEventsByTopic.get(topic);
             }
             if ( l != null ) {
-                queryCollection(result, type, l, filterProps);
+                queryCollection(result, type, l, limit, filterProps);
             }
         } else {
             final Set<Collection<JobEvent>> topics;
             synchronized ( this.allEventsByTopic ) {
                 topics = new HashSet<Collection<JobEvent>>(this.allEventsByTopic.values());
             }
-            for(final Collection<JobEvent> l : topics) {
-                queryCollection(result, type, l, filterProps);
+            boolean done = false;
+            final Iterator<Collection<JobEvent>> i = topics.iterator();
+            while ( !done && i.hasNext() ) {
+                final Collection<JobEvent> l = i.next();
+                done = queryCollection(result, type, l, limit, filterProps);
             }
         }
         return new JobsIteratorImpl(result);

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobManager.java?rev=1086626&r1=1086625&r2=1086626&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobManager.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobManager.java
Tue Mar 29 15:28:12 2011
@@ -75,6 +75,20 @@ public interface JobManager {
     JobsIterator queryJobs(QueryType type, String topic, Map<String, Object>... templates);
 
     /**
+     * Return all jobs either running or scheduled.
+     *
+     * @param type Required parameter for the type: either all jobs, only queued or only
started can be returned.
+     * @param topic Topic can be used as a filter, if it is non-null, only jobs with this
topic will be returned.
+     * @param limit A positive number indicating the maximum number of jobs returned by the
iterator.
+     * @param templates 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.
+     * @since 1.1
+     */
+    JobsIterator queryJobs(QueryType type, String topic, long limit, Map<String, Object>...
templates);
+
+    /**
      * Find a job - either scheduled or active.
      * This method searches for an event with the given topic and filter properties. If more
than one
      * job matches, the first one found is returned which could be any of the matching jobs.



Mime
View raw message