Package com.alibaba.ttl
Class TtlCallable<V>
java.lang.Object
com.alibaba.ttl.TtlCallable<V>
- All Implemented Interfaces:
TtlAttachments,TtlEnhanced,TtlWrapper<Callable<V>>,Callable<V>
public final class TtlCallable<V>
extends Object
implements Callable<V>, TtlWrapper<Callable<V>>, TtlEnhanced, TtlAttachments
TtlCallable decorate Callable to get TransmittableThreadLocal value
and transmit it to the time of Callable execution, needed when use Callable to thread pool.
Use factory method get(Callable) to get decorated instance.
Other TTL Wrapper for common Functional Interface see TtlWrappers.
- Since:
- 0.9.0
- Author:
- Jerry Lee (oldratlee at gmail dot com)
- See Also:
-
Field Summary
Fields inherited from interface com.alibaba.ttl.spi.TtlAttachments
KEY_IS_AUTO_WRAPPER -
Method Summary
Modifier and TypeMethodDescriptioncall()wrap methodCallable.call().booleanstatic <T> TtlCallable<T>Factory method, wrap inputCallabletoTtlCallable.static <T> TtlCallable<T>Factory method, wrap inputCallabletoTtlCallable.static <T> TtlCallable<T>Factory method, wrap inputCallabletoTtlCallable.return the original/underneathCallable.static <T> List<TtlCallable<T>>gets(Collection<? extends Callable<T>> tasks) wrap inputCallableCollection toTtlCallableCollection.static <T> List<TtlCallable<T>>gets(Collection<? extends Callable<T>> tasks, boolean releaseTtlValueReferenceAfterCall) wrap inputCallableCollection toTtlCallableCollection.static <T> List<TtlCallable<T>>gets(Collection<? extends Callable<T>> tasks, boolean releaseTtlValueReferenceAfterCall, boolean idempotent) wrap inputCallableCollection toTtlCallableCollection.<T> TgetTtlAttachment(String key) inthashCode()voidsetTtlAttachment(String key, Object value) toString()unwrap()unwrap to the original/underneathCallable.static <T> Callable<T>UnwrapTtlCallableto the original/underneath one.unwraps(Collection<? extends Callable<T>> tasks) UnwrapTtlCallableto the original/underneath one.
-
Method Details
-
call
wrap methodCallable.call(). -
getCallable
return the original/underneathCallable. -
unwrap
unwrap to the original/underneathCallable.- Specified by:
unwrapin interfaceTtlWrapper<V>- Since:
- 2.11.4
- See Also:
-
equals
-
hashCode
public int hashCode() -
toString
-
get
-
get
@Nullable @Contract(value="null, _ -> null; !null, _ -> !null", pure=true) public static <T> TtlCallable<T> get(@Nullable Callable<T> callable, boolean releaseTtlValueReferenceAfterCall) - Parameters:
callable- inputCallablereleaseTtlValueReferenceAfterCall- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.- Returns:
- Wrapped
Callable
-
get
@Nullable @Contract(value="null, _, _ -> null; !null, _, _ -> !null", pure=true) public static <T> TtlCallable<T> get(@Nullable Callable<T> callable, boolean releaseTtlValueReferenceAfterCall, boolean idempotent) - Parameters:
callable- inputCallablereleaseTtlValueReferenceAfterCall- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.idempotent- is idempotent or not.truewill cover up bugs! DO NOT set, only when you know why.- Returns:
- Wrapped
Callable
-
gets
@NonNull public static <T> List<TtlCallable<T>> gets(@Nullable Collection<? extends Callable<T>> tasks) wrap inputCallableCollection toTtlCallableCollection.- Parameters:
tasks- task to be wrapped- Returns:
- Wrapped
Callable
-
gets
@NonNull public static <T> List<TtlCallable<T>> gets(@Nullable Collection<? extends Callable<T>> tasks, boolean releaseTtlValueReferenceAfterCall) wrap inputCallableCollection toTtlCallableCollection.- Parameters:
tasks- task to be wrappedreleaseTtlValueReferenceAfterCall- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.- Returns:
- Wrapped
Callable
-
gets
@NonNull public static <T> List<TtlCallable<T>> gets(@Nullable Collection<? extends Callable<T>> tasks, boolean releaseTtlValueReferenceAfterCall, boolean idempotent) wrap inputCallableCollection toTtlCallableCollection.- Parameters:
tasks- task to be wrappedreleaseTtlValueReferenceAfterCall- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.idempotent- is idempotent or not.truewill cover up bugs! DO NOT set, only when you know why.- Returns:
- Wrapped
Callable
-
unwrap
@Nullable @Contract(value="null -> null; !null -> !null", pure=true) public static <T> Callable<T> unwrap(@Nullable Callable<T> callable) UnwrapTtlCallableto the original/underneath one.this method is
null-safe, when inputCallableparameter isnull, returnnull; if inputCallableparameter is not aTtlCallablejust return inputCallable.so
TtlCallable.unwrap(TtlCallable.get(callable))will always return the same inputcallableobject.- Since:
- 2.10.2
- See Also:
-
unwraps
@NonNull public static <T> List<Callable<T>> unwraps(@Nullable Collection<? extends Callable<T>> tasks) UnwrapTtlCallableto the original/underneath one.Invoke
unwrap(Callable)for each element in input collection.This method is
null-safe, when inputCallablecollection parameter isnull, return an empty list.- Since:
- 2.10.2
- See Also:
-
setTtlAttachment
- Specified by:
setTtlAttachmentin interfaceTtlAttachments- Parameters:
key- attachment keyvalue- attachment value- Since:
- 2.11.0
-
getTtlAttachment
- Specified by:
getTtlAttachmentin interfaceTtlAttachments- Parameters:
key- attachment key- Since:
- 2.11.0
-