Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datax-cloud
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄营
datax-cloud
Commits
242d5784
Commit
242d5784
authored
Oct 30, 2019
by
yuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目初始化
parent
9089acb9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
0 deletions
+69
-0
LogAspect.java
...-log/src/main/java/cn/datax/common/log/aop/LogAspect.java
+8
-0
AsyncTask.java
...og/src/main/java/cn/datax/common/log/async/AsyncTask.java
+26
-0
AutoConfiguration.java
...in/java/cn/datax/common/log/config/AutoConfiguration.java
+2
-0
LogAsyncConfig.java
.../main/java/cn/datax/common/log/config/LogAsyncConfig.java
+33
-0
No files found.
datax-common/datax-common-log/src/main/java/cn/datax/common/log/aop/LogAspect.java
View file @
242d5784
...
...
@@ -3,6 +3,7 @@ package cn.datax.common.log.aop;
import
java.lang.reflect.Method
;
import
cn.datax.common.log.annotation.LogAop
;
import
cn.datax.common.log.async.AsyncTask
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.Signature
;
import
org.aspectj.lang.annotation.AfterReturning
;
...
...
@@ -12,11 +13,15 @@ import org.aspectj.lang.annotation.Pointcut;
import
org.aspectj.lang.reflect.MethodSignature
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
@Slf4j
@Aspect
public
class
LogAspect
{
@Autowired
private
AsyncTask
asyncTask
;
// 配置织入点
@Pointcut
(
"@annotation(cn.datax.common.log.annotation.LogAop)"
)
public
void
logPointCut
()
{}
...
...
@@ -54,6 +59,9 @@ public class LogAspect {
String
className
=
joinPoint
.
getTarget
().
getClass
().
getName
();
String
methodName
=
joinPoint
.
getSignature
().
getName
();
log
.
info
(
"[类名]:{},[方法]:{},[模块]:{},[描述]:{}"
,
className
,
methodName
,
logAop
.
module
(),
logAop
.
value
());
// 异步保存数据库
asyncTask
.
doTask
();
}
catch
(
Exception
exp
)
{
log
.
error
(
"前置通知异常信息:{}"
,
exp
.
getMessage
(),
exp
);
}
...
...
datax-common/datax-common-log/src/main/java/cn/datax/common/log/async/AsyncTask.java
0 → 100644
View file @
242d5784
package
cn
.
datax
.
common
.
log
.
async
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Component
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
@Component
public
class
AsyncTask
{
@Async
(
"dataLogExecutor"
)
public
void
doTask
()
{
log
.
info
(
"开始做任务--模拟日志"
);
long
start
=
System
.
currentTimeMillis
();
try
{
Thread
.
sleep
(
1000
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
long
end
=
System
.
currentTimeMillis
();
log
.
info
(
"完成任务,耗时:"
+
(
end
-
start
)
+
"毫秒"
);
}
}
\ No newline at end of file
datax-common/datax-common-log/src/main/java/cn/datax/common/log/config/AutoConfiguration.java
View file @
242d5784
...
...
@@ -3,6 +3,7 @@ package cn.datax.common.log.config;
import
cn.datax.common.log.aop.LogAspect
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Import
;
/**
* 扫描注入bean
...
...
@@ -10,6 +11,7 @@ import org.springframework.context.annotation.ComponentScan;
* @since 2019/10/30
*/
@ComponentScan
({
"cn.datax.common.log"
})
@Import
({
LogAsyncConfig
.
class
})
public
class
AutoConfiguration
{
@Bean
...
...
datax-common/datax-common-log/src/main/java/cn/datax/common/log/config/LogAsyncConfig.java
0 → 100644
View file @
242d5784
package
cn
.
datax
.
common
.
log
.
config
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
@EnableAsync
public
class
LogAsyncConfig
{
private
static
int
corePoolSize
=
10
;
private
static
int
maxPoolSize
=
50
;
private
static
int
queueCapacity
=
100
;
@Bean
(
"dataLogExecutor"
)
public
Executor
dataLogExecutor
()
{
ThreadPoolTaskExecutor
executor
=
new
ThreadPoolTaskExecutor
();
executor
.
setCorePoolSize
(
corePoolSize
);
executor
.
setMaxPoolSize
(
maxPoolSize
);
executor
.
setQueueCapacity
(
queueCapacity
);
executor
.
setKeepAliveSeconds
(
60
);
executor
.
setThreadNamePrefix
(
"dataLogExecutor-"
);
executor
.
setWaitForTasksToCompleteOnShutdown
(
true
);
executor
.
setAwaitTerminationSeconds
(
60
);
executor
.
setRejectedExecutionHandler
(
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
executor
.
initialize
();
return
executor
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment