Author: hlship
Date: Wed Jul 13 00:02:58 2011
New Revision: 1145826
URL: http://svn.apache.org/viewvc?rev=1145826&view=rev
Log:
TAP5-1572: Add a name for each job, used with debugging/info output
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/PeriodicExecutorImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicExecutor.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicJob.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/PeriodicExecutorTests.groovy
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/PeriodicExecutorImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/PeriodicExecutorImpl.java?rev=1145826&r1=1145825&r2=1145826&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/PeriodicExecutorImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/PeriodicExecutorImpl.java
Wed Jul 13 00:02:58 2011
@@ -52,20 +52,28 @@ public class PeriodicExecutorImpl implem
private final Schedule schedule;
+ private final String name;
+
private final Runnable runnableJob;
private boolean executing, canceled;
private long nextExecution;
- public Job(Schedule schedule, Runnable runnableJob)
+ public Job(Schedule schedule, String name, Runnable runnableJob)
{
this.schedule = schedule;
+ this.name = name;
this.runnableJob = runnableJob;
nextExecution = schedule.firstExecution();
}
+ public String getName()
+ {
+ return name;
+ }
+
public synchronized long getNextExecution()
{
return nextExecution;
@@ -99,6 +107,9 @@ public class PeriodicExecutorImpl implem
{
StringBuilder builder = new
StringBuilder("PeriodicJob[#").append(jobId);
+
+ builder.append(", (").append(name).append(")");
+
if (executing)
{
builder.append(", executing");
@@ -158,9 +169,9 @@ public class PeriodicExecutorImpl implem
public Void invoke()
{
- if (logger.isDebugEnabled())
+ if (logger.isInfoEnabled())
{
- logger.debug(this + " starting execution");
+ logger.info(String.format("Executing job #%d (%s)", jobId,
name));
}
try
@@ -201,12 +212,13 @@ public class PeriodicExecutorImpl implem
}
- public synchronized PeriodicJob addJob(Schedule schedule, Runnable job)
+ public synchronized PeriodicJob addJob(Schedule schedule, String name,
Runnable job)
{
assert schedule != null;
+ assert name != null;
assert job != null;
- Job periodicJob = new Job(schedule, job);
+ Job periodicJob = new Job(schedule, name, job);
jobs.add(periodicJob);
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicExecutor.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicExecutor.java?rev=1145826&r1=1145825&r2=1145826&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicExecutor.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicExecutor.java
Wed Jul 13 00:02:58 2011
@@ -25,8 +25,8 @@ public interface PeriodicExecutor
* Adds a job to be executed. The job is executed in a thread pool (via
{@link
org.apache.tapestry5.ioc.services.ParallelExecutor#invoke(org.apache.tapestry5.ioc.Invokable)}},
as determined by the schedule.
*
* @param schedule defines when the job will next execute
- * @param job a Runnable object that represents the work to be done
- * @return a PeriodicJob that can be used to query when the job executes,
or to cancel its execution
+ * @param name a name used in debugging output related to the job
+ * @param job a Runnable object that represents the work to be done
@return a PeriodicJob that can be used to query when the job executes, or to
cancel its execution
*/
- PeriodicJob addJob(Schedule schedule, Runnable job);
+ PeriodicJob addJob(Schedule schedule, String name, Runnable job);
}
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicJob.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicJob.java?rev=1145826&r1=1145825&r2=1145826&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicJob.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicJob.java
Wed Jul 13 00:02:58 2011
@@ -20,13 +20,23 @@ package org.apache.tapestry5.ioc.service
public interface PeriodicJob
{
/**
+ * Returns the name for the job, supplied when the job is created; this is
not unique or meaningful, and
+ * primarily exists to assist with debugging.
+ *
+ * @return name provided for the job
+ */
+ String getName();
+
+ /**
* Is this Job currently executing (or queued, awaiting execution)?
*
* @return true if executing
*/
boolean isExecuting();
- /** Has this job been canceled. */
+ /**
+ * Has this job been canceled.
+ */
boolean isCanceled();
/**
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/PeriodicExecutorTests.groovy
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/PeriodicExecutorTests.groovy?rev=1145826&r1=1145825&r2=1145826&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/PeriodicExecutorTests.groovy
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/PeriodicExecutorTests.groovy
Wed Jul 13 00:02:58 2011
@@ -36,7 +36,7 @@ class PeriodicExecutorTests extends IOCT
def schedule = new IntervalSchedule(10)
- PeriodicJob job =
r.getService(PeriodicExecutor.class).addJob(schedule, { count++; })
+ PeriodicJob job =
r.getService(PeriodicExecutor.class).addJob(schedule, "count incrementer", {
count++; })
while (count < 10)
{