Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
72420c79
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
72420c79
编写于
6月 03, 2011
作者:
M
Mark Fisher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-8205 added support for a 'trigger' attribute (bean ref) on scheduled-task elements
上级
da41c9bb
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
58 addition
and
17 deletion
+58
-17
org.springframework.context/src/main/java/org/springframework/scheduling/config/ScheduledTasksBeanDefinitionParser.java
...scheduling/config/ScheduledTasksBeanDefinitionParser.java
+29
-17
org.springframework.context/src/main/resources/org/springframework/scheduling/config/spring-task-3.1.xsd
...org/springframework/scheduling/config/spring-task-3.1.xsd
+7
-0
org.springframework.context/src/test/java/org/springframework/scheduling/config/ScheduledTasksBeanDefinitionParserTests.java
...uling/config/ScheduledTasksBeanDefinitionParserTests.java
+19
-0
org.springframework.context/src/test/resources/org/springframework/scheduling/config/scheduledTasksContext.xml
...ringframework/scheduling/config/scheduledTasksContext.xml
+3
-0
未找到文件。
org.springframework.context/src/main/java/org/springframework/scheduling/config/ScheduledTasksBeanDefinitionParser.java
浏览文件 @
72420c79
/*
/*
* Copyright 2002-20
09
the original author or authors.
* Copyright 2002-20
11
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -53,6 +53,7 @@ public class ScheduledTasksBeanDefinitionParser extends AbstractSingleBeanDefini
...
@@ -53,6 +53,7 @@ public class ScheduledTasksBeanDefinitionParser extends AbstractSingleBeanDefini
ManagedMap
<
RuntimeBeanReference
,
String
>
cronTaskMap
=
new
ManagedMap
<
RuntimeBeanReference
,
String
>();
ManagedMap
<
RuntimeBeanReference
,
String
>
cronTaskMap
=
new
ManagedMap
<
RuntimeBeanReference
,
String
>();
ManagedMap
<
RuntimeBeanReference
,
String
>
fixedDelayTaskMap
=
new
ManagedMap
<
RuntimeBeanReference
,
String
>();
ManagedMap
<
RuntimeBeanReference
,
String
>
fixedDelayTaskMap
=
new
ManagedMap
<
RuntimeBeanReference
,
String
>();
ManagedMap
<
RuntimeBeanReference
,
String
>
fixedRateTaskMap
=
new
ManagedMap
<
RuntimeBeanReference
,
String
>();
ManagedMap
<
RuntimeBeanReference
,
String
>
fixedRateTaskMap
=
new
ManagedMap
<
RuntimeBeanReference
,
String
>();
ManagedMap
<
RuntimeBeanReference
,
RuntimeBeanReference
>
triggerTaskMap
=
new
ManagedMap
<
RuntimeBeanReference
,
RuntimeBeanReference
>();
NodeList
childNodes
=
element
.
getChildNodes
();
NodeList
childNodes
=
element
.
getChildNodes
();
for
(
int
i
=
0
;
i
<
childNodes
.
getLength
();
i
++)
{
for
(
int
i
=
0
;
i
<
childNodes
.
getLength
();
i
++)
{
Node
child
=
childNodes
.
item
(
i
);
Node
child
=
childNodes
.
item
(
i
);
...
@@ -72,25 +73,35 @@ public class ScheduledTasksBeanDefinitionParser extends AbstractSingleBeanDefini
...
@@ -72,25 +73,35 @@ public class ScheduledTasksBeanDefinitionParser extends AbstractSingleBeanDefini
RuntimeBeanReference
runnableBeanRef
=
new
RuntimeBeanReference
(
RuntimeBeanReference
runnableBeanRef
=
new
RuntimeBeanReference
(
createRunnableBean
(
ref
,
method
,
taskElement
,
parserContext
));
createRunnableBean
(
ref
,
method
,
taskElement
,
parserContext
));
String
cronAttribute
=
taskElement
.
getAttribute
(
"cron"
);
String
cronAttribute
=
taskElement
.
getAttribute
(
"cron"
);
if
(
StringUtils
.
hasText
(
cronAttribute
))
{
cronTaskMap
.
put
(
runnableBeanRef
,
cronAttribute
);
}
else
{
String
fixedDelayAttribute
=
taskElement
.
getAttribute
(
"fixed-delay"
);
String
fixedDelayAttribute
=
taskElement
.
getAttribute
(
"fixed-delay"
);
if
(
StringUtils
.
hasText
(
fixedDelayAttribute
))
{
fixedDelayTaskMap
.
put
(
runnableBeanRef
,
fixedDelayAttribute
);
}
else
{
String
fixedRateAttribute
=
taskElement
.
getAttribute
(
"fixed-rate"
);
String
fixedRateAttribute
=
taskElement
.
getAttribute
(
"fixed-rate"
);
if
(!
StringUtils
.
hasText
(
fixedRateAttribute
))
{
String
triggerAttribute
=
taskElement
.
getAttribute
(
"trigger"
);
boolean
hasCronAttribute
=
StringUtils
.
hasText
(
cronAttribute
);
boolean
hasFixedDelayAttribute
=
StringUtils
.
hasText
(
fixedDelayAttribute
);
boolean
hasFixedRateAttribute
=
StringUtils
.
hasText
(
fixedRateAttribute
);
boolean
hasTriggerAttribute
=
StringUtils
.
hasText
(
triggerAttribute
);
if
(!(
hasCronAttribute
|
hasFixedDelayAttribute
|
hasFixedRateAttribute
|
hasTriggerAttribute
))
{
parserContext
.
getReaderContext
().
error
(
parserContext
.
getReaderContext
().
error
(
"One of 'cron', 'fixed-delay', or 'fixed-rate'
is required"
,
taskElement
);
"exactly one of the 'cron', 'fixed-delay', 'fixed-rate', or 'trigger' attributes
is required"
,
taskElement
);
// Continue with the possible next task element
// Continue with the possible next task element
continue
;
continue
;
}
}
if
(
hasCronAttribute
)
{
cronTaskMap
.
put
(
runnableBeanRef
,
cronAttribute
);
}
if
(
hasFixedDelayAttribute
)
{
fixedDelayTaskMap
.
put
(
runnableBeanRef
,
fixedDelayAttribute
);
}
if
(
hasFixedRateAttribute
)
{
fixedRateTaskMap
.
put
(
runnableBeanRef
,
fixedRateAttribute
);
fixedRateTaskMap
.
put
(
runnableBeanRef
,
fixedRateAttribute
);
}
}
if
(
hasTriggerAttribute
)
{
triggerTaskMap
.
put
(
runnableBeanRef
,
new
RuntimeBeanReference
(
triggerAttribute
));
}
}
}
}
String
schedulerRef
=
element
.
getAttribute
(
"scheduler"
);
String
schedulerRef
=
element
.
getAttribute
(
"scheduler"
);
...
@@ -100,6 +111,7 @@ public class ScheduledTasksBeanDefinitionParser extends AbstractSingleBeanDefini
...
@@ -100,6 +111,7 @@ public class ScheduledTasksBeanDefinitionParser extends AbstractSingleBeanDefini
builder
.
addPropertyValue
(
"cronTasks"
,
cronTaskMap
);
builder
.
addPropertyValue
(
"cronTasks"
,
cronTaskMap
);
builder
.
addPropertyValue
(
"fixedDelayTasks"
,
fixedDelayTaskMap
);
builder
.
addPropertyValue
(
"fixedDelayTasks"
,
fixedDelayTaskMap
);
builder
.
addPropertyValue
(
"fixedRateTasks"
,
fixedRateTaskMap
);
builder
.
addPropertyValue
(
"fixedRateTasks"
,
fixedRateTaskMap
);
builder
.
addPropertyValue
(
"triggerTasks"
,
triggerTaskMap
);
}
}
private
boolean
isScheduledElement
(
Node
node
,
ParserContext
parserContext
)
{
private
boolean
isScheduledElement
(
Node
node
,
ParserContext
parserContext
)
{
...
...
org.springframework.context/src/main/resources/org/springframework/scheduling/config/spring-task-3.1.xsd
浏览文件 @
72420c79
...
@@ -216,6 +216,13 @@
...
@@ -216,6 +216,13 @@
]]>
</xsd:documentation>
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:annotation>
</xsd:attribute>
</xsd:attribute>
<xsd:attribute
name=
"trigger"
type=
"xsd:string"
use=
"optional"
>
<xsd:annotation>
<xsd:documentation>
<![CDATA[
A reference to a bean that implements the Trigger interface.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute
name=
"ref"
type=
"xsd:string"
use=
"required"
>
<xsd:attribute
name=
"ref"
type=
"xsd:string"
use=
"required"
>
<xsd:annotation>
<xsd:annotation>
<xsd:documentation>
<![CDATA[
<xsd:documentation>
<![CDATA[
...
...
org.springframework.context/src/test/java/org/springframework/scheduling/config/ScheduledTasksBeanDefinitionParserTests.java
浏览文件 @
72420c79
...
@@ -18,6 +18,7 @@ package org.springframework.scheduling.config;
...
@@ -18,6 +18,7 @@ package org.springframework.scheduling.config;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.Map
;
import
java.util.Map
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.*;
...
@@ -27,6 +28,8 @@ import org.junit.Test;
...
@@ -27,6 +28,8 @@ import org.junit.Test;
import
org.springframework.beans.DirectFieldAccessor
;
import
org.springframework.beans.DirectFieldAccessor
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
org.springframework.scheduling.Trigger
;
import
org.springframework.scheduling.TriggerContext
;
import
org.springframework.scheduling.support.ScheduledMethodRunnable
;
import
org.springframework.scheduling.support.ScheduledMethodRunnable
;
/**
/**
...
@@ -98,12 +101,28 @@ public class ScheduledTasksBeanDefinitionParserTests {
...
@@ -98,12 +101,28 @@ public class ScheduledTasksBeanDefinitionParserTests {
assertEquals
(
"*/4 * 9-17 * * MON-FRI"
,
expression
);
assertEquals
(
"*/4 * 9-17 * * MON-FRI"
,
expression
);
}
}
@Test
public
void
triggerTasks
()
{
Map
<
Runnable
,
Trigger
>
tasks
=
(
Map
<
Runnable
,
Trigger
>)
new
DirectFieldAccessor
(
this
.
registrar
).
getPropertyValue
(
"triggerTasks"
);
assertEquals
(
1
,
tasks
.
size
());
Trigger
trigger
=
tasks
.
values
().
iterator
().
next
();
assertEquals
(
TestTrigger
.
class
,
trigger
.
getClass
());
}
static
class
TestBean
{
static
class
TestBean
{
public
void
test
()
{
public
void
test
()
{
}
}
}
static
class
TestTrigger
implements
Trigger
{
public
Date
nextExecutionTime
(
TriggerContext
triggerContext
)
{
return
null
;
}
}
}
}
}
org.springframework.context/src/test/resources/org/springframework/scheduling/config/scheduledTasksContext.xml
浏览文件 @
72420c79
...
@@ -12,10 +12,13 @@
...
@@ -12,10 +12,13 @@
<task:scheduled
ref=
"testBean"
method=
"test"
fixed-rate=
"2000"
/>
<task:scheduled
ref=
"testBean"
method=
"test"
fixed-rate=
"2000"
/>
<task:scheduled
ref=
"testBean"
method=
"test"
fixed-delay=
"3000"
/>
<task:scheduled
ref=
"testBean"
method=
"test"
fixed-delay=
"3000"
/>
<task:scheduled
ref=
"testBean"
method=
"test"
cron=
"*/4 * 9-17 * * MON-FRI"
/>
<task:scheduled
ref=
"testBean"
method=
"test"
cron=
"*/4 * 9-17 * * MON-FRI"
/>
<task:scheduled
ref=
"testBean"
method=
"test"
trigger=
"customTrigger"
/>
</task:scheduled-tasks>
</task:scheduled-tasks>
<task:scheduler
id=
"testScheduler"
/>
<task:scheduler
id=
"testScheduler"
/>
<bean
id=
"testBean"
class=
"org.springframework.scheduling.config.ScheduledTasksBeanDefinitionParserTests$TestBean"
/>
<bean
id=
"testBean"
class=
"org.springframework.scheduling.config.ScheduledTasksBeanDefinitionParserTests$TestBean"
/>
<bean
id=
"customTrigger"
class=
"org.springframework.scheduling.config.ScheduledTasksBeanDefinitionParserTests$TestTrigger"
/>
</beans>
</beans>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录