Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
transmittable-thread-local
提交
ca491326
T
transmittable-thread-local
项目概览
阿啄debugIT
/
transmittable-thread-local
与 Fork 源项目一致
从无法访问的项目Fork
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
transmittable-thread-local
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ca491326
编写于
9月 26, 2018
作者:
oldratlee
🔥
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add unwrap method for TtlExecutors to get the original/underneath executor #112
上级
16ffb128
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
98 addition
and
18 deletion
+98
-18
src/main/java/com/alibaba/ttl/threadpool/ExecutorServiceTtlWrapper.java
...com/alibaba/ttl/threadpool/ExecutorServiceTtlWrapper.java
+5
-0
src/main/java/com/alibaba/ttl/threadpool/ExecutorTtlWrapper.java
...n/java/com/alibaba/ttl/threadpool/ExecutorTtlWrapper.java
+4
-0
src/main/java/com/alibaba/ttl/threadpool/ScheduledExecutorServiceTtlWrapper.java
...ba/ttl/threadpool/ScheduledExecutorServiceTtlWrapper.java
+6
-4
src/main/java/com/alibaba/ttl/threadpool/TtlExecutors.java
src/main/java/com/alibaba/ttl/threadpool/TtlExecutors.java
+43
-1
src/main/java/com/alibaba/ttl/threadpool/agent/TtlAgent.java
src/main/java/com/alibaba/ttl/threadpool/agent/TtlAgent.java
+4
-1
src/main/java/com/alibaba/ttl/threadpool/agent/internal/transformlet/JavassistTransformlet.java
...ol/agent/internal/transformlet/JavassistTransformlet.java
+0
-1
src/main/java/com/alibaba/ttl/threadpool/agent/internal/transformlet/impl/TtlForkJoinTransformlet.java
...t/internal/transformlet/impl/TtlForkJoinTransformlet.java
+1
-1
src/main/java/com/alibaba/ttl/threadpool/agent/internal/transformlet/impl/Utils.java
...tl/threadpool/agent/internal/transformlet/impl/Utils.java
+1
-1
src/test/java/com/alibaba/demo/agent/AgentDemo.kt
src/test/java/com/alibaba/demo/agent/AgentDemo.kt
+0
-1
src/test/java/com/alibaba/demo/distributed_tracer/refcount/DistributedTracerUseDemo.kt
...o/distributed_tracer/refcount/DistributedTracerUseDemo.kt
+1
-1
src/test/java/com/alibaba/demo/timer/TimerTaskDemo.kt
src/test/java/com/alibaba/demo/timer/TimerTaskDemo.kt
+1
-3
src/test/java/com/alibaba/ttl/threadpool/TtlExecutorsTest.kt
src/test/java/com/alibaba/ttl/threadpool/TtlExecutorsTest.kt
+31
-2
src/test/java/com/alibaba/ttl/threadpool/agent/TtlAgentTest.kt
...est/java/com/alibaba/ttl/threadpool/agent/TtlAgentTest.kt
+1
-2
未找到文件。
src/main/java/com/alibaba/ttl/threadpool/ExecutorServiceTtlWrapper.java
浏览文件 @
ca491326
...
...
@@ -83,4 +83,9 @@ class ExecutorServiceTtlWrapper extends ExecutorTtlWrapper implements ExecutorSe
public
<
T
>
T
invokeAny
(
Collection
<?
extends
Callable
<
T
>>
tasks
,
long
timeout
,
TimeUnit
unit
)
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
return
executorService
.
invokeAny
(
TtlCallable
.
gets
(
tasks
),
timeout
,
unit
);
}
@Override
public
ExecutorService
unwrap
()
{
return
executorService
;
}
}
src/main/java/com/alibaba/ttl/threadpool/ExecutorTtlWrapper.java
浏览文件 @
ca491326
...
...
@@ -24,4 +24,8 @@ class ExecutorTtlWrapper implements Executor {
public
void
execute
(
Runnable
command
)
{
executor
.
execute
(
TtlRunnable
.
get
(
command
));
}
public
Executor
unwrap
()
{
return
executor
;
}
}
src/main/java/com/alibaba/ttl/threadpool/ScheduledExecutorServiceTtlWrapper.java
浏览文件 @
ca491326
...
...
@@ -4,10 +4,7 @@ import com.alibaba.ttl.TransmittableThreadLocal;
import
com.alibaba.ttl.TtlCallable
;
import
com.alibaba.ttl.TtlRunnable
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.ScheduledFuture
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.*
;
/**
* {@link TransmittableThreadLocal} Wrapper of {@link ScheduledExecutorService},
...
...
@@ -44,4 +41,9 @@ class ScheduledExecutorServiceTtlWrapper extends ExecutorServiceTtlWrapper imple
public
ScheduledFuture
<?>
scheduleWithFixedDelay
(
Runnable
command
,
long
initialDelay
,
long
delay
,
TimeUnit
unit
)
{
return
scheduledExecutorService
.
scheduleWithFixedDelay
(
TtlRunnable
.
get
(
command
),
initialDelay
,
delay
,
unit
);
}
@Override
public
ScheduledExecutorService
unwrap
()
{
return
scheduledExecutorService
;
}
}
src/main/java/com/alibaba/ttl/threadpool/TtlExecutors.java
浏览文件 @
ca491326
...
...
@@ -7,7 +7,7 @@ import java.util.concurrent.ExecutorService;
import
java.util.concurrent.ScheduledExecutorService
;
/**
* Factory Utils for getting TTL
W
rapper of jdk executors.
* Factory Utils for getting TTL
w
rapper of jdk executors.
*
* @author Jerry Lee (oldratlee at gmail dot com)
* @see java.util.concurrent.Executor
...
...
@@ -56,6 +56,48 @@ public final class TtlExecutors {
return
new
ScheduledExecutorServiceTtlWrapper
(
scheduledExecutorService
);
}
/**
* check the executor is TTL wrapper executor or not.
* <p>
* if the parameter executor is TTL wrapper, return {@code true}, otherwise {@code false}.
* <p>
* NOTE: if input executor is {@code null}, return {@code false}.
*
* @param executor input executor
* @param <T> Executor type
* @see #getTtlExecutor(Executor)
* @see #getTtlExecutorService(ExecutorService)
* @see #getTtlScheduledExecutorService(ScheduledExecutorService)
* @see #unwrap(Executor)
* @since 2.8.0
*/
public
static
<
T
extends
Executor
>
boolean
isTtlWrapper
(
T
executor
)
{
return
(
executor
instanceof
ExecutorTtlWrapper
);
}
/**
* Unwrap TTL wrapper executor to the original/underneath one.
* <p>
* if the parameter executor is TTL wrapper, return the original/underneath executor;
* otherwise, just return the input parameter executor.
* <p>
* NOTE: if input executor is {@code null}, return {@code null}.
*
* @param executor input executor
* @param <T> Executor type
* @see #getTtlExecutor(Executor)
* @see #getTtlExecutorService(ExecutorService)
* @see #getTtlScheduledExecutorService(ScheduledExecutorService)
* @see #isTtlWrapper(Executor)
* @since 2.8.0
*/
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
extends
Executor
>
T
unwrap
(
T
executor
)
{
if
(!
isTtlWrapper
(
executor
))
return
executor
;
return
(
T
)
((
ExecutorTtlWrapper
)
executor
).
unwrap
();
}
private
TtlExecutors
()
{
}
}
src/main/java/com/alibaba/ttl/threadpool/agent/TtlAgent.java
浏览文件 @
ca491326
...
...
@@ -9,7 +9,10 @@ import com.alibaba.ttl.threadpool.agent.internal.transformlet.impl.TtlTimerTaskT
import
java.lang.instrument.ClassFileTransformer
;
import
java.lang.instrument.Instrumentation
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.logging.Level
;
/**
...
...
src/main/java/com/alibaba/ttl/threadpool/agent/internal/transformlet/JavassistTransformlet.java
浏览文件 @
ca491326
package
com.alibaba.ttl.threadpool.agent.internal.transformlet
;
import
javassist.CannotCompileException
;
import
javassist.CtClass
;
import
javassist.NotFoundException
;
import
java.io.IOException
;
...
...
src/main/java/com/alibaba/ttl/threadpool/agent/internal/transformlet/impl/TtlForkJoinTransformlet.java
浏览文件 @
ca491326
package
com.alibaba.ttl.threadpool.agent.internal.transformlet.impl
;
import
com.alibaba.ttl.threadpool.agent.internal.logging.Logger
;
import
com.alibaba.ttl.threadpool.agent.internal.transformlet.JavassistTransformlet
;
import
javassist.*
;
import
java.io.IOException
;
import
java.lang.reflect.Modifier
;
import
com.alibaba.ttl.threadpool.agent.internal.logging.Logger
;
import
static
com
.
alibaba
.
ttl
.
threadpool
.
agent
.
internal
.
transformlet
.
impl
.
Utils
.
getCtClass
;
import
static
com
.
alibaba
.
ttl
.
threadpool
.
agent
.
internal
.
transformlet
.
impl
.
Utils
.
signatureOfMethod
;
...
...
src/main/java/com/alibaba/ttl/threadpool/agent/internal/transformlet/impl/Utils.java
浏览文件 @
ca491326
...
...
@@ -6,8 +6,8 @@ import java.io.ByteArrayInputStream;
import
java.io.IOException
;
/**
* @since 2.6.0
* @author Jerry Lee (oldratlee at gmail dot com)
* @since 2.6.0
*/
class
Utils
{
/**
...
...
src/test/java/com/alibaba/demo/agent/AgentDemo.kt
浏览文件 @
ca491326
...
...
@@ -3,7 +3,6 @@
package
com.alibaba.demo.agent
import
com.alibaba.ttl.TransmittableThreadLocal
import
java.lang.IllegalStateException
import
java.util.concurrent.ExecutorService
import
java.util.concurrent.Executors
import
java.util.concurrent.TimeUnit
...
...
src/test/java/com/alibaba/demo/distributed_tracer/refcount/DistributedTracerUseDemo.kt
浏览文件 @
ca491326
...
...
@@ -2,11 +2,11 @@ package com.alibaba.demo.distributed_tracer.refcount
import
com.alibaba.ttl.TransmittableThreadLocal
import
com.alibaba.ttl.threadpool.TtlExecutors
import
java.lang.Thread.sleep
import
java.util.concurrent.ConcurrentHashMap
import
java.util.concurrent.Executors
import
java.util.concurrent.atomic.AtomicInteger
import
kotlin.concurrent.thread
import
java.lang.Thread.sleep
/**
* DistributedTracer(DT) use demo.
...
...
src/test/java/com/alibaba/demo/timer/TimerTaskDemo.kt
浏览文件 @
ca491326
package
com.alibaba.demo.timer
import
java.text.SimpleDateFormat
import
java.util.Date
import
java.util.Timer
import
java.util.TimerTask
import
java.util.*
/**
* @see [Java Timer TimerTask Example](https://www.journaldev.com/1050/java-timer-timertask-example)
...
...
src/test/java/com/alibaba/ttl/threadpool/TtlExecutorsTest.kt
浏览文件 @
ca491326
package
com.alibaba.ttl.threadpool
import
org.junit.Assert.assertNull
import
com.alibaba.ttl.threadpool.TtlExecutors.*
import
org.junit.Assert.*
import
org.junit.Test
import
java.util.concurrent.Executors.newScheduledThreadPool
/**
* @author Jerry Lee (oldratlee at gmail dot com)
*/
class
TtlExecutorsTest
{
@Test
fun
test_common
()
{
val
newScheduledThreadPool
=
newScheduledThreadPool
(
3
)
getTtlExecutor
(
newScheduledThreadPool
).
let
{
assertTrue
(
it
is
ExecutorTtlWrapper
)
assertTrue
(
isTtlWrapper
(
it
))
assertSame
(
newScheduledThreadPool
,
unwrap
(
it
))
}
getTtlExecutorService
(
newScheduledThreadPool
).
let
{
assertTrue
(
it
is
ExecutorServiceTtlWrapper
)
assertTrue
(
isTtlWrapper
(
it
))
assertSame
(
newScheduledThreadPool
,
unwrap
(
it
))
}
getTtlScheduledExecutorService
(
newScheduledThreadPool
).
let
{
assertTrue
(
it
is
ScheduledExecutorServiceTtlWrapper
)
assertTrue
(
isTtlWrapper
(
it
))
assertSame
(
newScheduledThreadPool
,
unwrap
(
it
))
}
}
@Test
fun
test_null
()
{
assertNull
(
TtlExecutors
.
getTtlExecutor
(
null
))
assertNull
(
TtlExecutors
.
getTtlExecutorService
(
null
))
assertNull
(
TtlExecutors
.
getTtlScheduledExecutorService
(
null
))
assertNull
(
getTtlScheduledExecutorService
(
null
))
assertFalse
(
isTtlWrapper
(
null
))
assertNull
(
unwrap
(
null
))
}
}
src/test/java/com/alibaba/ttl/threadpool/agent/TtlAgentTest.kt
浏览文件 @
ca491326
package
com.alibaba.ttl.threadpool.agent
import
com.alibaba.ttl.threadpool.agent.TtlAgent.splitCommaColonStringToKV
import
org.junit.Assert.assertEquals
import
org.junit.Test
import
org.junit.Assert.*
class
TtlAgentTest
{
@Test
fun
test_splitCommaColonStringToKV
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录