Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
a6569a29
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,发现更多精彩内容 >>
提交
a6569a29
编写于
10月 13, 2010
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
moved async aspect to aspectj sub-package
上级
d9d7fb6f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
130 addition
and
35 deletion
+130
-35
org.springframework.aspects/src/main/java/org/springframework/scheduling/aspectj/AbstractAsynchronousExecutionAspect.aj
...scheduling/aspectj/AbstractAsynchronousExecutionAspect.aj
+76
-0
org.springframework.aspects/src/main/java/org/springframework/scheduling/aspectj/AnnotationDrivenAsynchronousExecutionAspect.aj
...ng/aspectj/AnnotationDrivenAsynchronousExecutionAspect.aj
+54
-35
未找到文件。
org.springframework.aspects/src/main/java/org/springframework/scheduling/AbstractAsynchronousExecutionAspect.aj
→
org.springframework.aspects/src/main/java/org/springframework/scheduling/
aspectj/
AbstractAsynchronousExecutionAspect.aj
浏览文件 @
a6569a29
package
org
.
springframework
.
scheduling
;
import
java
.
util
.
concurrent
.
Callable
;
import
java
.
util
.
concurrent
.
Executor
;
import
java
.
util
.
concurrent
.
Future
;
import
org
.
aspectj
.
lang
.
reflect
.
MethodSignature
;
import
org
.
springframework
.
core
.
task
.
AsyncTaskExecutor
;
import
org
.
springframework
.
core
.
task
.
SimpleAsyncTaskExecutor
;
import
org
.
springframework
.
core
.
task
.
support
.
TaskExecutorAdapter
;
/**
*
Abstract
aspect
that
routes
selected
methods
asynchronously
.
*
<
p
>
*
This
aspect
,
by
default
,
uses
{@
link
SimpleAsyncTaskExecutor
}
to
route
method
*
execution
.
However
,
you
may
inject
it
with
any
implementation
of
*
{@
link
Executor
}
to
override
the
default
.
*
*
@
author
Ramnivas
Laddad
*/
public
abstract
aspect
AbstractAsynchronousExecutionAspect
{
private
AsyncTaskExecutor
asyncExecutor
;
public
AbstractAsynchronousExecutionAspect
()
{
//
Set
default
executor
,
which
may
be
replaced
by
calling
setExecutor
(
Executor
)
setExecutor
(
new
SimpleAsyncTaskExecutor
());
}
public
abstract
pointcut
asyncMethod
();
Object
around
()
:
asyncMethod
()
{
Callable
<
Object
>
callable
=
new
Callable
<
Object
>()
{
public
Object
call
()
throws
Exception
{
Object
result
=
proceed
();
if
(
result
instanceof
Future
)
{
return
((
Future
<?>)
result
).
get
();
}
return
null
;
}};
Future
<?>
result
=
asyncExecutor
.
submit
(
callable
);
if
(
Future
.
class
.
isAssignableFrom
(((
MethodSignature
)
thisJoinPointStaticPart
.
getSignature
()).
getReturnType
()))
{
return
result
;
}
else
{
return
null
;
}
}
public
void
setExecutor
(
Executor
executor
)
{
if
(
executor
instanceof
AsyncTaskExecutor
)
{
this
.
asyncExecutor
=
(
AsyncTaskExecutor
)
executor
;
}
else
{
this
.
asyncExecutor
=
new
TaskExecutorAdapter
(
asyncExecutor
);
}
}
}
/*
*
Copyright
2002
-
2010
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
.
*/
package
org
.
springframework
.
scheduling
.
aspectj
;
import
java
.
util
.
concurrent
.
Callable
;
import
java
.
util
.
concurrent
.
Executor
;
import
java
.
util
.
concurrent
.
Future
;
import
org
.
aspectj
.
lang
.
reflect
.
MethodSignature
;
import
org
.
springframework
.
core
.
task
.
AsyncTaskExecutor
;
import
org
.
springframework
.
core
.
task
.
SimpleAsyncTaskExecutor
;
import
org
.
springframework
.
core
.
task
.
support
.
TaskExecutorAdapter
;
/**
*
Abstract
aspect
that
routes
selected
methods
asynchronously
.
*
*
<
p
>
This
aspect
,
by
default
,
uses
{@
link
SimpleAsyncTaskExecutor
}
to
route
*
method
execution
.
However
,
you
may
inject
it
with
any
implementation
of
*
{@
link
Executor
}
to
override
the
default
.
*
*
@
author
Ramnivas
Laddad
*
@
since
3.0.5
*/
public
abstract
aspect
AbstractAsynchronousExecutionAspect
{
private
AsyncTaskExecutor
asyncExecutor
;
public
AbstractAsynchronousExecutionAspect
()
{
//
Set
default
executor
,
which
may
be
replaced
by
calling
setExecutor
.
setExecutor
(
new
SimpleAsyncTaskExecutor
());
}
public
void
setExecutor
(
Executor
executor
)
{
if
(
executor
instanceof
AsyncTaskExecutor
)
{
this
.
asyncExecutor
=
(
AsyncTaskExecutor
)
executor
;
}
else
{
this
.
asyncExecutor
=
new
TaskExecutorAdapter
(
asyncExecutor
);
}
}
Object
around
()
:
asyncMethod
()
{
Callable
<
Object
>
callable
=
new
Callable
<
Object
>()
{
public
Object
call
()
throws
Exception
{
Object
result
=
proceed
();
if
(
result
instanceof
Future
)
{
return
((
Future
<?>)
result
).
get
();
}
return
null
;
}};
Future
<?>
result
=
asyncExecutor
.
submit
(
callable
);
if
(
Future
.
class
.
isAssignableFrom
(((
MethodSignature
)
thisJoinPointStaticPart
.
getSignature
()).
getReturnType
()))
{
return
result
;
}
else
{
return
null
;
}
}
public
abstract
pointcut
asyncMethod
();
}
org.springframework.aspects/src/main/java/org/springframework/scheduling/AnnotationDrivenAsynchronousExecutionAspect.aj
→
org.springframework.aspects/src/main/java/org/springframework/scheduling/
aspectj/
AnnotationDrivenAsynchronousExecutionAspect.aj
浏览文件 @
a6569a29
package
org
.
springframework
.
scheduling
;
import
java
.
util
.
concurrent
.
Future
;
import
org
.
springframework
.
scheduling
.
annotation
.
Async
;
/**
*
Aspect
to
route
methods
based
on
the
{@
link
Async
}
annotation
.
*
<
p
>
*
This
aspect
routes
methods
marked
with
the
{@
link
Async
}
annotation
*
as
well
as
methods
in
classes
marked
with
the
same
.
Any
method
expected
*
to
be
routed
asynchronously
must
return
either
void
,
{@
link
Future
},
*
or
a
subtype
of
{@
link
Future
}.
This
aspect
,
therefore
,
will
produce
*
a
compile
-
time
error
for
methods
that
violate
this
constraint
on
the
return
type
.
*
If
,
however
,
a
class
marked
with
<
code
>&#
64
;
Async
</
code
>
contains
a
method
that
*
violates
this
constraint
,
it
produces
only
a
warning
.
*
*
@
author
Ramnivas
Laddad
*
*/
public
aspect
AnnotationDrivenAsynchronousExecutionAspect
extends
AbstractAsynchronousExecutionAspect
{
private
pointcut
asyncMarkedMethod
()
:
execution
(@
Async
(
void
||
Future
+)
*(..));
private
pointcut
asyncTypeMarkedMethod
()
:
execution
((
void
||
Future
+)
(@
Async
*).*(..));
public
pointcut
asyncMethod
()
:
asyncMarkedMethod
()
||
asyncTypeMarkedMethod
();
declare
error
:
execution
(@
Async
!(void||Future) *(..)):
"Only method that return void or Future may have @Async annotation"
;
declare
warning
:
execution
(
!(void||Future) (@Async *).*(..)):
"Method in class marked with @Async that do not return void or Future will be routed synchronously"
;
}
/*
*
Copyright
2002
-
2010
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
.
*/
package
org
.
springframework
.
scheduling
.
aspectj
;
import
java
.
util
.
concurrent
.
Future
;
import
org
.
springframework
.
scheduling
.
annotation
.
Async
;
/**
*
Aspect
to
route
methods
based
on
the
{@
link
Async
}
annotation
.
*
*
<
p
>
This
aspect
routes
methods
marked
with
the
{@
link
Async
}
annotation
*
as
well
as
methods
in
classes
marked
with
the
same
.
Any
method
expected
*
to
be
routed
asynchronously
must
return
either
void
,
{@
link
Future
},
*
or
a
subtype
of
{@
link
Future
}.
This
aspect
,
therefore
,
will
produce
*
a
compile
-
time
error
for
methods
that
violate
this
constraint
on
the
return
type
.
*
If
,
however
,
a
class
marked
with
<
code
>&#
64
;
Async
</
code
>
contains
a
method
that
*
violates
this
constraint
,
it
produces
only
a
warning
.
*
*
@
author
Ramnivas
Laddad
*
@
since
3.0.5
*/
public
aspect
AnnotationDrivenAsynchronousExecutionAspect
extends
AbstractAsynchronousExecutionAspect
{
private
pointcut
asyncMarkedMethod
()
:
execution
(@
Async
(
void
||
Future
+)
*(..));
private
pointcut
asyncTypeMarkedMethod
()
:
execution
((
void
||
Future
+)
(@
Async
*).*(..));
public
pointcut
asyncMethod
()
:
asyncMarkedMethod
()
||
asyncTypeMarkedMethod
();
declare
error
:
execution
(@
Async
!(void||Future) *(..)):
"Only methods that return void or Future may have an @Async annotation"
;
declare
warning
:
execution
(
!(void||Future) (@Async *).*(..)):
"Methods in a class marked with @Async that do not return void or Future will be routed synchronously"
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录