Syncing with Java Spring integration, polishing
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
using Spring.Objects.Support;
|
||||
|
||||
namespace Spring.Scheduling.Quartz
|
||||
{
|
||||
/// <summary>
|
||||
/// Exception that wraps an exception thrown from a target method.
|
||||
/// Propagated to the Quartz scheduler from a Job that reflectively invokes
|
||||
/// an arbitrary target method.
|
||||
/// </summary>
|
||||
/// <author>Juergen Hoeller</author>
|
||||
/// <seealso cref="MethodInvokingJobDetailFactoryObject" />
|
||||
public class JobMethodInvocationFailedException : Exception // TODO, in Java NestedRuntimeException
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for JobMethodInvocationFailedException.
|
||||
/// </summary>
|
||||
/// <param name="methodInvoker">the MethodInvoker used for reflective invocation</param>
|
||||
/// <param name="cause">the root cause (as thrown from the target method)</param>
|
||||
public JobMethodInvocationFailedException(MethodInvoker methodInvoker, Exception cause) :
|
||||
base("Invocation of method '" + methodInvoker.TargetMethod +
|
||||
"' on target class [" + methodInvoker.TargetType + "] failed", cause)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ namespace Spring.Scheduling.Quartz
|
||||
private string objectName;
|
||||
private readonly Constants constants = new Constants(typeof(MisfireInstruction.CronTrigger), typeof(MisfireInstruction));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Register objects in the JobDataMap via a given Map.
|
||||
/// </summary>
|
||||
@@ -80,10 +79,7 @@ namespace Spring.Scheduling.Quartz
|
||||
/// <seealso cref="MisfireInstruction.SmartPolicy" />
|
||||
public virtual string MisfireInstructionName
|
||||
{
|
||||
set
|
||||
{
|
||||
MisfireInstruction = constants.AsNumber(value);
|
||||
}
|
||||
set { MisfireInstruction = constants.AsNumber(value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -18,6 +18,8 @@ using System.Threading;
|
||||
|
||||
using Quartz;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Scheduling.Quartz
|
||||
{
|
||||
/// <summary>
|
||||
@@ -35,7 +37,7 @@ namespace Spring.Scheduling.Quartz
|
||||
/// <seealso cref="IJob.Execute(JobExecutionContext)" />
|
||||
public class DelegatingJob : IJob
|
||||
{
|
||||
private ThreadStart delegateInstance;
|
||||
private readonly ThreadStart delegateInstance;
|
||||
|
||||
/// <summary>
|
||||
/// Return the wrapped Runnable implementation.
|
||||
@@ -54,29 +56,17 @@ namespace Spring.Scheduling.Quartz
|
||||
/// </param>
|
||||
public DelegatingJob(ThreadStart delegateInstance)
|
||||
{
|
||||
if (delegateInstance == null)
|
||||
{
|
||||
throw new ArgumentException("Delegate must not be null", "delegateInstance");
|
||||
}
|
||||
AssertUtils.ArgumentNotNull(delegateInstance, "delegateInstance", "Delegate must not be null");
|
||||
this.delegateInstance = delegateInstance;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delegates execution to the underlying ThreadStart,
|
||||
/// converting any Exception thrown to a Quartz JobExecutionException
|
||||
/// (as required by the Job contract).
|
||||
/// Delegates execution to the underlying ThreadStart.
|
||||
/// </summary>
|
||||
public virtual void Execute(JobExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
delegateInstance.Invoke();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new JobExecutionException(ex);
|
||||
}
|
||||
delegateInstance.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,18 +70,19 @@ namespace Spring.Scheduling.Quartz
|
||||
}
|
||||
catch (TargetInvocationException ex)
|
||||
{
|
||||
logger.Warn(errorMessage, ex.GetBaseException());
|
||||
logger.Error(errorMessage, ex.GetBaseException());
|
||||
if (ex.GetBaseException() is JobExecutionException)
|
||||
{
|
||||
// -> JobExecutionException, to be logged at info level by Quartz
|
||||
throw ex.GetBaseException();
|
||||
}
|
||||
throw new JobExecutionException(errorMessage, ex.GetBaseException());
|
||||
|
||||
// -> "unhandled exception", to be logged at error level by Quartz
|
||||
throw new JobMethodInvocationFailedException(methodInvoker, ex.GetBaseException());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Warn(errorMessage, ex);
|
||||
throw new JobExecutionException(errorMessage, ex);
|
||||
// -> "unhandled exception", to be logged at error level by Quartz
|
||||
throw new JobMethodInvocationFailedException(methodInvoker, ex.GetBaseException());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
using Common.Logging;
|
||||
|
||||
@@ -104,20 +103,21 @@ namespace Spring.Scheduling.Quartz
|
||||
private ITriggerListener[] globalTriggerListeners;
|
||||
private ArrayList jobDetails;
|
||||
private IJobFactory jobFactory;
|
||||
private bool jobFactorySet;
|
||||
private IJobListener[] jobListeners;
|
||||
private string[] jobSchedulingDataLocations;
|
||||
private bool overwriteExistingJobs = false;
|
||||
private bool overwriteExistingJobs;
|
||||
private NameValueCollection quartzProperties;
|
||||
private IScheduler scheduler;
|
||||
private IDictionary schedulerContextMap;
|
||||
private Type schedulerFactoryType;
|
||||
private ISchedulerListener[] schedulerListeners;
|
||||
private string schedulerName;
|
||||
private int startupDelay = 0;
|
||||
private int startupDelay;
|
||||
private ITaskExecutor taskExecutor;
|
||||
private ITriggerListener[] triggerListeners;
|
||||
private ArrayList triggers;
|
||||
private bool waitForJobsToCompleteOnShutdown = false;
|
||||
private bool waitForJobsToCompleteOnShutdown;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SchedulerFactoryObject"/> class.
|
||||
@@ -126,7 +126,6 @@ namespace Spring.Scheduling.Quartz
|
||||
{
|
||||
logger = LogManager.GetLogger(GetType());
|
||||
schedulerFactoryType = typeof (StdSchedulerFactory);
|
||||
jobFactory = new AdaptableJobFactory();
|
||||
}
|
||||
|
||||
|
||||
@@ -265,20 +264,25 @@ namespace Spring.Scheduling.Quartz
|
||||
/// <remarks>
|
||||
/// <p>
|
||||
/// Default is Spring's <see cref="AdaptableJobFactory" />, which supports
|
||||
/// standard Quartz <see cref="IJob" /> instances.
|
||||
/// standard Quartz <see cref="IJob" /> instances. Note that this default only applies
|
||||
/// to a <i>local</i> Scheduler, not to a RemoteScheduler (where setting
|
||||
/// a custom JobFactory is not supported by Quartz).
|
||||
/// </p>
|
||||
/// <p>
|
||||
/// Specify an instance of Spring's <see cref="SpringObjectJobFactory" /> here
|
||||
/// (typically as an inner object definition) to automatically populate a
|
||||
/// job's object properties from the specified job data map and scheduler
|
||||
/// context.
|
||||
/// (typically as an inner object definition) to automatically populate a job's
|
||||
/// object properties from the specified job data map and scheduler context.
|
||||
/// </p>
|
||||
/// </remarks>
|
||||
/// <seealso cref="AdaptableJobFactory" />
|
||||
/// <seealso cref="SpringObjectJobFactory" />
|
||||
public virtual IJobFactory JobFactory
|
||||
{
|
||||
set { jobFactory = value; }
|
||||
set
|
||||
{
|
||||
jobFactory = value;
|
||||
jobFactorySet = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -636,6 +640,15 @@ namespace Spring.Scheduling.Quartz
|
||||
|
||||
// Get Scheduler instance from SchedulerFactory.
|
||||
scheduler = CreateScheduler(schedulerFactory, schedulerName);
|
||||
PopulateSchedulerContext();
|
||||
|
||||
if (!jobFactorySet && !(scheduler is RemoteScheduler))
|
||||
{
|
||||
// Use AdaptableJobFactory as default for a local Scheduler, unless when
|
||||
// explicitly given a null value through the "jobFactory" bean property.
|
||||
jobFactory = new AdaptableJobFactory();
|
||||
}
|
||||
|
||||
if (jobFactory != null)
|
||||
{
|
||||
if (jobFactory is ISchedulerContextAware)
|
||||
@@ -645,8 +658,6 @@ namespace Spring.Scheduling.Quartz
|
||||
scheduler.JobFactory = jobFactory;
|
||||
}
|
||||
|
||||
|
||||
PopulateSchedulerContext();
|
||||
RegisterListeners();
|
||||
RegisterJobsAndTriggers();
|
||||
|
||||
@@ -911,10 +922,7 @@ namespace Spring.Scheduling.Quartz
|
||||
scheduler.AddJob(jobDetail, true);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -969,10 +977,7 @@ namespace Spring.Scheduling.Quartz
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -133,6 +133,11 @@
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Scheduling\Quartz\JobMethodInvocationFailedException.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Scheduling\Quartz\LocalTaskExecutorThreadPool.cs"
|
||||
SubType = "Code"
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="JobMethodInvocationFailedException.cs" />
|
||||
<Compile Include="Scheduling\Quartz\AdaptableJobFactory.cs" />
|
||||
<Compile Include="Scheduling\Quartz\CronTriggerObject.cs" />
|
||||
<Compile Include="Scheduling\Quartz\DelegatingJob.cs" />
|
||||
|
||||
@@ -198,16 +198,13 @@ namespace Spring.Scheduling.Quartz
|
||||
// set expectations
|
||||
TestSchedulerFactory.MockScheduler.JobFactory = null;
|
||||
LastCall.IgnoreArguments();
|
||||
Expect.Call(TestSchedulerFactory.MockScheduler.SchedulerName).Return("schedName");
|
||||
TestSchedulerFactory.MockScheduler.Start();
|
||||
TestSchedulerFactory.MockScheduler.StartDelayed(2);
|
||||
TestSchedulerFactory.Mockery.ReplayAll();
|
||||
|
||||
factory.SchedulerFactoryType = typeof(TestSchedulerFactory);
|
||||
factory.AutoStartup = true;
|
||||
factory.StartupDelay = 2;
|
||||
factory.AfterPropertiesSet();
|
||||
Thread.Sleep(TimeSpan.FromSeconds(3));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user