@ -3,8 +3,6 @@ package com.fr.third.alibaba.ttl;
import com.fr.third.alibaba.ttl.threadpool.TtlExecutors ;
import com.fr.third.alibaba.ttl.threadpool.TtlForkJoinPoolHelper ;
import com.fr.third.alibaba.ttl.threadpool.agent.TtlAgent ;
import org.jetbrains.annotations.Nullable ;
import org.jetbrains.annotations.NotNull ;
import java.util.HashMap ;
import java.util.Iterator ;
@ -244,7 +242,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
/ * *
* Debug only method !
* /
static void dump ( @Nullable String title ) {
static void dump ( String title ) {
if ( title ! = null & & title . length ( ) > 0 ) {
System . out . printf ( "Start TransmittableThreadLocal[%s] Dump...%n" , title ) ;
} else {
@ -370,7 +368,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @return the captured { @link TransmittableThreadLocal } values
* @since 2 . 3 . 0
* /
@NotNull
public static Object capture ( ) {
return new Snapshot ( captureTtlValues ( ) , captureThreadLocalValues ( ) ) ;
}
@ -403,14 +401,14 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @see # capture ( )
* @since 2 . 3 . 0
* /
@NotNull
public static Object replay ( @NotNull Object captured ) {
public static Object replay ( Object captured ) {
final Snapshot capturedSnapshot = ( Snapshot ) captured ;
return new Snapshot ( replayTtlValues ( capturedSnapshot . ttl2Value ) , replayThreadLocalValues ( capturedSnapshot . threadLocal2Value ) ) ;
}
@NotNull
private static HashMap < TransmittableThreadLocal < Object > , Object > replayTtlValues ( @NotNull HashMap < TransmittableThreadLocal < Object > , Object > captured ) {
private static HashMap < TransmittableThreadLocal < Object > , Object > replayTtlValues ( HashMap < TransmittableThreadLocal < Object > , Object > captured ) {
HashMap < TransmittableThreadLocal < Object > , Object > backup = new HashMap < TransmittableThreadLocal < Object > , Object > ( ) ;
for ( final Iterator < TransmittableThreadLocal < Object > > iterator = holder . get ( ) . keySet ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) {
@ -436,7 +434,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
return backup ;
}
private static HashMap < ThreadLocal < Object > , Object > replayThreadLocalValues ( @NotNull HashMap < ThreadLocal < Object > , Object > captured ) {
private static HashMap < ThreadLocal < Object > , Object > replayThreadLocalValues ( HashMap < ThreadLocal < Object > , Object > captured ) {
final HashMap < ThreadLocal < Object > , Object > backup = new HashMap < ThreadLocal < Object > , Object > ( ) ;
for ( Map . Entry < ThreadLocal < Object > , Object > entry : captured . entrySet ( ) ) {
@ -458,7 +456,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @return the backup { @link TransmittableThreadLocal } values before clear
* @since 2 . 9 . 0
* /
@NotNull
public static Object clear ( ) {
final HashMap < TransmittableThreadLocal < Object > , Object > ttl2Value = new HashMap < TransmittableThreadLocal < Object > , Object > ( ) ;
@ -480,13 +478,13 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @see # clear ( )
* @since 2 . 3 . 0
* /
public static void restore ( @NotNull Object backup ) {
public static void restore ( Object backup ) {
final Snapshot backupSnapshot = ( Snapshot ) backup ;
restoreTtlValues ( backupSnapshot . ttl2Value ) ;
restoreThreadLocalValues ( backupSnapshot . threadLocal2Value ) ;
}
private static void restoreTtlValues ( @NotNull HashMap < TransmittableThreadLocal < Object > , Object > backup ) {
private static void restoreTtlValues ( HashMap < TransmittableThreadLocal < Object > , Object > backup ) {
// call afterExecute callback
doExecuteCallback ( false ) ;
@ -505,14 +503,14 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
setTtlValuesTo ( backup ) ;
}
private static void setTtlValuesTo ( @NotNull HashMap < TransmittableThreadLocal < Object > , Object > ttlValues ) {
private static void setTtlValuesTo ( HashMap < TransmittableThreadLocal < Object > , Object > ttlValues ) {
for ( Map . Entry < TransmittableThreadLocal < Object > , Object > entry : ttlValues . entrySet ( ) ) {
TransmittableThreadLocal < Object > threadLocal = entry . getKey ( ) ;
threadLocal . set ( entry . getValue ( ) ) ;
}
}
private static void restoreThreadLocalValues ( @NotNull HashMap < ThreadLocal < Object > , Object > backup ) {
private static void restoreThreadLocalValues ( HashMap < ThreadLocal < Object > , Object > backup ) {
for ( Map . Entry < ThreadLocal < Object > , Object > entry : backup . entrySet ( ) ) {
final ThreadLocal < Object > threadLocal = entry . getKey ( ) ;
threadLocal . set ( entry . getValue ( ) ) ;
@ -541,7 +539,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @see # restore ( Object )
* @since 2 . 3 . 1
* /
public static < R > R runSupplierWithCaptured ( @NotNull Object captured , @NotNull Supplier < R > bizLogic ) {
public static < R > R runSupplierWithCaptured ( Object captured , Supplier < R > bizLogic ) {
Object backup = replay ( captured ) ;
try {
return bizLogic . get ( ) ;
@ -560,7 +558,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @see # restore ( Object )
* @since 2 . 9 . 0
* /
public static < R > R runSupplierWithClear ( @NotNull Supplier < R > bizLogic ) {
public static < R > R runSupplierWithClear ( Supplier < R > bizLogic ) {
Object backup = clear ( ) ;
try {
return bizLogic . get ( ) ;
@ -582,7 +580,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @see # restore ( Object )
* @since 2 . 3 . 1
* /
public static < R > R runCallableWithCaptured ( @NotNull Object captured , @NotNull Callable < R > bizLogic ) throws Exception {
public static < R > R runCallableWithCaptured ( Object captured , Callable < R > bizLogic ) throws Exception {
Object backup = replay ( captured ) ;
try {
return bizLogic . call ( ) ;
@ -602,7 +600,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @see # restore ( Object )
* @since 2 . 9 . 0
* /
public static < R > R runCallableWithClear ( @NotNull Callable < R > bizLogic ) throws Exception {
public static < R > R runCallableWithClear ( Callable < R > bizLogic ) throws Exception {
Object backup = clear ( ) ;
try {
return bizLogic . call ( ) ;
@ -629,7 +627,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @see # registerThreadLocal ( ThreadLocal , TtlCopier , boolean )
* @since 2 . 11 . 0
* /
public static < T > boolean registerThreadLocal ( @NotNull ThreadLocal < T > threadLocal , @NotNull TtlCopier < T > copier ) {
public static < T > boolean registerThreadLocal ( ThreadLocal < T > threadLocal , TtlCopier < T > copier ) {
return registerThreadLocal ( threadLocal , copier , false ) ;
}
@ -652,7 +650,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @since 2 . 11 . 0
* /
@SuppressWarnings ( "unchecked" )
public static < T > boolean registerThreadLocalWithShadowCopier ( @NotNull ThreadLocal < T > threadLocal ) {
public static < T > boolean registerThreadLocalWithShadowCopier ( ThreadLocal < T > threadLocal ) {
return registerThreadLocal ( threadLocal , ( TtlCopier < T > ) shadowCopier , false ) ;
}
@ -673,7 +671,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @since 2 . 11 . 0
* /
@SuppressWarnings ( "unchecked" )
public static < T > boolean registerThreadLocal ( @NotNull ThreadLocal < T > threadLocal , @NotNull TtlCopier < T > copier , boolean force ) {
public static < T > boolean registerThreadLocal ( ThreadLocal < T > threadLocal , TtlCopier < T > copier , boolean force ) {
if ( threadLocal instanceof TransmittableThreadLocal ) {
logger . warning ( "register a TransmittableThreadLocal instance, this is unnecessary!" ) ;
return true ;
@ -710,7 +708,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @since 2 . 11 . 0
* /
@SuppressWarnings ( "unchecked" )
public static < T > boolean registerThreadLocalWithShadowCopier ( @NotNull ThreadLocal < T > threadLocal , boolean force ) {
public static < T > boolean registerThreadLocalWithShadowCopier ( ThreadLocal < T > threadLocal , boolean force ) {
return registerThreadLocal ( threadLocal , ( TtlCopier < T > ) shadowCopier , force ) ;
}
@ -724,7 +722,7 @@ public class TransmittableThreadLocal<T> extends InheritableThreadLocal<T> imple
* @see # registerThreadLocalWithShadowCopier ( ThreadLocal )
* @since 2 . 11 . 0
* /
public static < T > boolean unregisterThreadLocal ( @NotNull ThreadLocal < T > threadLocal ) {
public static < T > boolean unregisterThreadLocal ( ThreadLocal < T > threadLocal ) {
if ( threadLocal instanceof TransmittableThreadLocal ) {
logger . warning ( "unregister a TransmittableThreadLocal instance, this is unnecessary!" ) ;
return true ;