This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-event.git
commit e09069c079193d9a4e786953c5c64a9563214305 Author: Carsten Ziegeler <cziege...@apache.org> AuthorDate: Thu May 4 09:07:53 2017 +0000 SLING-6823 : Use Timer instead of scheduler for delayed execution git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1793757 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 8 ----- .../impl/jobs/config/JobManagerConfiguration.java | 34 ++++++++++------------ .../sling/event/impl/jobs/queues/JobQueueImpl.java | 17 +++++++---- .../sling/event/impl/jobs/queues/QueueManager.java | 4 --- .../event/impl/jobs/queues/QueueServices.java | 3 -- .../impl/jobs/scheduling/JobSchedulerImpl.java | 10 +++---- 6 files changed, 31 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index 3f81be8..eab232e 100644 --- a/pom.xml +++ b/pom.xml @@ -82,16 +82,8 @@ org.apache.sling.commons.osgi;inline="org/apache/sling/commons/osgi/PropertiesUtil.*", quartz;inline="org/quartz/CronExpression.*|org/quartz/ValueSet.*" </Embed-Dependency> - <_plugin>org.apache.felix.scrplugin.bnd.SCRDescriptorBndPlugin;destdir=${project.build.outputDirectory};</_plugin> </instructions> </configuration> - <dependencies> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.bnd</artifactId> - <version>1.7.2</version> - </dependency> - </dependencies> </plugin> <plugin> <groupId>org.apache.rat</groupId> diff --git a/src/main/java/org/apache/sling/event/impl/jobs/config/JobManagerConfiguration.java b/src/main/java/org/apache/sling/event/impl/jobs/config/JobManagerConfiguration.java index 4f75a4c..b9262fb 100644 --- a/src/main/java/org/apache/sling/event/impl/jobs/config/JobManagerConfiguration.java +++ b/src/main/java/org/apache/sling/event/impl/jobs/config/JobManagerConfiguration.java @@ -18,12 +18,13 @@ */ package org.apache.sling.event.impl.jobs.config; -import java.sql.Date; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; @@ -494,27 +495,22 @@ public class JobManagerConfiguration { } else { // and run checker again in some seconds (if leader) // notify listeners afterwards - final Scheduler local = this.scheduler; - if ( local != null ) { - final Runnable r = new Runnable() { - - @Override - public void run() { - if ( newCaps == topologyCapabilities && newCaps.isActive()) { - // start listeners - notifiyListeners(); - if ( newCaps.isLeader() && newCaps.isActive() ) { - final CheckTopologyTask mt = new CheckTopologyTask(JobManagerConfiguration.this); - mt.fullRun(); - } + final Timer timer = new Timer(); + timer.schedule(new TimerTask() + { + + @Override + public void run() { + if ( newCaps == topologyCapabilities && newCaps.isActive()) { + // start listeners + notifiyListeners(); + if ( newCaps.isLeader() && newCaps.isActive() ) { + final CheckTopologyTask mt = new CheckTopologyTask(JobManagerConfiguration.this); + mt.fullRun(); } } - }; - if ( !local.schedule(r, local.AT(new Date(System.currentTimeMillis() + this.backgroundLoadDelay * 1000))) ) { - // if for whatever reason scheduling doesn't work, let's run now - r.run(); } - } + }, this.backgroundLoadDelay * 1000); } logger.debug("Job processing started"); } diff --git a/src/main/java/org/apache/sling/event/impl/jobs/queues/JobQueueImpl.java b/src/main/java/org/apache/sling/event/impl/jobs/queues/JobQueueImpl.java index 0ab1a6b..34ff143 100644 --- a/src/main/java/org/apache/sling/event/impl/jobs/queues/JobQueueImpl.java +++ b/src/main/java/org/apache/sling/event/impl/jobs/queues/JobQueueImpl.java @@ -23,6 +23,8 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; import java.util.concurrent.Semaphore; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -80,7 +82,7 @@ public class JobQueueImpl private final QueueServices services; /** The map of events we're processing. */ - private final Map<String, JobHandler> processingJobsLists = new HashMap<String, JobHandler>(); + private final Map<String, JobHandler> processingJobsLists = new HashMap<>(); private final ThreadPool threadPool; @@ -676,7 +678,6 @@ public class JobQueueImpl this.isSleepingUntil = fireDate.getTime(); } - final String jobName = "Waiting:" + queueName + ":" + handler.hashCode(); final Runnable t = new Runnable() { @Override public void run() { @@ -695,10 +696,14 @@ public class JobQueueImpl } }; this.waitCounter.incrementAndGet(); - if ( !services.scheduler.schedule(t, services.scheduler.AT(fireDate).name(jobName)) ) { - // if scheduling fails run the thread directly - t.run(); - } + final Timer timer = new Timer(); + timer.schedule(new TimerTask() { + + @Override + public void run() { + t.run(); + } + }, delay); } else { // put directly into queue this.requeue(handler); diff --git a/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueManager.java b/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueManager.java index 7141984..2a98f8a 100644 --- a/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueManager.java +++ b/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueManager.java @@ -85,9 +85,6 @@ public class QueueManager private EventAdmin eventAdmin; @Reference - private Scheduler scheduler; - - @Reference private JobConsumerManager jobConsumerManager; @Reference @@ -135,7 +132,6 @@ public class QueueManager queueServices.configuration = this.configuration; queueServices.eventAdmin = this.eventAdmin; queueServices.jobConsumerManager = this.jobConsumerManager; - queueServices.scheduler = this.scheduler; queueServices.threadPoolManager = this.threadPoolManager; queueServices.statisticsManager = statisticsManager; queueServices.eventingThreadPool = this.threadPool; diff --git a/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueServices.java b/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueServices.java index e39235f..31beab2 100644 --- a/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueServices.java +++ b/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueServices.java @@ -18,7 +18,6 @@ */ package org.apache.sling.event.impl.jobs.queues; -import org.apache.sling.commons.scheduler.Scheduler; import org.apache.sling.commons.threads.ThreadPool; import org.apache.sling.commons.threads.ThreadPoolManager; import org.apache.sling.event.impl.jobs.JobConsumerManager; @@ -41,8 +40,6 @@ public class QueueServices { public ThreadPoolManager threadPoolManager; - public Scheduler scheduler; - public StatisticsManager statisticsManager; public ThreadPool eventingThreadPool; diff --git a/src/main/java/org/apache/sling/event/impl/jobs/scheduling/JobSchedulerImpl.java b/src/main/java/org/apache/sling/event/impl/jobs/scheduling/JobSchedulerImpl.java index b4b7612..180dabe 100644 --- a/src/main/java/org/apache/sling/event/impl/jobs/scheduling/JobSchedulerImpl.java +++ b/src/main/java/org/apache/sling/event/impl/jobs/scheduling/JobSchedulerImpl.java @@ -88,7 +88,7 @@ public class JobSchedulerImpl private final ScheduledJobHandler scheduledJobHandler; /** All scheduled jobs, by scheduler name */ - private final Map<String, ScheduledJobInfoImpl> scheduledJobs = new HashMap<String, ScheduledJobInfoImpl>(); + private final Map<String, ScheduledJobInfoImpl> scheduledJobs = new HashMap<>(); /** * Create the scheduler @@ -241,7 +241,7 @@ public class JobSchedulerImpl break; } // Create configuration for scheduled job - final Map<String, Serializable> config = new HashMap<String, Serializable>(); + final Map<String, Serializable> config = new HashMap<>(); config.put(PROPERTY_READ_JOB, info); config.put(PROPERTY_SCHEDULE_INDEX, index); this.scheduler.schedule(this, options.name(name).config(config).canRunConcurrently(false)); @@ -305,7 +305,7 @@ public class JobSchedulerImpl this.scheduledJobHandler.remove(info); } else { // update schedule list - final List<ScheduleInfo> infos = new ArrayList<ScheduleInfo>(); + final List<ScheduleInfo> infos = new ArrayList<>(); for(final ScheduleInfo i : info.getSchedules() ) { if ( i != si ) { // no need to use equals infos.add(i); @@ -424,7 +424,7 @@ public class JobSchedulerImpl public Collection<ScheduledJobInfo> getScheduledJobs(final String topic, final long limit, final Map<String, Object>... templates) { - final List<ScheduledJobInfo> jobs = new ArrayList<ScheduledJobInfo>(); + final List<ScheduledJobInfo> jobs = new ArrayList<>(); long count = 0; synchronized ( this.scheduledJobs ) { for(final ScheduledJobInfoImpl job : this.scheduledJobs.values() ) { @@ -504,7 +504,7 @@ public class JobSchedulerImpl final boolean isSuspended, final List<ScheduleInfoImpl> scheduleInfos, final List<String> errors) { - final List<String> msgs = new ArrayList<String>(); + final List<String> msgs = new ArrayList<>(); if ( scheduleName == null || scheduleName.length() == 0 ) { msgs.add("Schedule name not specified"); } -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.